[antlr-interest] return LTR values

Kevin J. Cummings cummings at kjchome.homeip.net
Thu Aug 19 10:31:33 PDT 2010


On 08/19/2010 11:56 AM, Brian Lavender wrote:
> So, I have a parser rule that grabs 10 LTR lexer values. I would like to have the parser
> rule set its $text value to be the concatonation of these LTR values and put an
> XML tag around it. 
> 
> How do I do that?
> 
> author	:	l=LTR l=LTR l=LTR l=LTR l=LTR l=LTR l=LTR l=LTR l=LTR l=LTR 
> { <Author>$l+</Author> };

Do it with a LEXER rule instead of a parser rule.

AUTHOR : LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR
       ;

If you still need to do something in a parser rule, do it as

author : AUTHOR
	 { ... }
       ;

> LTR  :   . ;

Having a lexer rule that matches any single character is going to get
you into trouble later on if you are not careful.  The whole point of
lexing to the convert single characters into TOKENs which can then be
parsed by the parser.

-- 
Kevin J. Cummings
kjchome at rcn.com
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list