Does the lexer ANTLR rule consume characters, even if they do not match?

I have a weird side effect from antlr's lexer rule, and I created a (almost) minimal working example to demonstrate it. In this example, I want to match String, for example [0..1]. But when I debug the grammar, the stream of tokens reaching the parser contains only [..1]. The first integer, no matter how many digits it contains, is always consumed, and I do not know how this happens. If I delete the rule FLOAT, everything will be fine, so I assume that the error lies somewhere in this rule. But, since he should not combine anything in [0..1], I am completely puzzled.

I would be happy for any pointers where I might have been mistaken. This is my example:

grammar min;
options{
language = Java;
output = AST;
ASTLabelType=CommonTree;
backtrack = true;
}
tokens {
  DECLARATION;
}

declaration : LBRACEVAR a=INTEGER DDOTS b=INTEGER RBRACEVAR -> ^(DECLARATION $a $b);

EXP : 'e' | 'E';
LBRACEVAR: '[';
RBRACEVAR: ']';
DOT: '.';
DDOTS: '..';

FLOAT
    : INTEGER DOT POS_INTEGER
    | INTEGER DOT POS_INTEGER EXP INTEGER
    | INTEGER EXP INTEGER
    ;

INTEGER : POS_INTEGER | NEG_INTEGER;
fragment NEG_INTEGER : ('-') POS_INTEGER;
fragment POS_INTEGER : NUMBER+;
fragment NUMBER: ('0'..'9');
+5
1

'0' , :

line 1:3 no viable alternative at character '.'
line 1:2 extraneous input '..' expecting INTEGER

, lexer '0.', FLOAT, . , '0.', , '0' DOT.

, ANTLR lexer: INTEGER, DDOTS ( , backtrack=true !).

FLOAT , , '.' , INTEGER. , ( ('..')=>) FLOAT , '.' ( ('.' DIGIT)=>). . :

declaration
 : LBRACEVAR INTEGER DDOTS INTEGER RBRACEVAR
 ;

LBRACEVAR : '[';
RBRACEVAR : ']';
DOT       : '.';
DDOTS     : '..';

INTEGER
 : DIGIT+
 ;

FLOAT
 : DIGIT+ ( ('.' DIGIT)=> '.' DIGIT+ EXP? 
          | ('..')=>      {$type=INTEGER;} // change the token here
          |               EXP
          )
 ;

fragment EXP   : ('e' | 'E') DIGIT+;
fragment DIGIT : ('0'..'9');
+6

All Articles