Regex for floating hex

ChrisDolan on 2009-01-14T03:29:12

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'] [
     | '.' + ? ?
     | + [
         | '.' * ? ?
         | ?
     ]
  ]
}
token HexDigit { [\d|<[a..f]>|<[A..F]>] }
token HexExponent { ['p'|'P'] ['+'|'-']? \d+ }
token FloatTypeSuffix { 'f'|'F'|'d'|'D' }