[antlr-interest] "Coarse grained" errors in antlr
David Ferrao
david.ferrao at gmail.com
Thu Sep 25 03:03:33 PDT 2008
Hi and apologies for the newbie question.
I am trying to build an autocomplete mechanism using antlr error messages,
but am facing a problem where the parser seems to bail out one rule earlier
than I would like.
To illustrate, consider the following grammar snippet.
--------Antlr 3 snippet-------
create : 'CREATE' stream;
stream : 'STREAM' qname 'TYPE' stream_types;
stream_types : map_schema| java_bean|xml_schema;
map_schema :'MAP_SCHEMA' '{' (value_list)? '}';
java_bean :'JAVA_BEAN' '(' class_name ')' '{' '}';
xml_schema :'XML_SCHEMA' '(' string_literal ')' '{' '}';
....contd...
---------end Grammar------
Given the string "CREATE STREAM system:TEST TYPE MAP_SCHEMA" as input, the
parser generates the following NoViableAltException
"36:1: stream_types : ( map_schema | java_bean | xml_schema );"
This is a completely logical error considering that the parser cannot match
either "map_schema" or "java_bean" or "xml_schema".
However, it is not very helpful for my auto complete scenario which would be
better served by an error message stating that a '{' was expected.
I was wondering if there is any option /technique to coax the parser to
start executing and consequently throw a NoViableAltException in the
"map_schema" rule, considering that the input DOES contain the 'MAP_SCHEMA'
token.
Would deeply appreciate any inputs, I have skimmed through the 'Definitive
ANTLR reference', but still couldnt come up with a solution :(
Thanks
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080925/976c90eb/attachment.html
More information about the antlr-interest
mailing list