All you need do is use a predicate at the DOT, which is where the esPred rule 
is. You can change the syntactic predicate to a semantic predicate and check 
for #, ., ( and : via input.LT() but can also look at the previous token even 
if off channel to make sure it is not a space:

simpleSelector
        : elementName 
                ({ mySemPred() }?=>elementSubsequent)*
                
        | ({ mySemPred() }?=>elementSubsequent)+
        ;
@parser:members {

boolean mySemPred() {
switch (input.LA(1)) {
   case DOT:
        // Only if no preceding spaces (but is that correct for CSS?
        //
        if ((TokenStream)input).get( input.index()-1 ).getType() != WS) { 
return true; } else {return false; }
        break;
   case HASH:
   case LBRACKET:
   case COLON:
      return true;
   default:
      return false;
 }
}   

> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of David Grieve
> Sent: Monday, January 18, 2010 12:29 PM
> To: [email protected]
> Subject: [antlr-interest] Detecting a space as a token
> 
> 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.
> 
> 
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.


Reply via email to