Skipping unmatched input in Antlr
问题 Is there a way to specify in a grammar that I want to skip all input that doesnt match any of the rules (that would otherwise throw a recognition error)? 回答1: Yes. Implementation depends on where you need/want to do the skipping. In the lexer, a last rule like: Unknown : . -> skip ; // or -> channel(HIDDEN) ; will consume any otherwise unmatched input characters yet keep them from being tokenized and considered by the parser. You do want to match a single character at a time so that at every