[antlr-interest] Replacing characters in a token during lexic
al phase
mzukowski at yci.com
mzukowski at yci.com
Fri Jun 6 15:07:24 PDT 2003
See http://www.antlr.org/doc/lexer.html#Manipulating_Token_Text_and_Objects.
You could use the $append() method:
// string literals
STRING_LITERAL
: '\'' (~('"'|'\\'))* '\''
| '\"'! {$append("'");} sl:(~('"'|'\\'))* '\"'! {$append("'");}
{
//_token = makeToken(_ttype);
//_token.setText(
}
;
Monty
-----Original Message-----
From: Ney, Richard [mailto:richard.ney at aspect.com]
Sent: Friday, June 06, 2003 2:48 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Replacing characters in a token during lexical
phase
I am trying to figure out how to get hold of the token on a string literal
so I can change the enclosing double quotes into single quotes. The rule
looks like this"
// string literals
STRING_LITERAL
: '\'' (~('"'|'\\'))* '\''
| '\"' sl:(~('"'|'\\'))* '\"'
{
//_token = makeToken(_ttype);
//_token.setText(
}
;
Which is the basic string literal rule, any idea how to get hold of the
character without running into the WS rule
// White Space
WS : (' '
| '\t'
| '\n'
| '\r')
{ _ttype = Token.SKIP; }
;
Since if I pull the inner piece of the string literal rule into a separate
token it conflicts with WS.
-Richard
----------------------------------------------------------------------------
------------------------
Richard Ney Aspect
Communications
Principal Software Engineer
<http://www.aspect.com> Main: 408.325.2200
<mailto:richard.ney at aspect.com> SJ Office: 408.325.2464
Home Office: 916.797.9602
----------------------------------------------------------------------------
------------------------
The Three Laws of Infernal Dynamics:
1. An object in motion will always be headed in the wrong direction.
2. An object at rest will always be in the wrong place.
3. The energy required to change either of these states will always be more
than you wish to expend, but never so much as to make the task appear
prospectively impossible.
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list