[antlr-interest] Customizing errors in antlr3
Benoit Miller
fulg at iname.com
Sun Jan 7 14:33:49 PST 2007
I tried David's suggestion but there was no change in behavior. However
you pointed me in the right direction.
I think the solution is to merge both rules in one, and perform that
kind of validation after parsing is complete.
Thanks!
Ben.
James Briant wrote:
> Seems like, from the point of view of your grammar, that "[foo] class bar;"
> is valid, i.e. recognizable, and only then do you want to tell the user
> that
> its invalid.
>
> On 1/7/07, Benoit Miller <fulg at iname.com> wrote:
>> What is the best way to customize reported errors in antlr3?
>>
>> For example, in the following snippet:
>>
>> start
>> : forwardDecl* objectDecl*
>> ;
>>
>> forwardDecl
>> : classOrStruct IDENTIFIER ';'
>> -> ^(classOrStruct IDENTIFIER)
>> ;
>>
>> objectDecl
>> : attrList? classOrStruct IDENTIFIER '{' property* '}' ';'
>> -> ^(classOrStruct IDENTIFIER attrList? property*)
>> ;
>>
>> [unedited snippet, so this time it should be representative :)]
>>
>> Given an input such as "[foo] class Bar;", I want to report to the tool
>> user something like "cannot specify attributes on forward declarations",
>> but it's unclear to me how to do this.
More information about the antlr-interest
mailing list