[antlr-interest] retrieving the length of a production match
Randall R Schulz
rschulz at sonic.net
Tue Aug 21 12:48:29 PDT 2007
On Tuesday 21 August 2007 12:32, Adrian Herscu wrote:
> Hi all,
>
> I want to embed my parser in an IDE. One of the required features is
> to provide error markers. The markers framework API requires the
> length of the error besides of the line and column.
Technically speaking, parse errors don't have a length. There is a point
(a single token) at which the parser can detect ungrammatical input.
After that, it's all over.
Of course, people often try to go beyond that elementary kind of yes /
no parsing and add some kind recovery. My favorite "universal"
(non-parser-tool-dependent) technique is to write production for
explicitly non-grammatical (but usually common) errors so that you can
report them and continue parsing.
Other more sophisticated, parser-generator-specific techniques are
possible, but I'm not up on them. The topic is covered extensively in
TDAR.
> I have looked into the AST API and couldn't find nothing to help with
> this task... Searched the group and google, but still nothing :-(
If nothing else, you can just use the length of the token at which the
parse failed.
> Please help,
> Adrian.
Randall Schulz
More information about the antlr-interest
mailing list