Skip to content

Commit

Permalink
Implement 'for...of' and reserve 'let' in the example JS grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed Dec 4, 2023
1 parent 8aa207c commit e32faa4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/javascript.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Keyword
/ InstanceofToken
/ InToken
/ NewToken
/ OfToken
/ ReturnToken
/ SwitchToken
/ ThisToken
Expand All @@ -204,6 +205,7 @@ FutureReservedWord
/ ExportToken
/ ExtendsToken
/ ImportToken
/ LetToken
/ SuperToken

Literal
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e32faa4

Please sign in to comment.