Skip to content

Commit b85bae2

Browse files
committed
refactoring: update ast structure of "Closure" and "ClosureUse" nodes
1 parent 03c7979 commit b85bae2

14 files changed

+1071
-996
lines changed

internal/php5/parser_test.go

+204-202
Large diffs are not rendered by default.

internal/php5/php5.go

+288-281
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/php5/php5.y

+69-62
Original file line numberDiff line numberDiff line change
@@ -3367,36 +3367,38 @@ expr_without_variable:
33673367
}
33683368
| function is_reference '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
33693369
{
3370-
$$ = &ast.ExprClosure{
3371-
Position: yylex.(*Parser).builder.NewTokensPosition($1, $9),
3372-
FunctionTkn: $1,
3373-
AmpersandTkn: $2,
3374-
OpenParenthesisTkn: $3,
3375-
Params: $4.(*ast.ParserSeparatedList).Items,
3376-
SeparatorTkns: $4.(*ast.ParserSeparatedList).SeparatorTkns,
3377-
CloseParenthesisTkn: $5,
3378-
ClosureUse: $6,
3379-
OpenCurlyBracketTkn: $7,
3380-
Stmts: $8,
3381-
CloseCurlyBracketTkn: $9,
3382-
}
3370+
closure := $6.(*ast.ExprClosure)
3371+
3372+
closure.Position = yylex.(*Parser).builder.NewTokensPosition($1, $9)
3373+
closure.FunctionTkn = $1
3374+
closure.AmpersandTkn = $2
3375+
closure.OpenParenthesisTkn = $3
3376+
closure.Params = $4.(*ast.ParserSeparatedList).Items
3377+
closure.SeparatorTkns = $4.(*ast.ParserSeparatedList).SeparatorTkns
3378+
closure.CloseParenthesisTkn = $5
3379+
closure.OpenCurlyBracketTkn = $7
3380+
closure.Stmts = $8
3381+
closure.CloseCurlyBracketTkn = $9
3382+
3383+
$$ = closure
33833384
}
33843385
| T_STATIC function is_reference '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
33853386
{
3386-
$$ = &ast.ExprClosure{
3387-
Position: yylex.(*Parser).builder.NewTokensPosition($1, $10),
3388-
StaticTkn: $1,
3389-
FunctionTkn: $2,
3390-
AmpersandTkn: $3,
3391-
OpenParenthesisTkn: $4,
3392-
Params: $5.(*ast.ParserSeparatedList).Items,
3393-
SeparatorTkns: $5.(*ast.ParserSeparatedList).SeparatorTkns,
3394-
CloseParenthesisTkn: $6,
3395-
ClosureUse: $7,
3396-
OpenCurlyBracketTkn: $8,
3397-
Stmts: $9,
3398-
CloseCurlyBracketTkn: $10,
3399-
}
3387+
closure := $7.(*ast.ExprClosure)
3388+
3389+
closure.Position = yylex.(*Parser).builder.NewTokensPosition($1, $10)
3390+
closure.StaticTkn = $1
3391+
closure.FunctionTkn = $2
3392+
closure.AmpersandTkn = $3
3393+
closure.OpenParenthesisTkn = $4
3394+
closure.Params = $5.(*ast.ParserSeparatedList).Items
3395+
closure.SeparatorTkns = $5.(*ast.ParserSeparatedList).SeparatorTkns
3396+
closure.CloseParenthesisTkn = $6
3397+
closure.OpenCurlyBracketTkn = $8
3398+
closure.Stmts = $9
3399+
closure.CloseCurlyBracketTkn = $10
3400+
3401+
$$ = closure
34003402
}
34013403
;
34023404

