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.
In the source code below, you will see action call outs to produce error messages from your lexer. Programming for errors is generally ignored by programmers new to ANTLR because it is easy to program a rule that matches, but not so easy to program one that catches badly formed constructs - this is important for your users . Replace these JavaFX compiler specific calls with calls to your own error manager - the errors they are throwing should be obvious. There are also callouts to check numeric ranges, which also log errors if numbers are out of defined ranges - again, implement your own code here.
The very few action elements here are in Java, but are easily adapted to other targets.
Note the use of fragment rules with no body to define the token types that the main FLOATING_POINT_LITERAL uses.