title: ANTLR How to use lexer rules having same starting?
body: <p>How to use lexer rules having same starting?</p>
  
  <p>I am trying to use two similar lexer rules (having the same starting):</p>
  
  <pre><code>TIMECONSTANT: ('0'..'9')+ ':' ('0'..'9')+;
  INTEGER     : ('0'..'9')+;
  COLON       : ':';
  </code></pre>
  
  <p>Here is my sample grammar:</p>
  
  <pre><code>grammar TestTime;
  
  text      : (timeexpr | caseblock)*;
  
  timeexpr  : TIME;
  caseblock : INT COLON ID;
  
  TIME      : ('0'..'9')+ ':' ('0'..'9')+;
  INT       : ('0'..'9')+;
  COLON     : ':';
  ID        : ('a'..'z')+;
  
  WS        : (' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;};
  </code></pre>
  
  <p>When i try to parse text:</p>
  
  <pre><code>12:44
  123 : abc
  123: abc
  </code></pre>
  
  <p>First two lines are parsed correctly, 3rd - generates error.
  For some reason, '123:' ANTLR parses as TIME (while it is not)...</p>
  
  <p>So, is it possible to make grammar with such lexems?</p>
  
  <p>Having such rules is necessary in my language for using both case-blocks and datetime constants. For example in my language it is possible to write:</p>
  
  <pre><code>case MyInt of
    1: a := 01.01.2012;
    2: b := 12:44;
    3: ....
  end;
  </code></pre>