[refactoring] update ast structure of "MagicConstant" and "String" nodes

This commit is contained in:
Vadym Slizov 2020-11-20 23:53:58 +02:00
parent e6a23dfa3a
commit 3bda40e8ce
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 1374 additions and 1349 deletions

590
internal/php5/php5.go generated

File diff suppressed because it is too large Load Diff

View File

@ -4020,15 +4020,19 @@ combined_scalar_offset:
} }
| T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']' | T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
{ {
str := &ast.ScalarString{ast.Node{}, $1.Value} str := &ast.ScalarString{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
StringTkn: $1,
Value: $1.Value,
}
$$ = &ast.ExprArrayDimFetch{ast.Node{}, str, $3} $$ = &ast.ExprArrayDimFetch{ast.Node{}, str, $3}
// save position // save position
str.GetNode().Position = position.NewTokenPosition($1)
$$.GetNode().Position = position.NewNodeTokenPosition(str, $4) $$.GetNode().Position = position.NewNodeTokenPosition(str, $4)
// save comments // save comments
yylex.(*Parser).setFreeFloating(str, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens) yylex.(*Parser).setFreeFloatingTokens($$, token.Var, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens) yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.SkippedTokens)
} }
@ -4517,83 +4521,83 @@ common_scalar:
} }
| T_CONSTANT_ENCAPSED_STRING | T_CONSTANT_ENCAPSED_STRING
{ {
$$ = &ast.ScalarString{ast.Node{}, $1.Value} $$ = &ast.ScalarString{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
StringTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_LINE | T_LINE
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_FILE | T_FILE
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_DIR | T_DIR
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_TRAIT_C | T_TRAIT_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_METHOD_C | T_METHOD_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_FUNC_C | T_FUNC_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_NS_C | T_NS_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ {
@ -4734,13 +4738,13 @@ static_scalar_value:
} }
| T_CLASS_C | T_CLASS_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| static_operation | static_operation
{ {
@ -5213,13 +5217,13 @@ scalar:
} }
| T_CLASS_C | T_CLASS_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
; ;
@ -6151,13 +6155,13 @@ encaps_var:
encaps_var_offset: encaps_var_offset:
T_STRING T_STRING
{ {
$$ = &ast.ScalarString{ast.Node{}, $1.Value} $$ = &ast.ScalarString{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
StringTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_NUM_STRING | T_NUM_STRING
{ {
@ -6171,7 +6175,13 @@ encaps_var_offset:
Value: $1.Value, Value: $1.Value,
} }
} else { } else {
$$ = &ast.ScalarString{ast.Node{}, $1.Value} $$ = &ast.ScalarString{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
StringTkn: $1,
Value: $1.Value,
}
} }
// save position // save position

197
internal/php7/php7.go generated
View File

@ -347,7 +347,7 @@ const yyEofCode = 1
const yyErrCode = 2 const yyErrCode = 2
const yyInitialStackSize = 16 const yyInitialStackSize = 16
// line internal/php7/php7.y:4988 // line internal/php7/php7.y:4989
// line yacctab:1 // line yacctab:1
var yyExca = [...]int{ var yyExca = [...]int{
@ -6541,13 +6541,13 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:3933 // line internal/php7/php7.y:3933
{ {
yyVAL.node = &ast.ScalarString{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarString{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
StringTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 402: case 402:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
@ -6577,97 +6577,97 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:3966 // line internal/php7/php7.y:3966
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 405: case 405:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:3976 // line internal/php7/php7.y:3976
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 406: case 406:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:3986 // line internal/php7/php7.y:3986
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 407: case 407:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:3996 // line internal/php7/php7.y:3996
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 408: case 408:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4006 // line internal/php7/php7.y:4006
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 409: case 409:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4016 // line internal/php7/php7.y:4016
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 410: case 410:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4026 // line internal/php7/php7.y:4026
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 411: case 411:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4036 // line internal/php7/php7.y:4036
{ {
yyVAL.node = &ast.ScalarMagicConstant{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
MagicConstTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 412: case 412:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
@ -7497,13 +7497,13 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4792 // line internal/php7/php7.y:4792
{ {
yyVAL.node = &ast.ScalarString{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarString{
Node: ast.Node{
// save position Position: position.NewTokenPosition(yyDollar[1].token),
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token) },
StringTkn: yyDollar[1].token,
// save comments Value: yyDollar[1].token.Value,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) }
} }
case 482: case 482:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
@ -7519,14 +7519,14 @@ yydefault:
Value: yyDollar[1].token.Value, Value: yyDollar[1].token.Value,
} }
} else { } else {
yyVAL.node = &ast.ScalarString{ast.Node{}, yyDollar[1].token.Value} yyVAL.node = &ast.ScalarString{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
StringTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
}
} }
// save position
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token)
// save comments
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens)
} }
case 483: case 483:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
@ -7544,20 +7544,21 @@ yydefault:
Value: yyDollar[2].token.Value, Value: yyDollar[2].token.Value,
} }
yyVAL.node = &ast.ExprUnaryMinus{ast.Node{}, lnumber} yyVAL.node = &ast.ExprUnaryMinus{ast.Node{}, lnumber}
} else {
yyDollar[2].token.Value = append([]byte("-"), yyDollar[2].token.Value...)
yyVAL.node = &ast.ScalarString{ast.Node{}, yyDollar[2].token.Value}
}
// save position
yyVAL.node.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[2].token) yyVAL.node.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[2].token)
} else {
// save comments yyVAL.node = &ast.ScalarString{
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens) Node: ast.Node{
Position: position.NewTokensPosition(yyDollar[1].token, yyDollar[2].token),
},
MinusTkn: yyDollar[1].token,
StringTkn: yyDollar[2].token,
Value: append([]byte("-"), yyDollar[2].token.Value...),
}
}
} }
case 484: case 484:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4848 // line internal/php7/php7.y:4849
{ {
identifier := &ast.Identifier{ identifier := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7576,7 +7577,7 @@ yydefault:
} }
case 485: case 485:
yyDollar = yyS[yypt-5 : yypt+1] yyDollar = yyS[yypt-5 : yypt+1]
// line internal/php7/php7.y:4868 // line internal/php7/php7.y:4869
{ {
yyVAL.node = &ast.ExprIsset{ast.Node{}, yyDollar[3].list} yyVAL.node = &ast.ExprIsset{ast.Node{}, yyDollar[3].list}
@ -7594,7 +7595,7 @@ yydefault:
} }
case 486: case 486:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4884 // line internal/php7/php7.y:4885
{ {
exprBrackets := &ast.ParserBrackets{ exprBrackets := &ast.ParserBrackets{
Node: ast.Node{ Node: ast.Node{
@ -7616,7 +7617,7 @@ yydefault:
} }
case 487: case 487:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4904 // line internal/php7/php7.y:4905
{ {
yyVAL.node = &ast.ExprInclude{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprInclude{ast.Node{}, yyDollar[2].node}
@ -7628,7 +7629,7 @@ yydefault:
} }
case 488: case 488:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4914 // line internal/php7/php7.y:4915
{ {
yyVAL.node = &ast.ExprIncludeOnce{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprIncludeOnce{ast.Node{}, yyDollar[2].node}
@ -7640,7 +7641,7 @@ yydefault:
} }
case 489: case 489:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4924 // line internal/php7/php7.y:4925
{ {
exprBrackets := &ast.ParserBrackets{ exprBrackets := &ast.ParserBrackets{
Node: ast.Node{ Node: ast.Node{
@ -7662,7 +7663,7 @@ yydefault:
} }
case 490: case 490:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4944 // line internal/php7/php7.y:4945
{ {
yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node}
@ -7674,7 +7675,7 @@ yydefault:
} }
case 491: case 491:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4954 // line internal/php7/php7.y:4955
{ {
yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node}
@ -7686,13 +7687,13 @@ yydefault:
} }
case 492: case 492:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4967 // line internal/php7/php7.y:4968
{ {
yyVAL.list = []ast.Vertex{yyDollar[1].node} yyVAL.list = []ast.Vertex{yyDollar[1].node}
} }
case 493: case 493:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4971 // line internal/php7/php7.y:4972
{ {
yyVAL.list = append(yyDollar[1].list, yyDollar[3].node) yyVAL.list = append(yyDollar[1].list, yyDollar[3].node)
@ -7701,7 +7702,7 @@ yydefault:
} }
case 494: case 494:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4981 // line internal/php7/php7.y:4982
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }

View File

@ -3931,13 +3931,13 @@ dereferencable_scalar:
} }
| T_CONSTANT_ENCAPSED_STRING | T_CONSTANT_ENCAPSED_STRING
{ {
$$ = &ast.ScalarString{ast.Node{}, $1.Value} $$ = &ast.ScalarString{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
StringTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
; ;
@ -3964,83 +3964,83 @@ scalar:
} }
| T_LINE | T_LINE
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_FILE | T_FILE
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_DIR | T_DIR
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_TRAIT_C | T_TRAIT_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_METHOD_C | T_METHOD_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_FUNC_C | T_FUNC_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_NS_C | T_NS_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_CLASS_C | T_CLASS_C
{ {
$$ = &ast.ScalarMagicConstant{ast.Node{}, $1.Value} $$ = &ast.ScalarMagicConstant{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
MagicConstTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ {
@ -4790,13 +4790,13 @@ encaps_var:
encaps_var_offset: encaps_var_offset:
T_STRING T_STRING
{ {
$$ = &ast.ScalarString{ast.Node{}, $1.Value} $$ = &ast.ScalarString{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
StringTkn: $1,
// save comments Value: $1.Value,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| T_NUM_STRING | T_NUM_STRING
{ {
@ -4810,14 +4810,14 @@ encaps_var_offset:
Value: $1.Value, Value: $1.Value,
} }
} else { } else {
$$ = &ast.ScalarString{ast.Node{}, $1.Value} $$ = &ast.ScalarString{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
StringTkn: $1,
Value: $1.Value,
}
} }
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| '-' T_NUM_STRING | '-' T_NUM_STRING
{ {
@ -4833,16 +4833,17 @@ encaps_var_offset:
Value: $2.Value, Value: $2.Value,
} }
$$ = &ast.ExprUnaryMinus{ast.Node{}, lnumber} $$ = &ast.ExprUnaryMinus{ast.Node{}, lnumber}
} else {
$2.Value = append([]byte("-"), $2.Value...)
$$ = &ast.ScalarString{ast.Node{}, $2.Value}
}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $2) $$.GetNode().Position = position.NewTokensPosition($1, $2)
} else {
// save comments $$ = &ast.ScalarString{
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) Node: ast.Node{
Position: position.NewTokensPosition($1, $2),
},
MinusTkn: $1,
StringTkn: $2,
Value: append([]byte("-"), $2.Value...),
}
}
} }
| T_VARIABLE | T_VARIABLE
{ {

View File

@ -172,6 +172,7 @@ func (n *ScalarLnumber) Accept(v NodeVisitor) {
// ScalarMagicConstant node // ScalarMagicConstant node
type ScalarMagicConstant struct { type ScalarMagicConstant struct {
Node Node
MagicConstTkn *token.Token
Value []byte Value []byte
} }
@ -182,6 +183,8 @@ func (n *ScalarMagicConstant) Accept(v NodeVisitor) {
// ScalarString node // ScalarString node
type ScalarString struct { type ScalarString struct {
Node Node
MinusTkn *token.Token
StringTkn *token.Token
Value []byte Value []byte
} }