[antlr-interest] gUnit test cases and Windows paths

David Peckham dave.peckham at me.com
Sun Jan 18 00:11:49 PST 2009


The sample grammar was just a part of my larger grammar. I made this  
work by defining backslash as a token:

tokens {
	...
	BACKSLASH = '\\' ;
	...
}

I assumed that ~NEWLINE+ would match anything up to the end of the  
line. Thanks for the tip about forcing gUnit to display the error  
message.

Dave


On Jan 17, 2009, at 11:24 PM, Leon Su wrote:

> Hi David,
>
> Are there only 2 lexical rules in your grammar?
> If yes, the following gUnit test case must fail because ANTLR can't  
> tokenize your input string properly.
>
> dbCommand:
> ".output C:\TEMP\test.csv" OK
>
> Here is a trick to display the error messages from ANTLR as below:
> ".output C:\TEMP\test.csv" -> "show me the error message!"  // the  
> rhs expected result can be any arbitrary string...
> then you'll see some error messages like no viable alternative at  
> character '...'
>
> Leon
>
> ---------------  your grammar -----------------
>
> grammar sample;
>
> statement
>    :   dbCommand NEWLINE
>    ;
>
> dbCommand
>    :   CMD_OUTPUT { $CMD_OUTPUT.pos == 0 }? ~NEWLINE+
>    ;
>
> CMD_OUTPUT
>    :   ( '.output' | '.outpu' | '.outp' | '.out' | '.ou' | '.o' )
>    ;
>
> NEWLINE
>    : '\r'? '\n'
>    ;
>
> On Jan 17, 2009, at 6:27 PM, David Peckham wrote:
>
>> On Jan 17, 2009, at 6:11 PM, Gavin Lambert wrote:
>>
>>> At 14:01 18/01/2009, David Peckham wrote:
>>> >My gUnit test cases fail when they contain Windows paths. UNIX
>>> >paths work fine.
>>> [...]
>>> >dbCommand:
>>> >".output C:\TEMP\test.csv" OK
>>> ><<.output C:\TEMP\test.csv>> OK
>>>
>>> Did you try doubling the backslashes (ie. using \\ instead)?   
>>> While I don't know anything about gUnit syntax, it wouldn't  
>>> surprise me if it was being used as an escape character (so your  
>>> single backslashes are either getting ignored entirely or being  
>>> interpreted as tab characters, since they're followed by a "t").
>>>
>>
>> Yes, double backslashes fail too.
>>
>



More information about the antlr-interest mailing list