...
- You have ANTLR and TestNG installed. (You can use the same ideas with other unit testing frameworks such as JUnit)
- You can run ANTLR to generate Java sources from a grammar.
- You can build and run Java code.
- (optional) You have JDK 1.5 or later installed. If not, you won't be able to use some of the constructs in this example and will need to translate back to 1.4 or earlier.
Develop
...
a basic CSV parser
Basic setup
Every CSV line ends in a newline (line feed) or carriage return + line feed. Let's set that up as our basic grammar.
...
No Format |
---|
line 1:3 no viable alternative at character ' ' line 1:4 no viable alternative at character ' ' line 1:6 no viable alternative at character ' ' line 1:7 no viable alternative at character ' ' line 1:8 no viable alternative at character ' ' line 1:15 no viable alternative at character ' ' |
ANTLR 3's error recovery is taking care of this for us .I'm inclined to make any production code do the right thing anyway, if for no other reason than to make the grammar self-documenting. So I will leave you with the following challenges:by skipping the space characters (which are unrecognized by the UNUOTED
rule. If we want to catch the error instead, we'll have to alter the error recovery mechanism.
Panel | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
|