From c70c8551b474dc105b549ffc8ca431fc4a73b307 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 6 Apr 2014 15:20:01 +0200 Subject: [PATCH] JavaScript example: Fix parsing of statements Fixes a problem where statements starting with a reserved word produced errors like this: Reserved word "return" can't be used as an identifier. The problem was in a wrong ordering of choices in the |Statement| rule together with aggressive reserved word detection in the |Identifier| rule. --- examples/javascript.pegjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/javascript.pegjs b/examples/javascript.pegjs index 3851746..3151b18 100644 --- a/examples/javascript.pegjs +++ b/examples/javascript.pegjs @@ -993,18 +993,23 @@ 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 Block = "{" __ body:(StatementList __)? "}" {