[antlr-interest] Lexer for a grammar similar to a template engine

Graham Wideman gwlist at grahamwideman.com
Sun Oct 11 03:43:15 PDT 2009


First off, your OTHER rule should contain OR not AND if you want to accept '$' or '{' when they are not part of '${'.  

Other than that, it should be possible to write this without resorting to an action (semantic predicate), which would allow visualizing in ANTLRworks and so on.

-- Graham

>I've tried that grammar but it doesn't works. If I enter an input that
>contains $ or { in enters in an infinite bucle:
>
>Grammar:
>----
>OTHER:	(
>	    {input.LA(1)!='$' && input.LA(2)!='{'}? . 	
>	)+;
>	
>ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
>    ;
>	
>line	: (OTHER
>	  | expr )*;
>
>expr	: '${' ID '}';
>---
>
>I'm sure I'm missing some basic concept but have passed more than
>three or four years from my last antlr parser and I've to refresh my
>parsing abilities.
>Some one can orient me of how to solve that? or what I'm doing wrong?
>
>Can I do that in one parser or is better to use one parser to separate
>arbitrary content of expressions and then use another parser for the
>expressions?
>
>A lot of thanks in advance,
>
>
>-- 
>Joan Jesús Pujol Espinar
>http://www.joanpujol.cat
>http://lujop.deviantart.com
>
>List: http://www.antlr.org/mailman/listinfo/antlr-interest
>Unsubscribe: 
>http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list