[antlr-interest] Parsing free text
Bolek Vrany
lenochodpetiprsty at seznam.cz
Thu Nov 1 16:00:38 PDT 2007
Hello,
I'm quite new to ANTLR. Could you please help me with the following task?
How do I create either a lexer or parser rule that would read all text
starting with WRN or ERR until the end of file to a single token. The
language is case sensitive. For example
IF color=white AND size=big THEN ERR Not in stock
IF color=white AND size=big THEN WRN [[43:WR12345]]
Both identifiers and the text after WRN or ERR can be arbitrarily long.
Identifiers can contain 'a'..'z'|'A'..'Z'|'_'|'0'..'9' (numeric literals
are enclosed in $$, ie. $50.0$). WRN [[43:WR12345]] means look up the
text of warning [[43:WR12345]] in a database and display it, while the
first form simply display 'Not in stock'. The message is delimited only
by ERR and EOF.
I tried several ways to do it, but always ended with an ambiguity, loop
or a lexer rule eating all the text including IF and the condition to a
single token.
Thanks a lot
Bolek
More information about the antlr-interest
mailing list