[antlr-interest] Stuck

John B. Brodie jbb at acm.org
Mon Aug 20 11:07:36 PDT 2007


Ryan Daum asked (in part):
>Hi all,

Greetings!

>I'm writing a fairly simple grammar for the following protocol:
>
>http://www.belfry.com/fuzzball/trebuchet/mcp.html
>
>However, I'm stuck on a problem at the lexer level that I can't seem to
>solve.  I believe it's my final issue before I have a working parser.
>
>Basically, I have a number of rules which can match a combination of
>characters:
>
>        fragment
>        LINE 	:	(LINE_CHAR)* EOF;
>        IDENT 	:	ALPHA (ALPHA|DIGIT|'-' ~(SPACE | COLON |
>        OTHER_CHAR))* ;

...snipped...        

>This is all fine, individually they work well.  However, in the rule: 
>
>        messageContinue
>          	:	STAR SPACE datatag SPACE IDENT COLON SPACE LINE 
>          		-> ^(MESSAGE_CONTINUE datatag LINE);
>
>Working against the following line:
>
>        * 9b76 text: This is some sample text.
>
>I always get a MismatchedTokenException because the parser seems to want
>to turn everything after SPACE into an IDENT, rather than a line.  The
>intention of "LINE" is just to collect all input after the SPACE in a
>messageContinue; I do not want the rest of the lexer's rules to apply at
>all.  
>

I have not really looked too much at your grammar...

But right off I see that LINE is a fragment. This means that the
Parser will never see a LINE token.

Could that be your problem?

HTH
   -jbb


More information about the antlr-interest mailing list