[antlr-interest] Failure to ignore newline

Norman Dunbar Norman at dunbar-it.co.uk
Fri Nov 18 07:20:15 PST 2011


Afternoon David,

On 18/11/11 15:01, David Riddle wrote:
> Yes, it's a \n, and I thought I told the grammar to set '\n' to a hidden
> channel.  So, why is it not hidden?


Think in C, where a newline character is represented in code as '\n'. 
There are two physical characters between the quotes, but the result is 
a single character 0x0a if you like - a unix new line.


 >>> WS: '\n'+ {$channel=HIDDEN;};

WS  is defining a single character of whitespace, the newline, not the 
two characters backslash and n.


 >>> // Input: a \n b

You have passed in a string of characters "a \n b" which is 6 characters 
long. You need to pass in "a<press return key>b" which will be 3 characters.


>>> // Output: a n b
When I ran it, I actually got a /n b as output using your input.

I think you are trying to get the input reader to convert '\n' to a 
single newline, and it obviously doesn't. Just press the return key when 
you want a new line.


HTH

Cheers,
Norm.

Disclaimer: I'm not a compiler writer nor do I play one on TV.

-- 
Norman Dunbar
Dunbar IT Consultants Ltd

Registered address:
Thorpe House
61 Richardshaw Lane
Pudsey
West Yorkshire
United Kingdom
LS28 7EL

Company Number: 05132767


More information about the antlr-interest mailing list