How do I manage optional whitespace in ANTLR?
问题 I am trying to parse a data file in ANTLR - it has optional whitespace exemplified by 3 6 97 12 15 18 The following shows where the line starts and ends are. There is a newline at the end and there are no tabs. ^ 3 6$ ^ 97 12$ ^ 15 18$ ^ My grammar is: lines : line+; line : ws1 {System.out.println("WSOPT :"+$ws1.text+":");} num1 {System.out.println("NUM1 "+$num1.text);} ws2 {System.out.println("WS :"+$ws2.text+":");} num2 {System.out.println("NUM2 "+$num2.text);} NEWLINE ; num1 : INT ; num2 :