Closed TodePond closed 2 years ago
Note: This effect can currently be loosely achieved with the 'check' property (??
) but it's more complicated. I don't think this is fully correct but it's something like this:
:: "#" HexDigits
HexDigits (
:: HexDigit+
?? ([[digits]]) => digits.length === 6
)
Huzzah! I actually tried to implement this, and it worked pretty well. This was my code:
Colour (
Hex :: /[0-9A-Fa-f]/ >> h => (''+h).toUpperCase()
:: "#" Hex Hex Hex Hex? [Hex Hex] [Hex Hex]
>> match => match.source
)
It matches #rgb
, #rgba
, #rrggbb
and #rrggbbaa
With this kind of syntax, it could be simplified to something like
Colour (
Hex :: /[0-9A-F]/i >> h => (''+h).toUpperCase()
:: "#" 3 Hex Hex? [2 Hex] [2 Hex]
>> match => match.source
)
Yes that looks along the right lines! Cool to see someone else's MotherTode 🤩
Here's another attempt:
Colour (
Hex :: /[0-9a-fA-F]/ >> hex => hex.output.toUpperCase()
:: "#" (3 Hex) | (4 Hex) | (6 Hex) | (8 Hex)
)
(with tabs instead of spaces of course 😅)
The way you wrote makes the whole thing make a lot more sense lmao. The IDE I use automatically turns tabs into 2 spaces, so that's my excuse!
Closing because of upcoming rewrite
It might be useful to be able to specify how many times you want a term to be repeated. Imagine you want to match a hex colour code:
It would be great if you could specify that you want only 6 of them... maybe like this... Not sure what syntax would be best.