consili...@gmail.com wrote:
You probably want to move a lot of this structure into the parser and not the lexer. It is a lot easier to just add the missing \n yourself before parsing, especially as your lexer gets bigger/more complicated.On 09-08-18 12:43 PM, David-Sarah Hopwood wrote:consili...@gmail.com wrote:The last line, b., doesn't match the MC_INCORRECT token because there's no newline after it. Is there an easy way to match this in ANTLR?Yes. I had the same problem when matching the end of a //-style comment, and solved it like this:fragment ENDOFLINE : NEWLINE | { input.LA(1) == EOF }? ; (If this were a non-fragment rule, it would be a problem that it can sometimes match no characters, but since it's a fragment, that's OK.)I want to use your solution, however it throws errors about "The following alternatives can never be matched: 1" for MC_QUESTION and MC_INCORRECT. Shouldn't the below work? MC_QUESTION : INT ('.'|')') .* ENDOFLINE; MC_INCORRECT : LETTER '.' .* ENDOFLINE; MC_CORRECT : '*' MC_INCORRECT; fragment ENDOFLINE : NEWLINE | { input.LA(1) == EOF }?; fragment NEWLINE : '\r'? '\n'; fragment LETTER : ('a'..'z'|'A'..'Z'); fragment INT : '0'..'9'+; List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address Jim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-interest@googlegroups.com To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~--- |
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address