refactoring: update ast structure of "Foreach" node
This commit is contained in:
@@ -16524,61 +16524,53 @@ func TestStmtForeach_WithRef(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Var: &ast.ExprReference{
|
||||
AmpersandTkn: &token.Token{
|
||||
ID: token.ID(38),
|
||||
Value: []byte("&"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 24,
|
||||
EndPos: 27,
|
||||
EndPos: 25,
|
||||
},
|
||||
AmpersandTkn: &token.Token{
|
||||
ID: token.ID(38),
|
||||
Value: []byte("&"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 24,
|
||||
EndPos: 25,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 23,
|
||||
EndPos: 24,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 23,
|
||||
EndPos: 24,
|
||||
},
|
||||
},
|
||||
},
|
||||
Var: &ast.ExprVariable{
|
||||
},
|
||||
Var: &ast.ExprVariable{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 25,
|
||||
EndPos: 27,
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 25,
|
||||
EndPos: 27,
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$v"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 25,
|
||||
EndPos: 27,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$v"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 25,
|
||||
EndPos: 27,
|
||||
},
|
||||
},
|
||||
Value: []byte("$v"),
|
||||
},
|
||||
Value: []byte("$v"),
|
||||
},
|
||||
},
|
||||
CloseParenthesisTkn: &token.Token{
|
||||
@@ -36268,7 +36260,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
EndPos: 36,
|
||||
},
|
||||
FunctionTkn: &token.Token{
|
||||
ID: token.T_FUNCTION,
|
||||
ID: token.T_FUNCTION,
|
||||
Value: []byte("function"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36278,7 +36270,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_OPEN_TAG,
|
||||
ID: token.T_OPEN_TAG,
|
||||
Value: []byte("<?"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36288,7 +36280,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36300,7 +36292,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
OpenParenthesisTkn: &token.Token{
|
||||
ID: token.ID(40),
|
||||
ID: token.ID(40),
|
||||
Value: []byte("("),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36332,7 +36324,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
EndPos: 14,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$a"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36367,7 +36359,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
EndPos: 18,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$b"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36377,7 +36369,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36395,7 +36387,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
SeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36406,7 +36398,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
CloseParenthesisTkn: &token.Token{
|
||||
ID: token.ID(41),
|
||||
ID: token.ID(41),
|
||||
Value: []byte(")"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36416,7 +36408,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
UseTkn: &token.Token{
|
||||
ID: token.T_USE,
|
||||
ID: token.T_USE,
|
||||
Value: []byte("use"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36426,7 +36418,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36438,7 +36430,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
UseOpenParenthesisTkn: &token.Token{
|
||||
ID: token.ID(40),
|
||||
ID: token.ID(40),
|
||||
Value: []byte("("),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36448,7 +36440,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36482,7 +36474,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
EndPos: 27,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$c"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36503,7 +36495,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
EndPos: 32,
|
||||
},
|
||||
AmpersandTkn: &token.Token{
|
||||
ID: token.ID(38),
|
||||
ID: token.ID(38),
|
||||
Value: []byte("&"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36513,7 +36505,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36539,7 +36531,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
EndPos: 32,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$d"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36555,7 +36547,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
UseSeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36566,7 +36558,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
UseCloseParenthesisTkn: &token.Token{
|
||||
ID: token.ID(41),
|
||||
ID: token.ID(41),
|
||||
Value: []byte(")"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36576,7 +36568,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36586,7 +36578,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36599,7 +36591,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
Stmts: []ast.Vertex{},
|
||||
CloseCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(125),
|
||||
ID: token.ID(125),
|
||||
Value: []byte("}"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36610,7 +36602,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
SemiColonTkn: &token.Token{
|
||||
ID: token.ID(59),
|
||||
ID: token.ID(59),
|
||||
Value: []byte(";"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36621,8 +36613,7 @@ func TestExprClosure_Use(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
EndTkn: &token.Token{
|
||||
},
|
||||
EndTkn: &token.Token{},
|
||||
}
|
||||
|
||||
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
|
||||
@@ -36658,7 +36649,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
EndPos: 36,
|
||||
},
|
||||
FunctionTkn: &token.Token{
|
||||
ID: token.T_FUNCTION,
|
||||
ID: token.T_FUNCTION,
|
||||
Value: []byte("function"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36668,7 +36659,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_OPEN_TAG,
|
||||
ID: token.T_OPEN_TAG,
|
||||
Value: []byte("<?"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36678,7 +36669,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36690,7 +36681,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
OpenParenthesisTkn: &token.Token{
|
||||
ID: token.ID(40),
|
||||
ID: token.ID(40),
|
||||
Value: []byte("("),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36722,7 +36713,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
EndPos: 14,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$a"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36757,7 +36748,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
EndPos: 18,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$b"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36767,7 +36758,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36785,7 +36776,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
SeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36796,7 +36787,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
CloseParenthesisTkn: &token.Token{
|
||||
ID: token.ID(41),
|
||||
ID: token.ID(41),
|
||||
Value: []byte(")"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36806,7 +36797,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
UseTkn: &token.Token{
|
||||
ID: token.T_USE,
|
||||
ID: token.T_USE,
|
||||
Value: []byte("use"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36816,7 +36807,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36828,7 +36819,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
UseOpenParenthesisTkn: &token.Token{
|
||||
ID: token.ID(40),
|
||||
ID: token.ID(40),
|
||||
Value: []byte("("),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36838,7 +36829,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36858,7 +36849,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
EndPos: 28,
|
||||
},
|
||||
AmpersandTkn: &token.Token{
|
||||
ID: token.ID(38),
|
||||
ID: token.ID(38),
|
||||
Value: []byte("&"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36882,7 +36873,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
EndPos: 28,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$c"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36917,7 +36908,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
EndPos: 32,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$d"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36927,7 +36918,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36945,7 +36936,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
UseSeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36956,7 +36947,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
UseCloseParenthesisTkn: &token.Token{
|
||||
ID: token.ID(41),
|
||||
ID: token.ID(41),
|
||||
Value: []byte(")"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36966,7 +36957,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36976,7 +36967,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -36989,7 +36980,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
Stmts: []ast.Vertex{},
|
||||
CloseCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(125),
|
||||
ID: token.ID(125),
|
||||
Value: []byte("}"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -37000,7 +36991,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
SemiColonTkn: &token.Token{
|
||||
ID: token.ID(59),
|
||||
ID: token.ID(59),
|
||||
Value: []byte(";"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -37011,8 +37002,7 @@ func TestExprClosure_Use2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
EndTkn: &token.Token{
|
||||
},
|
||||
EndTkn: &token.Token{},
|
||||
}
|
||||
|
||||
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
|
||||
@@ -43525,309 +43515,6 @@ func TestExprPropertyFetch(t *testing.T) {
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestExprReference_ForeachWithRef(t *testing.T) {
|
||||
t.Helper()
|
||||
src := `<? foreach ($a as $k => &$v) {}`
|
||||
|
||||
expected := &ast.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 3,
|
||||
EndPos: 31,
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtForeach{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 3,
|
||||
EndPos: 31,
|
||||
},
|
||||
ForeachTkn: &token.Token{
|
||||
ID: token.T_FOREACH,
|
||||
Value: []byte("foreach"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 3,
|
||||
EndPos: 10,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_OPEN_TAG,
|
||||
Value: []byte("<?"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 0,
|
||||
EndPos: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 2,
|
||||
EndPos: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenParenthesisTkn: &token.Token{
|
||||
ID: token.ID(40),
|
||||
Value: []byte("("),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 11,
|
||||
EndPos: 12,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 10,
|
||||
EndPos: 11,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Expr: &ast.ExprVariable{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 12,
|
||||
EndPos: 14,
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 12,
|
||||
EndPos: 14,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$a"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 12,
|
||||
EndPos: 14,
|
||||
},
|
||||
},
|
||||
Value: []byte("$a"),
|
||||
},
|
||||
},
|
||||
AsTkn: &token.Token{
|
||||
ID: token.T_AS,
|
||||
Value: []byte("as"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 15,
|
||||
EndPos: 17,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 14,
|
||||
EndPos: 15,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Key: &ast.ExprVariable{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 18,
|
||||
EndPos: 20,
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 18,
|
||||
EndPos: 20,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$k"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 18,
|
||||
EndPos: 20,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 17,
|
||||
EndPos: 18,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Value: []byte("$k"),
|
||||
},
|
||||
},
|
||||
DoubleArrowTkn: &token.Token{
|
||||
ID: token.T_DOUBLE_ARROW,
|
||||
Value: []byte("=>"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 21,
|
||||
EndPos: 23,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 20,
|
||||
EndPos: 21,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Var: &ast.ExprReference{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 24,
|
||||
EndPos: 27,
|
||||
},
|
||||
AmpersandTkn: &token.Token{
|
||||
ID: token.ID(38),
|
||||
Value: []byte("&"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 24,
|
||||
EndPos: 25,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 23,
|
||||
EndPos: 24,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Var: &ast.ExprVariable{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 25,
|
||||
EndPos: 27,
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 25,
|
||||
EndPos: 27,
|
||||
},
|
||||
IdentifierTkn: &token.Token{
|
||||
ID: token.T_VARIABLE,
|
||||
Value: []byte("$v"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 25,
|
||||
EndPos: 27,
|
||||
},
|
||||
},
|
||||
Value: []byte("$v"),
|
||||
},
|
||||
},
|
||||
},
|
||||
CloseParenthesisTkn: &token.Token{
|
||||
ID: token.ID(41),
|
||||
Value: []byte(")"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 27,
|
||||
EndPos: 28,
|
||||
},
|
||||
},
|
||||
Stmt: &ast.StmtStmtList{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 29,
|
||||
EndPos: 31,
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 29,
|
||||
EndPos: 30,
|
||||
},
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 28,
|
||||
EndPos: 29,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Stmts: []ast.Vertex{},
|
||||
CloseCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(125),
|
||||
Value: []byte("}"),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 30,
|
||||
EndPos: 31,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EndTkn: &token.Token{},
|
||||
}
|
||||
|
||||
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
|
||||
php7parser := php7.NewParser(lexer, nil)
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestExprShellExec(t *testing.T) {
|
||||
src := "<? `cmd $a`;"
|
||||
|
||||
|
||||
742
internal/php7/php7.go
generated
742
internal/php7/php7.go
generated
File diff suppressed because it is too large
Load Diff
@@ -962,29 +962,43 @@ statement:
|
||||
}
|
||||
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
|
||||
{
|
||||
$7.(*ast.StmtForeach).ForeachTkn = $1
|
||||
$7.(*ast.StmtForeach).OpenParenthesisTkn = $2
|
||||
$7.(*ast.StmtForeach).Expr = $3
|
||||
$7.(*ast.StmtForeach).AsTkn = $4
|
||||
$7.(*ast.StmtForeach).Var = $5
|
||||
$7.(*ast.StmtForeach).CloseParenthesisTkn = $6
|
||||
$7.(*ast.StmtForeach).Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $7)
|
||||
foreach := $7.(*ast.StmtForeach)
|
||||
|
||||
$$ = $7
|
||||
foreach.Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $7)
|
||||
foreach.ForeachTkn = $1
|
||||
foreach.OpenParenthesisTkn = $2
|
||||
foreach.Expr = $3
|
||||
foreach.AsTkn = $4
|
||||
foreach.Var = $5
|
||||
foreach.CloseParenthesisTkn = $6
|
||||
|
||||
if val, ok := $5.(*ast.ExprReference); ok {
|
||||
foreach.AmpersandTkn = val.AmpersandTkn
|
||||
foreach.Var = val.Var
|
||||
}
|
||||
|
||||
$$ = foreach
|
||||
}
|
||||
| T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement
|
||||
{
|
||||
$9.(*ast.StmtForeach).ForeachTkn = $1
|
||||
$9.(*ast.StmtForeach).OpenParenthesisTkn = $2
|
||||
$9.(*ast.StmtForeach).Expr = $3
|
||||
$9.(*ast.StmtForeach).AsTkn = $4
|
||||
$9.(*ast.StmtForeach).Key = $5
|
||||
$9.(*ast.StmtForeach).DoubleArrowTkn = $6
|
||||
$9.(*ast.StmtForeach).Var = $7
|
||||
$9.(*ast.StmtForeach).CloseParenthesisTkn = $8
|
||||
$9.(*ast.StmtForeach).Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $9)
|
||||
foreach := $9.(*ast.StmtForeach)
|
||||
|
||||
$$ = $9
|
||||
foreach.Position = yylex.(*Parser).builder.NewTokenNodePosition($1, $9)
|
||||
foreach.ForeachTkn = $1
|
||||
foreach.OpenParenthesisTkn = $2
|
||||
foreach.Expr = $3
|
||||
foreach.AsTkn = $4
|
||||
foreach.Key = $5
|
||||
foreach.DoubleArrowTkn = $6
|
||||
foreach.Var = $7
|
||||
foreach.CloseParenthesisTkn = $8
|
||||
|
||||
if val, ok := $7.(*ast.ExprReference); ok {
|
||||
foreach.AmpersandTkn = val.AmpersandTkn
|
||||
foreach.Var = val.Var
|
||||
}
|
||||
|
||||
$$ = foreach
|
||||
}
|
||||
| T_DECLARE '(' const_list ')' declare_statement
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user