O'Reilly logo

The Definitive ANTLR 4 Reference, 2nd Edition by Terence Parr

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

listeners/t.csv
 
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, let’s label each of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required