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