Loading CSV Data

Our goal is to build a listener that loads comma-separated-value (CSV) data into a nice “list of maps” data structure. This is the kind of thing that any data format reader or even a configuration file reader would do. We’ll collect the fields of each row into a map that associates a header name with a value. So, given the following input:

​ Details,Month,Amount
​ Mid Bonus,June,"$2,000"
​ ,January,"""zippo"""
​ Total Bonuses,"","$5,000"

we’d like to see the following list of maps printed out:

​ [{Details=Mid Bonus, Month=June, Amount="$2,000"},
​  {Details=, Month=January, Amount="""zippo"""},
​  {Details=Total Bonuses, Month="", Amount="$5,000"}]

To get precise methods within our listener, ...

Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.