arr-ai / wbnf

ωBNF implementation
Apache License 2.0
7 stars 4 forks source link

Redefine parser rule parameter as a term expression #18

Closed marcelocantos closed 4 years ago

marcelocantos commented 4 years ago

Currently, Parse takes a rule Rule parameter. This can be generalised to any term expression. For instance, today you can parse a JSON object.

json.Parse(Rule("object"), `{"a": 1}`)

But what if you want to parse a sequence of them?

json.Parse(`object+`, `{"a": 1}{"b":2}{"c":3}`)

or even a //-delimited list of them?

json.Parse(`object:"//"`, `{"a": 1}//{"b":2}//{"c":3}`)
ghost commented 4 years ago

I think this is a 👎 from me. I'm trying to disconnect the parser compiler from the parser engine, nothing is stopping (package) users from implemeting this as a wrapper around the .Parse() call though

marcelocantos commented 4 years ago

Wbnf was designed to support dynamic parsing. I'm worried that any changes to the architecture that make the above difficult or impossible within the engine itself are essentially negating this core design goal.

ghost commented 4 years ago

Just pushed a working implementation (which also stop NewFromParserNode crashing if it gets a Scanner instead of a Node).

question:

  1. Do we change the generated code to do this always instead of calling grammar.Parse() directly? - this would force the wbnf/wbnf package dependancy onto the users.
  2. Return type is currently ast.Node, if we did the above it would look like:

func ParseTerm(term string, input *parser.Scanner) (MyGrammarNode, error) {} (proabbly in addition to the existing func Parse()

ChloePlanet commented 4 years ago

Done.

ghost commented 4 years ago

@ChloePlanet done??