[antlr-interest] JavaScript grammar

David Holroyd dave at badgers-in-foil.co.uk
Sat Mar 29 15:57:57 PDT 2008


On Fri, Mar 28, 2008 at 08:13:32PM +0000, Chris Lambrou wrote:
>    1. Unlike other whitespace characters, line separators (represented by
>    my LT token type) are important in JavaScript, as you're allowed to use them
>    to terminate statements instead of the usual terminating semicolon
>    character. As a result, I cannot 'hide' line separators like other
>    whitespace characters, and my grammar is peppered with LT!* sequences. Is
>    there a way to place the LT tokens on the hidden channel, and then
>    optionally reveal them only in the few rules that require it?

I attempted[1] to approach this by having a rule like,

  semi
	:	SEMI!
	|	{ virtualSemi() }?  /* then empty alt is allowed */
	;

then defining the virtualSemi() function to return true if there's a
newline in the whitespace preceding the current location in the token
stream (i.e. hunt back through any hidden-channel tokens).

However I must admit that due to ambiguities that ANTLR started
reporting, I commented out the second alt for the moment :(


ta,
dave

[1] http://svn.badgers-in-foil.co.uk/metaas/trunk/src/main/antlr/org/asdt/core/internal/antlr/AS3.g3

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list