class CSVParser extends Parser; options { k=2; } file {System.out.println("file called");} : ( line (NEWLINE line)* (NEWLINE)? EOF) {System.out.println("file matched");} ; line {System.out.println("line called");} : ( (record)+ ) {System.out.println("line matched");} ; record {System.out.println("record called");} : ( (r:RECORD) (COMMA)? ) {System.out.println("record = " + r.getText()); System.out.println("record matched");} ; class CSVLexer extends Lexer; options { charVocabulary='\3'..'\377'; } RECORD : '"'! (~(','|'\r'|'\n'))+ ; COMMA : ',' ; NEWLINE : ('\r''\n')=> '\r''\n' //DOS | '\r' //MAC | '\n' //UNIX { newline(); } ; WS : (' '|'\t') { $setType(Token.SKIP); } ;