proposal-binary-ast icon indicating copy to clipboard operation
proposal-binary-ast copied to clipboard

Grammar quirks

Open bakkot opened this issue 6 years ago • 1 comments

It is almost certainly too early to worry about this, but a couple notes while I'm thinking of them:

  • The tree grammar specified does not allow for (var a = b in c);, which is a legal program (in sloppy mode, assuming Annex B) as of https://github.com/tc39/ecma262/pull/614.

  • There's a variety of ways that well-typed trees can fail to correspond to real programs, which should all be captured in this project (except that said project hasn't been updated for async/await yet). For example, you can't have an if with an else as the body of an if without an else, even though the tree types can represent that. You also have to make sure that Identifiers are actually identifiers and that sort of thing. These aren't captured by the early error rules because they don't match the lexical grammar, and so presumably will need to be checked explicitly.

  • The type for TemplateExpression can be made more strict by having something like

interface Interpolation {
  attribute Expression value;
  attribute TemplateElement after;
}
interface TemplateExpression : Node {
  attribute Expression? tag;
  attribute TemplateElement start;
  attribute FrozenArray<Interpolation> elements;
};

instead of the current TemplateExpression definition which just has a list of elements which mixes Expressions and TemplateElements. Shift doesn't currently do this because it's kinda awkward to use (or, well, I think that was the justification, but have now forgotten), but this project might find it to be worth it.

bakkot avatar May 16 '18 07:05 bakkot

Thanks for the list! The validations that were implicit in the lexical grammar that must now be made explicit is a very important point.

syg avatar May 16 '18 14:05 syg