arr-ai / wbnf

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

Solve a problem with the generated code for when a terminal rule with… #66

Closed ghost closed 4 years ago

ghost commented 4 years ago

… multiple unique options


         // a rule like: x -> 'a' | 'b' | 'c'; would expect to have an @choice rule and a single unnamedToken() rule
    // Because the options all only have a single token the code will generate a getter for the "" named tree node
    // However, this will fail because in this case the ast not would look like [@choice: 0, RULE_NAME: 'a']
    // instead of simply ["": 'a'] which is what would be expected.
    // To solve this problem the second if block is added to catch this.
    // A better solution would be to do `ast.First(ast.First(c.Node, "TheRule").Node, "") but the codegen loses
    // the rule name, this solution is Good Enough(TM)