JavaScript example: Remove reserved word detection

Reserved word detection as it was implemented in the JavaScript example
grammar had two big downsides:

  1. It required changes in ordering of choices in some rules in order
     not to trigger the detection prematurely. One of the changes was
     already implemented (in the |Statement| rule, see the diff), but
     apparently more were needed (the grammar didn't parse inputs like
     |true| or |function f() {}|). And I'm not 100% sure that would be
     the end of it (maybe deeper structural changes would be needed).

  2. It made error messages confusing. Consider the following example:

       var a = @;

     Instead of reporting:

       Expected ... but "@" found.

     the generated parser reported:

       Reserved word "var" can't be used as an identifier.

     This was because the parser parsed the statement first as
     |VariableStatement| and when this failed, it tried to parse it as
     |ExpressionStatement|, triggering the reserved word detection.

Because of these, I decided to remove reserved word detection from the
JavaScript example grammar.
David Majda 10 years ago
parent b271d66442
commit c13cc88262

@ -146,11 +146,6 @@ SingleLineComment
= !ReservedWord name:IdentifierName { return name; }
/ name:IdentifierName {
"Reserved word \"" + + "\" can't be used as an identifier."
IdentifierName "identifier"
= first:IdentifierStart rest:IdentifierPart* {
@ -993,23 +988,18 @@ Statement
= Block
/ VariableStatement
/ EmptyStatement
/ ExpressionStatement
/ IfStatement
/ IterationStatement
/ ContinueStatement
/ BreakStatement
/ ReturnStatement
/ WithStatement
/ LabelledStatement
/ SwitchStatement
/ ThrowStatement
/ TryStatement
/ DebuggerStatement
* The following two statements begin with identifiers. They must be at the
* very end of the list to prevent triggering reserved word detection in the
* |Identifier| rule by keywords the statemets above begin with (e.g. |if|).
/ ExpressionStatement
/ LabelledStatement
= "{" __ body:(StatementList __)? "}" {