Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

How to lex numbers, dots/periods, and range operators all at the same time.

(... and catch errors with malformed literals.)

The question "How do I parse floating point numbers, and single periods/dots and I need a range operator which is two dots at the same time?" comes up so frequently, that I decided to publish the lexical rules from the commercial grade lexer in the JavaFX compiler, with the blessings of Sun Microsystems, as the compiler is open source. See JavaFX for more details of the JavaFX project.

...

Info
titleNotes

Note the use of fragment rules with no body to define the token types that the main FLOATING_POINT_LITERAL uses.
You may feel that this looks like a complicated rule, but in fact it is very simple as all the possible paths through a literal definition are laid out and you can read it directly, without having to infer any decisions that ANTLR tried to make for you.

...