-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Milestone
Description
Such an API is needed. We will start by highlighting the problems with the current API (and there are many!) and then propose a new one.
Problems with the current API
- The existing
ParsingResulthas fields which are allpublic, with no accessors! This will change starting with 1.0.0-beta.10; - It is unclear how you can tell whether a match succeeded (problem highlighted in issue Possibly contradicting parse error indicators #6).
- Error messages are generated by the parse runners themselves; the rules, by themselves, have no way of emitting error messages of their own (problem highlighted in issue Allow custom parse error messages #7).
- Nulls! Unless you call the appropriate
ParseRunner, aParsingResultwill have most of its fields set tonull. - Parsing trees; there is no reason for
@BuildParseTreeto exist at all; you should be able to generate a parse tree for any parser without having to annotate it.
There are other problems as well.
Proposed new API
The new API would look like this:
// default factory
final ParseRunnerFactory factory = ParseRunnerFactory.defaultFactory();
// customized
final ParseRunnerFactory factory = ParseRunnerFactory.newBuilder()
.noValueStack() // don't create a value stack
.createParseTree() // create a parse tree
.build(); // create the factory
// "parser" is a generated parser instance
// unlike the current API, parse runners created would be reusable
final ParseRunner<X> runner = factory.create(parser.rule());