Re: [whatwg/webidl] ExtendedAttributeList can match unbalanced ( ), [ ], and { } (Issue #1100)

Yes, exactly, it's unambiguously _derivable_ from the given facts ... but it's a bit of a journey to get there! I agree that a note would help future readers.

FWIW, I also got caught by this when I first started working w/ the Web IDL grammar, and there's a fair amount of evidence that it's confused other folks too. It's a hazard when editors add new keywords because it's not obvious that the act of adding a new keyword in a specific production also removes that literal source text string from `identifier`, affecting any number of other nonterminals one did not realize they were also editing!

The benefit, I think, is that this model effectively elevates "keywords" to a concern of the lexical grammar. This is kinda cool; it means there's (almost) no "static semantics" style rules needed to constrain identifiers extra-grammatically. The BNF-ish rules encode it directly instead. (The exceptions are cases where it's the string value of the ID that matters, e.g. "constructor" cannot be an operation name even if escaped with the underscore prefix.)

The biggest clue about the existence of this behavior is probably the nonterminals like ArgumentNameKeyword. These only make sense if there are ~85 or so (I forget the exact number) unique terminal symbols, not 7: all of their alternatives match the "initial" `identifier` regexp.

To save you from possibly having to figure out the next "wait, huh?" step of this lil journey, you may want to check out #812. The intuitive approach to lexing is to still use the seven "named" terminal patterns and then map their symbolic identities after with a static table, but there is one "anonymous" terminal that this approach will miss.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/1100#issuecomment-1043867145
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/1100/1043867145@github.com>

Received on Friday, 18 February 2022 04:24:48 UTC