You want a rule like this:
DELIM : { input.LA(1) == currDelim}?=> . ;
However, this could get a little complicated to get the matching order of
the rules correct when you start having a lot more rules. You will need to
experiment a little.
You could also pre-process the input and substitute something extremely
unlikely to clash with the language, such as '\u0001' or something like
that. Then only look for that character in the main lexer.
Jim
> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Frederic Beister
> Sent: Sunday, August 15, 2010 11:40 PM
> To: [email protected]
> Subject: [antlr-interest] Lexer Rule matching member variable (Java)
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello,
>
> I want to write an ANTLR-Lexer and -Parser for a Literate Programming
> language. The idea is to embed code fragments in various languages in a
> LaTeX document and generate source files on-the-fly.
>
> The languages allows to change the special character used to denote the
> beginning of a code snippet and the special character used inside these
> snippets to denote inclusion of other snippets. This is needed because
some
> "guest"-languages might need a pre-defined special character themselves.
>
> The special character can be changed anywhere in the source text by using
> <OLDSPECIAL>=<NEWSPECIAL> where <OLDSPACIAL> is the old special
> character and <NEWSPECIAL> is the new special character that should be
> active after that instruction.
>
> My idea was to modify the lexer such that it has a member variable "char
> cur_special" that is set to the current special character and match
against it in
> a rule
>
> "fragment SCHAR : cur_special"
>
> such that the token stream abstracts from the different possible special
> characters.
>
> At the moment, the only way I see to accomplish this is to manually modify
> the generated lexer in many places.
>
> Is there perhaps a built-in functionality in ANTLR 3.2 i could use? I
couldn't
> find anything in the archives searching for "lexer match member". I really
> don't need a full how-to but a gentle nudge in the correct direction.
>
> Thanks in advance
> Frederic
>
> P.S.
> Sorry if this is/becomes a repost. My first mail didn't make it through
> - - perhaps because it had a PGP signature attachment
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkxo3UcACgkQOBEXShUwZO0hagCeNY82qTh5wRk7SmvCAxB
> 9oAfk
> 1RwAni+IC77x5IBHbw2Tp4SQ4qv1RIS7
> =U+NM
> -----END PGP SIGNATURE-----
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.