Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New parsing run/parsing result API #16

Open
fge opened this issue May 20, 2014 · 0 comments
Open

New parsing run/parsing result API #16

fge opened this issue May 20, 2014 · 0 comments

Comments

@fge
Copy link
Owner

fge commented May 20, 2014

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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant