From e32faa4e040b94495c82d470cfe6b38bfa3b1e35 Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Mon, 4 Dec 2023 18:24:55 +0200 Subject: [PATCH] Implement 'for...of' and reserve 'let' in the example JS grammar --- examples/javascript.pegjs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/examples/javascript.pegjs b/examples/javascript.pegjs index 06844474..bc80ecf9 100644 --- a/examples/javascript.pegjs +++ b/examples/javascript.pegjs @@ -186,6 +186,7 @@ Keyword / InstanceofToken / InToken / NewToken + / OfToken / ReturnToken / SwitchToken / ThisToken @@ -204,6 +205,7 @@ FutureReservedWord / ExportToken / ExtendsToken / ImportToken + / LetToken / SuperToken Literal @@ -452,8 +454,10 @@ IfToken = "if" !IdentifierPart ImportToken = "import" !IdentifierPart InstanceofToken = "instanceof" !IdentifierPart InToken = "in" !IdentifierPart +LetToken = "let" !IdentifierPart NewToken = "new" !IdentifierPart NullToken = "null" !IdentifierPart +OfToken = "of" !IdentifierPart ReturnToken = "return" !IdentifierPart SetToken = "set" !IdentifierPart SuperToken = "super" !IdentifierPart @@ -1150,6 +1154,40 @@ IterationStatement body: body }; } + / ForToken __ + "(" __ + left:LeftHandSideExpression __ + OfToken __ + right:Expression __ + ")" __ + body:Statement + { + return { + type: "ForOfStatement", + left: left, + right: right, + body: body + }; + } + / ForToken __ + "(" __ + VarToken __ declarations:VariableDeclarationListNoIn __ + OfToken __ + right:Expression __ + ")" __ + body:Statement + { + return { + type: "ForOfStatement", + left: { + type: "VariableDeclaration", + declarations: declarations, + kind: "var" + }, + right: right, + body: body + }; + } ContinueStatement = ContinueToken EOS {