Skip to content

Commit

Permalink
try to fix ForStatement and VariableDeclarationList
Browse files Browse the repository at this point in the history
  • Loading branch information
w-y committed May 22, 2017
1 parent b8f4649 commit e5f88c2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
11 changes: 7 additions & 4 deletions src/bnf/IterationStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module.exports = {
'while LeftParenthesis Expression_In RightParenthesis Statement',

'for LeftParenthesis LexicalDeclaration Expression_In ; Expression_In RightParenthesis Statement',
'for LeftParenthesis var VariableDeclarationList ; Expression_In ; Expression_In RightParenthesis Statement',
'for LeftParenthesis VAR VariableDeclarationList ; Expression_In ; Expression_In RightParenthesis Statement',

'for LeftParenthesis LeftHandSideExpression in Expression_In RightParenthesis Statement',
'for LeftParenthesis ForDeclaration in Expression_In RightParenthesis Statement',

'for LeftParenthesis LeftHandSideExpression of AssignmentExpression_In RightParenthesis Statement',
'for LeftParenthesis var ForBinding of AssignmentExpression_In RightParenthesis Statement',
'for LeftParenthesis VAR ForBinding of AssignmentExpression_In RightParenthesis Statement',
'for LeftParenthesis ForDeclaration of AssignmentExpression_In RightParenthesis Statement',

'for LeftParenthesis Expression ; Expression_In ; Expression_In RightParenthesis Statement',
Expand All @@ -34,7 +34,8 @@ module.exports = {
`,
`
require('./ast/IterationStatement').checkForAutoSemicolonInsertion(yy.autoInsertionOffset, $2.range, $9.range, yy.lexer.yylloc);
$$ = new (require('./ast/IterationStatement').ForStatementNode)($4, $6, $8, $10, { loc: this._$, yy })
$$ = new (require('./ast/IterationStatement').ForStatementNode)(
new (require('./ast/VariableStatement').VariableStatementNode)($4, { loc: $3, yy }), $6, $8, $10, { loc: this._$, yy });
`,

`
Expand All @@ -52,7 +53,8 @@ module.exports = {
`,
`
require('./ast/IterationStatement').checkForAutoSemicolonInsertion(yy.autoInsertionOffset, $2.range, $7.range, yy.lexer.yylloc);
$$ = new (require('./ast/IterationStatement').ForOfStatementNode)($4, $6, $8, { loc: this._$, yy })
$$ = new (require('./ast/IterationStatement').ForOfStatementNode)(
new (require('./ast/VariableStatement').VariableStatementNode)($4, { loc: $3, yy }), $6, $8, { loc: this._$, yy });
`,
`
require('./ast/IterationStatement').checkForAutoSemicolonInsertion(yy.autoInsertionOffset, $2.range, $6.range, yy.lexer.yylloc);
Expand Down Expand Up @@ -105,5 +107,6 @@ module.exports = {
require('./Expression'),
require('./LeftParenthesis'),
require('./RightParenthesis'),
require('./Var'),
],
};
10 changes: 6 additions & 4 deletions src/bnf/IterationStatement_Return.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module.exports = {
'while LeftParenthesis Expression_In RightParenthesis Statement_Return',

'for LeftParenthesis LexicalDeclaration Expression_In ; Expression_In RightParenthesis Statement_Return',
'for LeftParenthesis var VariableDeclarationList ; Expression_In ; Expression_In RightParenthesis Statement_Return',
'for LeftParenthesis VAR VariableDeclarationList ; Expression_In ; Expression_In RightParenthesis Statement_Return',

'for LeftParenthesis LeftHandSideExpression in Expression_In RightParenthesis Statement_Return',
'for LeftParenthesis ForDeclaration in Expression_In RightParenthesis Statement_Return',

'for LeftParenthesis LeftHandSideExpression of AssignmentExpression_In RightParenthesis Statement_Return',
'for LeftParenthesis var ForBinding of AssignmentExpression_In RightParenthesis Statement_Return',
'for LeftParenthesis VAR ForBinding of AssignmentExpression_In RightParenthesis Statement_Return',
'for LeftParenthesis ForDeclaration of AssignmentExpression_In RightParenthesis Statement_Return',

'for LeftParenthesis Expression ; Expression_In ; Expression_In RightParenthesis Statement_Return',
Expand All @@ -34,7 +34,8 @@ module.exports = {
`,
`
require('./ast/IterationStatement').checkForAutoSemicolonInsertion(yy.autoInsertionOffset, $2.range, $9.range, yy.lexer.yylloc);
$$ = new (require('./ast/IterationStatement').ForStatementNode)($4, $6, $8, $10, { loc: this._$, yy })
$$ = new (require('./ast/IterationStatement').ForStatementNode)(
new (require('./ast/VariableStatement').VariableStatementNode)($4, { loc: $3, yy }), $6, $8, $10, { loc: this._$, yy });
`,

`
Expand All @@ -52,7 +53,8 @@ module.exports = {
`,
`
require('./ast/IterationStatement').checkForAutoSemicolonInsertion(yy.autoInsertionOffset, $2.range, $7.range, yy.lexer.yylloc);
$$ = new (require('./ast/IterationStatement').ForOfStatementNode)($4, $6, $8, { loc: this._$, yy })
$$ = new (require('./ast/IterationStatement').ForOfStatementNode)(
new (require('./ast/VariableStatement').VariableStatementNode)($4, { loc: $3, yy }), $6, $8, { loc: this._$, yy });
`,
`
require('./ast/IterationStatement').checkForAutoSemicolonInsertion(yy.autoInsertionOffset, $2.range, $6.range, yy.lexer.yylloc);
Expand Down
12 changes: 12 additions & 0 deletions src/bnf/Var.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
conditions: [''],
name: 'Var',
rules: [
'var',
],
handlers: [
'$$ = this._$'
],
subRules: [
],
};
4 changes: 2 additions & 2 deletions src/bnf/VariableDeclarationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module.exports = {
'VariableDeclarationList , VariableDeclaration',
],
handlers: [
'$$ = $1;',
'$$ = $1;$$.declarations.concat($3.declarations);',
'$$ = [$1];',
'$$ = $1.concat([$3]);'
],
subRules: [
require('./VariableDeclaration'),
Expand Down
2 changes: 1 addition & 1 deletion src/bnf/VariableDeclarationList_In.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
],
handlers: [
'$$ = [$1]',
'$$ = $1.concat($3)',
'$$ = $1.concat([$3])',
],
subRules: [
require('./VariableDeclaration_In'),
Expand Down
7 changes: 4 additions & 3 deletions src/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5f88c2

Please sign in to comment.