[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 182 additions and 168 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

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

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

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

View File

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