Fixed parser weirdness. More readable parser finished.

For whatever reason, writing the parser in Groovy was causing weird errors
to occur when the parser or parse runner was created. Using a plain Java
source file fixed this.
This commit is contained in:
Jonathan Bernard
2011-08-26 05:51:29 -05:00
parent e8ebcd4998
commit 13e0e72fed
4 changed files with 85 additions and 62 deletions

BIN
src/test/TestParser.class Normal file

Binary file not shown.

27
src/test/TestParser.java Normal file
View File

@ -0,0 +1,27 @@
import org.parboiled.BaseParser;
import org.parboiled.Parboiled;
import org.parboiled.Rule;
import org.parboiled.annotations.BuildParseTree;
import org.parboiled.parserunners.ReportingParseRunner;
import org.parboiled.support.ParsingResult;
import static org.parboiled.support.ParseTreeUtils.printNodeTree;
@BuildParseTree
public class TestParser extends BaseParser<Object> {
public Rule S() {
return OneOrMore(
Sequence(A(), OneOrMore(B()), C())); }
Rule A() { return Ch('a'); }
Rule B() { return Ch('b'); }
Rule C() { return Ch('c'); }
public static void main(String[] args) {
TestParser parser = Parboiled.createParser(TestParser.class);
ReportingParseRunner parseRunner = new ReportingParseRunner(parser.S());
ParsingResult result = parseRunner.run("abbbbcabc");
System.out.println(result.matched ? printNodeTree(result) + "\n" : "No Match");
}
}