A couple days ago I wrote about Java syntax for hexadecimal representation of floating point numbers like this:
0x1.fffffeP+127f
Here are the Perl 6 grammar snippets I put together to parse this. Easy!
token HexLiteral {
'0' ['x'|'X'] [
| '.' <HexDigit>+ <HexExponent>? <FloatTypeSuffix>?
| <HexDigit>+ [
| '.' <HexDigit>* <HexExponent>? <FloatTypeSuffix>?
| <IntegerTypeSuffix>?
]
]
}
token HexDigit { [\d|<[a..f]>|<[A..F]>] }
token HexExponent { ['p'|'P'] ['+'|'-']? \d+ }
token FloatTypeSuffix { 'f'|'F'|'d'|'D' }
Regex for floating hex 0 Comments More | Login | Reply /