[antlr-interest] gUnit and Error Recovery

Louis Rose louis at cs.york.ac.uk
Fri Aug 8 04:12:57 PDT 2008


Hi Leon,

Many thanks for your help.

After a little more investigating, I now believe this is an issue with 
error reporting.

The grammar that I'm using generates a parser which extend a base class, 
BaseParser. The BaseParser class overrides the displayRecognitionError 
method, and redirects the output (to an Eclipse console).

Does gUnit require errors to be reported to System.err? If so, I'll find 
a way to change BaseParser to allow this.

Cheers,
Louis.

Leon Su wrote:
> Hi Louis,
> 
> I just quickly tested the grammar fragment you provided:
> remove (cls)* from pkg, and add WS:( ' ' | '\t' | '\r' | '\n' )+ 
> {$channel = HIDDEN;};
> 
> tested by gUnit1.0.2+ANTLR3.1b2 and gUnit-1.0.1+ANTLR3.0.1
> and both got the failed 2nd test as we expected ( and received the error 
> msg from ANTLR: line 0:-1 missing RBRACKET at '<EOF>' )
> 
> If you're using gunit-1.0.1 currently, don't forget to download the 
> updated gunit-1.0.1.jar Version2 on the wiki page.
> Please let me know if you any problem.
> 
> Leon
> 
> On Aug 7, 2008, at 10:25 AM, Louis Rose wrote:
> 
>> Hi all,
>>
>> I'm currently considering migrating a large number of unit tests to 
>> gUnit. I have a query about the way gUnit works with ANTLR's error 
>> recovery capabilities.
>>
>> Here's a fragment from an ANTLR grammar that I wish to test:
>>
>> pkg: NAME^ LBRACKET! (cls)* RBRACKET!;
>>
>> LBRACKET     : '{';
>> RBRACKET     : '}';
>> NAME         : ID_START_LETTER (ID_LETTER)*;
>>
>> fragment
>> ID_START_LETTER
>>     :    '_'
>>     |    'a'..'z'
>>     |    'A'..'Z'
>>     |    '@'
>>     ;
>>
>> fragment
>> ID_LETTER
>>     :    ID_START_LETTER
>>     |    '0'..'9'
>>     |    '-'
>>     ;
>>
>>
>> I have the following gUnit tests:
>>
>> pkg:
>>     "Families {}" -> "Families"
>>     "Families {"    FAIL
>>
>> I would expect the second test to verify that a terminating right 
>> bracket is required. (i.e. parsing would fail). In fact, the parser 
>> successfully recognises the input from the second test:
>>
>> 1 failures found:
>> test2 (pkg, line6) -
>> expected: FAIL
>> actual: OK
>>
>> Tests run: 2, Failures: 1
>>
>>
>> Is this working as intended? How can I test that all uses of pkg 
>> should be terminated with a closing bracket?
>>
>> Many thanks,
>> Louis Rose.
>>
> 


More information about the antlr-interest mailing list