ptal / oak

A typed parser generator embedded in Rust code for Parsing Expression Grammars
Apache License 2.0
142 stars 14 forks source link

Automatic AST generation #15

Closed ptal closed 9 years ago

ptal commented 10 years ago

We can automatically derived an AST from a grammar without semantic action.

#[constructors_name(Digit, Letter)]
rule_1 = digit*
           /  letter

derive an AST that looks like:

enum Rule1
{
  Digit(Vec<int>),
  Letter(char)
}
ptal commented 9 years ago

We can achieve a similar result with our notion of semantic actions:

rule_1 = digit* > Digit
      /  letter > Letter

In a first time, we expect the variants Letter and Digit to be declared by the programmer himself. We close this for the moment because it might not be easy or a good idea to generate it by default, furthermore this syntax would generate ambiguities if we generate the AST.

ptal commented 9 years ago

Note: the main difficulty is to name things (notably sum types).