[antlr-interest] Grammar problem

John B. Brodie jbb at acm.org
Mon Sep 3 10:03:27 PDT 2012


Greetings!

Your sample grammar does not handle blanks in the optional text but your 
first sample input text does contain blanks in the optional text. So I 
am confused.....

Maybe as a start just delete the unused Token rule for TXTALPHANUM ?

Hope this helps....
    -jbb

On 09/03/2012 11:54 AM, vincent wrote:
>   Hy,
>
> I use some ANTLR grammar to decode text files. But i encouter a problem
> with the following example.
> Does anybody can help me ?
>
> My text files is componed of the following parts :
>
> start line : "-  "
> optional text : text ended with "."
> serial number : 5 digits ended by a space
> versioning : digit / digit
> text : text
>
> example with optional text :
>
> -  optional text.00001 001/001TEXT
>
> example without optional text :
>
> -  00001 001/001TEXT
>
> my probem is for optional text, cant detect it with antlr grammar.
> I use the following code :
>
>
>
>
> COMMA : ',';
> DOT : '.';
> HYPHEN :'-';
> SPACE : ' ';
> SLASH : '/';
> CHAR : ('a'..'z'|'A'..'Z');
> SEPARATOR : (DOT |HYPHEN)+;
> DIGIT : ('0'..'9');
> TXTALPHA : (CHAR)+ ;
> NUMBER : (DIGIT)+ ;
> TXTALPHANUM : ((CHAR) | (DIGIT))+;
>
>
> textline : HYPHEN (SPACE)+  (optionalLines)* normalLine;
>
> optionalLines : (TXTALPHA)* DOT
>
> normalLine: serialNumber SPACE currentPartNumber SLASH maxPartNumber;
>
>



More information about the antlr-interest mailing list