Skip to content

New parsing run/parsing result API #16

@fge

Description

@fge

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 ParsingResult has fields which are all public, 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, a ParsingResult will have most of its fields set to null.
  • Parsing trees; there is no reason for @BuildParseTree to 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());

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions