From: "Daniel Lidström" <[email protected]> [...] > Is there a way to capture > the part outside [] as-is, > with whitespace exactly like written, and the part inside [] is relaxed > where whitespace to go hidden > channel? > > Daniel > > Here's my grammar, btw: > > parse > : (IDENT | variable)+ EOF > ; > > variable > : '[' mult ']' > ; > > // the multiplication is optional > mult > : IDENT ('*' INTEGER)? > ; > > fragment DIGIT : '0'..'9' ; > INTEGER : DIGIT+ ; > > fragment LETTER : 'a'..'z' | 'A'..'Z'; > IDENT : LETTER+ ; > > WS : ' '+ { $channel = HIDDEN; } ;
I will try to answer myself. After a good nights sleep I think I have found a way to solve this problem, using actions. I am going to build an abstract syntax tree from this grammar. Then I figured I can keep a context variable within my parser. Whenever I am parsing a variable (rule above) I set the variableContext to true. Then I capture whitespace within the WS rule but only when the variableContext is set to false. I haven't worked out the details yet but I am positive it should work. Is there anyone who knows of an online grammar example that does something like this? Daniel 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.