@@ -3520,30 +3522,32 @@ function:
35203522
lexical_vars:
35213523
/* empty */
35223524
{
3523-
$$ = nil
3525+
$$ = &ast.ExprClosure{}
35243526
}
35253527
| T_USE '(' lexical_var_list ')'
35263528
{
3527-
$$ = &ast.ExprClosureUse{
3528-
Position: yylex.(*Parser).builder.NewTokensPosition($1, $4),
3529-
UseTkn: $1,
3530-
OpenParenthesisTkn: $2,
3531-
Uses: $3.(*ast.ParserSeparatedList).Items,
3532-
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
3533-
CloseParenthesisTkn: $4,
3529+
$$ = &ast.ExprClosure{
3530+
UseTkn: $1,
3531+
UseOpenParenthesisTkn: $2,
3532+
Use: $3.(*ast.ParserSeparatedList).Items,
3533+
UseSeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
3534+
UseCloseParenthesisTkn: $4,
35343535
}
35353536
}
35363537
;
35373538

35383539
lexical_var_list:
35393540
lexical_var_list ',' T_VARIABLE
35403541
{
3541-
variable := &ast.ExprVariable{
3542+
variable := &ast.ExprClosureUse{
35423543
Position: yylex.(*Parser).builder.NewTokenPosition($3),
3543-
VarName: &ast.Identifier{
3544+
Var: &ast.ExprVariable{
35443545
Position: yylex.(*Parser).builder.NewTokenPosition($3),
3545-
IdentifierTkn: $3,
3546-
Value: $3.Value,
3546+
VarName: &ast.Identifier{
3547+
Position: yylex.(*Parser).builder.NewTokenPosition($3),
3548+
IdentifierTkn: $3,
3549+
Value: $3.Value,
3550+
},
35473551
},
35483552
}
35493553

@@ -3554,7 +3558,7 @@ lexical_var_list:
35543558
}
35553559
| lexical_var_list ',' '&' T_VARIABLE
35563560
{
3557-
reference := &ast.ExprReference{
3561+
variable := &ast.ExprClosureUse{
35583562
Position: yylex.(*Parser).builder.NewTokensPosition($3, $4),
35593563
AmpersandTkn: $3,
35603564
Var: &ast.ExprVariable{
@@ -3568,43 +3572,46 @@ lexical_var_list:
35683572
}
35693573

35703574
$1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
3571-
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, reference)
3575+
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, variable)
35723576

35733577
$$ = $1
35743578
}
35753579
| T_VARIABLE
35763580
{
3577-
$$ = &ast.ParserSeparatedList{
3578-
Items: []ast.Vertex{
3579-
&ast.ExprVariable{
3581+
variable := &ast.ExprClosureUse{
3582+
Position: yylex.(*Parser).builder.NewTokenPosition($1),
3583+
Var: &ast.ExprVariable{
3584+
Position: yylex.(*Parser).builder.NewTokenPosition($1),
3585+
VarName: &ast.Identifier{
35803586
Position: yylex.(*Parser).builder.NewTokenPosition($1),
3581-
VarName: &ast.Identifier{
3582-
Position: yylex.(*Parser).builder.NewTokenPosition($1),
3583-
IdentifierTkn: $1,
3584-
Value: $1.Value,
3585-
},
3587+
IdentifierTkn: $1,
3588+
Value: $1.Value,
35863589
},
35873590
},
35883591
}
3592+
3593+
$$ = &ast.ParserSeparatedList{
3594+
Items: []ast.Vertex{ variable },
3595+
}
35893596
}
35903597
| '&' T_VARIABLE
35913598
{
3592-
$$ = &ast.ParserSeparatedList{
3593-
Items: []ast.Vertex{
3594-
&ast.ExprReference{
3595-
Position: yylex.(*Parser).builder.NewTokensPosition($1, $2),
3596-
AmpersandTkn: $1,
3597-
Var: &ast.ExprVariable{
3598-
Position: yylex.(*Parser).builder.NewTokenPosition($2),
3599-
VarName: &ast.Identifier{
3600-
Position: yylex.(*Parser).builder.NewTokenPosition($2),
3601-
IdentifierTkn: $2,
3602-
Value: $2.Value,
3603-
},
3604-
},
3599+
variable := &ast.ExprClosureUse{
3600+
Position: yylex.(*Parser).builder.NewTokensPosition($1, $2),
3601+
AmpersandTkn: $1,
3602+
Var: &ast.ExprVariable{
3603+
Position: yylex.(*Parser).builder.NewTokenPosition($2),
3604+
VarName: &ast.Identifier{
3605+
Position: yylex.(*Parser).builder.NewTokenPosition($2),
3606+
IdentifierTkn: $2,
3607+
Value: $2.Value,
36053608
},
36063609
},
36073610
}
3611+
3612+
$$ = &ast.ParserSeparatedList{
3613+
Items: []ast.Vertex{ variable },
3614+
}
36083615
}
36093616
;
36103617

0 commit comments

Comments
 (0)