Accessing Token and Rule Attributes
Letâs use the CSV grammar from âParsing Comma-Separated Valuesâ as a foundation for exploring some more action-related features. Weâre going to build an application that creates a map from column name to field for each row and prints out information gained from parsing the data. Our goal here is really just to learn more about rule-related actions and attributes.
First, letâs take a look at how to define local variables using the locals section. As with parameters and return values, the declarations in a locals section become fields in the rule context object. Because we get a new rule context object for every rule invocation, we get a new copy of the locals as weâd expect. The following augmented ...
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.