Hi Ron, Thanks, I've been applying the channel=HIDDEN on the WS_CHAR fragment level, and that messed up everything, but using this extra token works perfectly.
Cheers, Davy On Fri, Feb 26, 2010 at 01:54, Ron Hunter-Duvar <[email protected]> wrote: > Hi Davy, > > You don't have a rule for consuming whitespace. Add something like this: > > WS : > WS_CHAR+ {$channel=HIDDEN;} > ; > > fragment WS_CHAR : > (' '|'\r'|'\t'|'\u000C'|'\n') > ; > > Ron > > > Davy Landman wrote: >> >> Hello, >> >> I'm having some problems with my generated java parser/lexer, but I've >> tried to reduce the problem to a small subset. >> >> Let's assume the simple language which has identifiers and numbers. >> And the only rules are, a number contains out of only numbers, and a >> identifier can not contain `'?', ':', ' '` and can not begin with a >> number. >> >> I would create the following ANTLR specification of this language. >> >> grammar simple; >> >> prog: expr* EOF; >> >> expr >> : ID | INT; >> >> >> ID : ~('0'..'9'|SEPERATORS) ~(SEPERATORS)*; >> >> fragment >> SEPERATORS >> : ' ' | ':' | '?'; >> >> INT : '0'..'9'+ >> ; >> >> And running this in ANTLRWorks debugging and parsing mode, no errors >> are reported to the console. >> >> But if I than generate the Parser and Lexer and try to consume it in a >> java program as such: >> >> import org.antlr.runtime.ANTLRStringStream; >> import org.antlr.runtime.CommonTokenStream; >> import org.antlr.runtime.RecognitionException; >> >> >> public class runner { >> >> public static void main(String args[]) >> { >> simpleLexer lex = new simpleLexer(new >> ANTLRStringStream("a33 44")); >> CommonTokenStream tokens= new CommonTokenStream(lex); >> simpleParser parser = new simpleParser(tokens); >> try { >> parser.prog(); >> } catch (RecognitionException e) { >> e.printStackTrace(); >> } >> } >> } >> >> The parser works, and the prog() continues succesfully. But in the >> background the following error message is printed to the console. >> >> line 1:3 no viable alternative at character ' ' >> >> The same exact sequence causes no messages to the ANTLRWorks console, >> so I was wondering, am I abusing the ~ ? Or is there a difference >> between the ANTLRWorks debugger and default java runtime? >> >> So if anybody can help me how to get rid of these messages? Because in >> the original lexer and parser where this question is based, I get a >> nice looking AST but only have messages printed to the eclipse >> console. >> >> Versions used: >> ANTLRWorks 1.3.1 >> ANTLR-3.2 >> Linux x64 >> >> Kind regards, >> Davy Landman >> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest >> Unsubscribe: >> http://www.antlr.org/mailman/options/antlr-interest/your-email-address >> >> > > -- > Ron Hunter-Duvar | Software Developer V | 403-272-6580 > Oracle Service Engineering > Gulf Canada Square 401 - 9th Avenue S.W., Calgary, AB, Canada T2P 3C5 > > All opinions expressed here are mine, and do not necessarily represent > those of my employer. > > 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.
