[antlr-interest] Detecting a space as a token

David Grieve David.Grieve at Sun.COM
Mon Jan 18 12:29:17 PST 2010


In CSS, a selector is (roughly) a sequence of simple selectors joined by a combinator. http://www.antlr.org/grammar/1240941192304/css21.g has the following rules which correspond to this. 

combinator
	: PLUS
	| GREATER
	|
	;
	
selector
	: simpleSelector (combinator simpleSelector)*
	;

The issue I'm having is how to handle the combinator which is a space in the selector rule. Specifically, I should be able to parse 
	
	A .b

as two simple selectors: A and .b. However, since whitespace is ignored, this is getting parsed as one selector. The following parses as desired: 

	A *.b

Using the universal selector as part of the second simple selector is a workaround that I shouldn't have to employ. 

How can I parse "A<space>.b" such that the space is recognized as a combinator? Thanks in advance for any help!
David Grieve 
Sun Microsystems, Inc.






More information about the antlr-interest mailing list