[refactoring] update ast structure of "MagicConstant" and "String" nodes
This commit is contained in:
parent
e6a23dfa3a
commit
3bda40e8ce
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -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
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -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}
|
||||||
|
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
||||||
} else {
|
} else {
|
||||||
$2.Value = append([]byte("-"), $2.Value...)
|
$$ = &ast.ScalarString{
|
||||||
$$ = &ast.ScalarString{ast.Node{}, $2.Value}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $2),
|
||||||
|
},
|
||||||
|
MinusTkn: $1,
|
||||||
|
StringTkn: $2,
|
||||||
|
Value: append([]byte("-"), $2.Value...),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// save position
|
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_VARIABLE
|
| T_VARIABLE
|
||||||
{
|
{
|
||||||
|
@ -172,7 +172,8 @@ func (n *ScalarLnumber) Accept(v NodeVisitor) {
|
|||||||
// ScalarMagicConstant node
|
// ScalarMagicConstant node
|
||||||
type ScalarMagicConstant struct {
|
type ScalarMagicConstant struct {
|
||||||
Node
|
Node
|
||||||
Value []byte
|
MagicConstTkn *token.Token
|
||||||
|
Value []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ScalarMagicConstant) Accept(v NodeVisitor) {
|
func (n *ScalarMagicConstant) Accept(v NodeVisitor) {
|
||||||
@ -182,7 +183,9 @@ func (n *ScalarMagicConstant) Accept(v NodeVisitor) {
|
|||||||
// ScalarString node
|
// ScalarString node
|
||||||
type ScalarString struct {
|
type ScalarString struct {
|
||||||
Node
|
Node
|
||||||
Value []byte
|
MinusTkn *token.Token
|
||||||
|
StringTkn *token.Token
|
||||||
|
Value []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ScalarString) Accept(v NodeVisitor) {
|
func (n *ScalarString) Accept(v NodeVisitor) {
|
||||||
|
Loading…
Reference in New Issue
Block a user