[refactoring] keep $ in variable identifier

This commit is contained in:
Vadym Slizov 2020-06-30 00:45:15 +03:00
parent d7652b1c7f
commit ee3fe3b5c0
13 changed files with 1506 additions and 1599 deletions

View File

@ -2,7 +2,6 @@ package php5
import ( import (
"bytes" "bytes"
"fmt"
"github.com/z7zmey/php-parser/internal/scanner" "github.com/z7zmey/php-parser/internal/scanner"
"github.com/z7zmey/php-parser/pkg/ast" "github.com/z7zmey/php-parser/pkg/ast"
@ -63,10 +62,6 @@ func lastNode(nn []ast.Vertex) ast.Vertex {
return nn[len(nn)-1] return nn[len(nn)-1]
} }
func isDollar(r rune) bool {
return r == '$'
}
func (p *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) { func (p *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) {
if p.withTokens == false { if p.withTokens == false {
return return
@ -110,19 +105,6 @@ func (p *Parser) GetFreeFloatingToken(t *scanner.Token) []token.Token {
} }
} }
func (p *Parser) addDollarToken(v ast.Vertex) {
if p.withTokens == false {
return
}
p.setFreeFloating(v, token.Dollar, []token.Token{
{
ID: token.ID('$'),
Value: []byte("$"),
},
})
}
func (p *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.Vertex) { func (p *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.Vertex) {
if p.withTokens == false { if p.withTokens == false {
return return
@ -144,7 +126,6 @@ func (p *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.
} }
vlen := len(semiColon[0].Value) vlen := len(semiColon[0].Value)
fmt.Printf("vlen: %q\n", string(semiColon[0].Value))
tlen := 2 tlen := 2
if bytes.HasSuffix(semiColon[0].Value, []byte("?>\n")) { if bytes.HasSuffix(semiColon[0].Value, []byte("?>\n")) {

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1418,7 +1418,7 @@ catch_statement:
} }
| T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}' additional_catches | T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}' additional_catches
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($4.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $4.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
catchNode := &ast.StmtCatch{ast.Node{}, []ast.Vertex{$3}, variable, $7} catchNode := &ast.StmtCatch{ast.Node{}, []ast.Vertex{$3}, variable, $7}
$$ = append([]ast.Vertex{catchNode}, $9...) $$ = append([]ast.Vertex{catchNode}, $9...)
@ -1432,7 +1432,6 @@ catch_statement:
yylex.(*Parser).setFreeFloating(catchNode, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating(catchNode, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating(catchNode, token.Catch, $2.Hidden) yylex.(*Parser).setFreeFloating(catchNode, token.Catch, $2.Hidden)
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $4.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(catchNode, token.Var, $5.Hidden) yylex.(*Parser).setFreeFloating(catchNode, token.Var, $5.Hidden)
yylex.(*Parser).setFreeFloating(catchNode, token.Cond, $6.Hidden) yylex.(*Parser).setFreeFloating(catchNode, token.Cond, $6.Hidden)
yylex.(*Parser).setFreeFloating(catchNode, token.Stmts, $8.Hidden) yylex.(*Parser).setFreeFloating(catchNode, token.Stmts, $8.Hidden)
@ -1497,7 +1496,7 @@ non_empty_additional_catches:
additional_catch: additional_catch:
T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}' T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}'
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($4.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $4.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtCatch{ast.Node{}, []ast.Vertex{$3}, variable, $7} $$ = &ast.StmtCatch{ast.Node{}, []ast.Vertex{$3}, variable, $7}
@ -1510,7 +1509,6 @@ additional_catch:
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Catch, $2.Hidden) yylex.(*Parser).setFreeFloating($$, token.Catch, $2.Hidden)
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $4.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating($$, token.Var, $5.Hidden) yylex.(*Parser).setFreeFloating($$, token.Var, $5.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Cond, $6.Hidden) yylex.(*Parser).setFreeFloating($$, token.Cond, $6.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Stmts, $8.Hidden) yylex.(*Parser).setFreeFloating($$, token.Stmts, $8.Hidden)
@ -2284,7 +2282,7 @@ non_empty_parameter_list:
parameter: parameter:
optional_class_type is_reference is_variadic T_VARIABLE optional_class_type is_reference is_variadic T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($4.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $4.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, nil} $$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, nil}
@ -2312,7 +2310,6 @@ parameter:
yylex.(*Parser).setFreeFloating($$, token.Ampersand, $3.Hidden) yylex.(*Parser).setFreeFloating($$, token.Ampersand, $3.Hidden)
} }
yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden) yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden)
yylex.(*Parser).addDollarToken(variable)
// normalize // normalize
if $3 == nil { if $3 == nil {
@ -2329,7 +2326,7 @@ parameter:
} }
| optional_class_type is_reference is_variadic T_VARIABLE '=' static_scalar | optional_class_type is_reference is_variadic T_VARIABLE '=' static_scalar
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($4.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $4.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, $6} $$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, $6}
@ -2358,7 +2355,6 @@ parameter:
} }
yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden) yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Var, $5.Hidden) yylex.(*Parser).setFreeFloating($$, token.Var, $5.Hidden)
yylex.(*Parser).addDollarToken(variable)
// normalize // normalize
if $3 == nil { if $3 == nil {
@ -2552,7 +2548,7 @@ global_var_list:
global_var: global_var:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} name := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, name} $$ = &ast.ExprVariable{ast.Node{}, name}
// save position // save position
@ -2561,7 +2557,6 @@ global_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -2574,7 +2569,6 @@ global_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Dollar, yylex.(*Parser).GetFreeFloatingToken($1))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -2587,7 +2581,6 @@ global_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Dollar, yylex.(*Parser).GetFreeFloatingToken($1))
yylex.(*Parser).setFreeFloating($3, token.Start, append($2.Hidden, append(yylex.(*Parser).GetFreeFloatingToken($2), $3.GetNode().Tokens[token.Start]...)...)) yylex.(*Parser).setFreeFloating($3, token.Start, append($2.Hidden, append(yylex.(*Parser).GetFreeFloatingToken($2), $3.GetNode().Tokens[token.Start]...)...))
yylex.(*Parser).setFreeFloating($3, token.End, append($3.GetNode().Tokens[token.End], append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)...)) yylex.(*Parser).setFreeFloating($3, token.End, append($3.GetNode().Tokens[token.End], append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)...))
@ -2599,7 +2592,7 @@ global_var:
static_var_list: static_var_list:
static_var_list ',' T_VARIABLE static_var_list ',' T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($3.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $3.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
staticVar := &ast.StmtStaticVar{ast.Node{}, variable, nil} staticVar := &ast.StmtStaticVar{ast.Node{}, variable, nil}
$$ = append($1, staticVar) $$ = append($1, staticVar)
@ -2611,14 +2604,13 @@ static_var_list:
// save comments // save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden) yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(staticVar, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(staticVar, token.Start, $3.Hidden)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| static_var_list ',' T_VARIABLE '=' static_scalar | static_var_list ',' T_VARIABLE '=' static_scalar
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($3.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $3.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
staticVar := &ast.StmtStaticVar{ast.Node{}, variable, $5} staticVar := &ast.StmtStaticVar{ast.Node{}, variable, $5}
$$ = append($1, staticVar) $$ = append($1, staticVar)
@ -2630,7 +2622,6 @@ static_var_list:
// save comments // save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden) yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(staticVar, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(staticVar, token.Start, $3.Hidden)
yylex.(*Parser).setFreeFloating(staticVar, token.Var, $4.Hidden) yylex.(*Parser).setFreeFloating(staticVar, token.Var, $4.Hidden)
@ -2638,7 +2629,7 @@ static_var_list:
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
staticVar := &ast.StmtStaticVar{ast.Node{}, variable, nil} staticVar := &ast.StmtStaticVar{ast.Node{}, variable, nil}
$$ = []ast.Vertex{staticVar} $$ = []ast.Vertex{staticVar}
@ -2649,14 +2640,13 @@ static_var_list:
staticVar.GetNode().Position = position.NewTokenPosition($1) staticVar.GetNode().Position = position.NewTokenPosition($1)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(staticVar, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating(staticVar, token.Start, $1.Hidden)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_VARIABLE '=' static_scalar | T_VARIABLE '=' static_scalar
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
staticVar := &ast.StmtStaticVar{ast.Node{}, variable, $3} staticVar := &ast.StmtStaticVar{ast.Node{}, variable, $3}
$$ = []ast.Vertex{staticVar} $$ = []ast.Vertex{staticVar}
@ -2667,7 +2657,6 @@ static_var_list:
staticVar.GetNode().Position = position.NewTokenNodePosition($1, $3) staticVar.GetNode().Position = position.NewTokenNodePosition($1, $3)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(staticVar, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating(staticVar, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating(staticVar, token.Var, $2.Hidden) yylex.(*Parser).setFreeFloating(staticVar, token.Var, $2.Hidden)
@ -3154,7 +3143,7 @@ member_modifier:
class_variable_declaration: class_variable_declaration:
class_variable_declaration ',' T_VARIABLE class_variable_declaration ',' T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($3.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $3.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, nil} property := &ast.StmtProperty{ast.Node{}, variable, nil}
$$ = append($1, property) $$ = append($1, property)
@ -3165,7 +3154,6 @@ class_variable_declaration:
property.GetNode().Position = position.NewTokenPosition($3) property.GetNode().Position = position.NewTokenPosition($3)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden) yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden)
yylex.(*Parser).setFreeFloating(property, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(property, token.Start, $3.Hidden)
@ -3173,7 +3161,7 @@ class_variable_declaration:
} }
| class_variable_declaration ',' T_VARIABLE '=' static_scalar | class_variable_declaration ',' T_VARIABLE '=' static_scalar
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($3.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $3.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, $5} property := &ast.StmtProperty{ast.Node{}, variable, $5}
$$ = append($1, property) $$ = append($1, property)
@ -3185,7 +3173,6 @@ class_variable_declaration:
// save comments // save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden) yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(property, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(property, token.Start, $3.Hidden)
yylex.(*Parser).setFreeFloating(property, token.Var, $4.Hidden) yylex.(*Parser).setFreeFloating(property, token.Var, $4.Hidden)
@ -3193,7 +3180,7 @@ class_variable_declaration:
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, nil} property := &ast.StmtProperty{ast.Node{}, variable, nil}
$$ = []ast.Vertex{property} $$ = []ast.Vertex{property}
@ -3204,14 +3191,13 @@ class_variable_declaration:
property.GetNode().Position = position.NewTokenPosition($1) property.GetNode().Position = position.NewTokenPosition($1)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(property, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating(property, token.Start, $1.Hidden)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_VARIABLE '=' static_scalar | T_VARIABLE '=' static_scalar
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
property := &ast.StmtProperty{ast.Node{}, variable, $3} property := &ast.StmtProperty{ast.Node{}, variable, $3}
$$ = []ast.Vertex{property} $$ = []ast.Vertex{property}
@ -3222,7 +3208,6 @@ class_variable_declaration:
property.GetNode().Position = position.NewTokenNodePosition($1, $3) property.GetNode().Position = position.NewTokenNodePosition($1, $3)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(property, token.Start, $2.Hidden) yylex.(*Parser).setFreeFloating(property, token.Start, $2.Hidden)
yylex.(*Parser).setFreeFloating(property, token.Var, $2.Hidden) yylex.(*Parser).setFreeFloating(property, token.Var, $2.Hidden)
@ -4592,7 +4577,7 @@ lexical_vars:
lexical_var_list: lexical_var_list:
lexical_var_list ',' T_VARIABLE lexical_var_list ',' T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($3.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $3.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = append($1, variable) $$ = append($1, variable)
@ -4603,13 +4588,12 @@ lexical_var_list:
// save comments // save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden) yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden)
yylex.(*Parser).setFreeFloating(variable, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $3.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| lexical_var_list ',' '&' T_VARIABLE | lexical_var_list ',' '&' T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($4.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $4.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
reference := &ast.ExprReference{ast.Node{}, variable} reference := &ast.ExprReference{ast.Node{}, variable}
$$ = append($1, reference) $$ = append($1, reference)
@ -4623,13 +4607,12 @@ lexical_var_list:
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden) yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.Hidden)
yylex.(*Parser).setFreeFloating(reference, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(reference, token.Start, $3.Hidden)
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $4.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = []ast.Vertex{variable} $$ = []ast.Vertex{variable}
@ -4639,13 +4622,12 @@ lexical_var_list:
// save comments // save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| '&' T_VARIABLE | '&' T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($2.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $2.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
reference := &ast.ExprReference{ast.Node{}, variable} reference := &ast.ExprReference{ast.Node{}, variable}
$$ = []ast.Vertex{reference} $$ = []ast.Vertex{reference}
@ -4658,7 +4640,6 @@ lexical_var_list:
// save comments // save comments
yylex.(*Parser).setFreeFloating(reference, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating(reference, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating(variable, token.Start, $2.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $2.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -6390,7 +6371,7 @@ reference_variable:
compound_variable: compound_variable:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} name := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, name} $$ = &ast.ExprVariable{ast.Node{}, name}
// save position // save position
@ -6399,7 +6380,6 @@ compound_variable:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -6412,7 +6392,6 @@ compound_variable:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Dollar, yylex.(*Parser).GetFreeFloatingToken($1))
yylex.(*Parser).setFreeFloating($3, token.Start, append($2.Hidden, append(yylex.(*Parser).GetFreeFloatingToken($2), $3.GetNode().Tokens[token.Start]...)...)) yylex.(*Parser).setFreeFloating($3, token.Start, append($2.Hidden, append(yylex.(*Parser).GetFreeFloatingToken($2), $3.GetNode().Tokens[token.Start]...)...))
yylex.(*Parser).setFreeFloating($3, token.End, append($3.GetNode().Tokens[token.End], append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)...)) yylex.(*Parser).setFreeFloating($3, token.End, append($3.GetNode().Tokens[token.End], append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)...))
@ -6535,7 +6514,6 @@ simple_indirect_reference:
// save comments // save comments
yylex.(*Parser).setFreeFloating(n, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating(n, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating(n, token.Dollar, yylex.(*Parser).GetFreeFloatingToken($1))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -6553,9 +6531,8 @@ simple_indirect_reference:
// save comments // save comments
yylex.(*Parser).setFreeFloating(n, token.Start, $2.Hidden) yylex.(*Parser).setFreeFloating(n, token.Start, $2.Hidden)
yylex.(*Parser).setFreeFloating(n, token.Dollar, yylex.(*Parser).GetFreeFloatingToken($2))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -6817,7 +6794,7 @@ encaps_list:
encaps_var: encaps_var:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} name := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, name} $$ = &ast.ExprVariable{ast.Node{}, name}
// save position // save position
@ -6826,13 +6803,12 @@ encaps_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_VARIABLE '[' encaps_var_offset ']' | T_VARIABLE '[' encaps_var_offset ']'
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $3} $$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $3}
@ -6842,7 +6818,6 @@ encaps_var:
$$.GetNode().Position = position.NewTokensPosition($1, $4) $$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating($$, token.Var, append($2.Hidden, yylex.(*Parser).GetFreeFloatingToken($2)...)) yylex.(*Parser).setFreeFloating($$, token.Var, append($2.Hidden, yylex.(*Parser).GetFreeFloatingToken($2)...))
yylex.(*Parser).setFreeFloating($$, token.Expr, append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)) yylex.(*Parser).setFreeFloating($$, token.Expr, append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...))
@ -6850,7 +6825,7 @@ encaps_var:
} }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING | T_VARIABLE T_OBJECT_OPERATOR T_STRING
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
fetch := &ast.Identifier{ast.Node{}, $3.Value} fetch := &ast.Identifier{ast.Node{}, $3.Value}
$$ = &ast.ExprPropertyFetch{ast.Node{}, variable, fetch} $$ = &ast.ExprPropertyFetch{ast.Node{}, variable, fetch}
@ -6862,7 +6837,6 @@ encaps_var:
$$.GetNode().Position = position.NewTokensPosition($1, $3) $$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden) yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden)
yylex.(*Parser).setFreeFloating(fetch, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(fetch, token.Start, $3.Hidden)
@ -6963,7 +6937,7 @@ encaps_var_offset:
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, identifier} $$ = &ast.ExprVariable{ast.Node{}, identifier}
// save position // save position
@ -6972,7 +6946,6 @@ encaps_var_offset:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }

File diff suppressed because it is too large Load Diff

View File

@ -62,10 +62,6 @@ func lastNode(nn []ast.Vertex) ast.Vertex {
return nn[len(nn)-1] return nn[len(nn)-1]
} }
func isDollar(r rune) bool {
return r == '$'
}
func (p *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) { func (p *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) {
if p.withTokens == false { if p.withTokens == false {
return return
@ -109,19 +105,6 @@ func (p *Parser) GetFreeFloatingToken(t *scanner.Token) []token.Token {
} }
} }
func (p *Parser) addDollarToken(v ast.Vertex) {
if p.withTokens == false {
return
}
p.setFreeFloating(v, token.Dollar, []token.Token{
{
ID: token.ID('$'),
Value: []byte("$"),
},
})
}
func (p *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.Vertex) { func (p *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.Vertex) {
if p.withTokens == false { if p.withTokens == false {
return return

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1352,7 +1352,7 @@ catch_list:
} }
| catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}' | catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}'
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($5.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $5.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
catch := &ast.StmtCatch{ast.Node{}, $4, variable, $8} catch := &ast.StmtCatch{ast.Node{}, $4, variable, $8}
$$ = append($1, catch) $$ = append($1, catch)
@ -1366,7 +1366,6 @@ catch_list:
yylex.(*Parser).setFreeFloating(catch, token.Start, $2.Hidden) yylex.(*Parser).setFreeFloating(catch, token.Start, $2.Hidden)
yylex.(*Parser).setFreeFloating(catch, token.Catch, $3.Hidden) yylex.(*Parser).setFreeFloating(catch, token.Catch, $3.Hidden)
yylex.(*Parser).setFreeFloating(variable, token.Start, $5.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $5.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating(catch, token.Var, $6.Hidden) yylex.(*Parser).setFreeFloating(catch, token.Var, $6.Hidden)
yylex.(*Parser).setFreeFloating(catch, token.Cond, $7.Hidden) yylex.(*Parser).setFreeFloating(catch, token.Cond, $7.Hidden)
yylex.(*Parser).setFreeFloating(catch, token.Stmts, $9.Hidden) yylex.(*Parser).setFreeFloating(catch, token.Stmts, $9.Hidden)
@ -2142,7 +2141,7 @@ non_empty_parameter_list:
parameter: parameter:
optional_type is_reference is_variadic T_VARIABLE optional_type is_reference is_variadic T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($4.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $4.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, nil} $$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, nil}
@ -2171,7 +2170,6 @@ parameter:
} }
yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden) yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden)
yylex.(*Parser).addDollarToken(variable)
// normalize // normalize
if $3 == nil { if $3 == nil {
@ -2188,7 +2186,7 @@ parameter:
} }
| optional_type is_reference is_variadic T_VARIABLE '=' expr | optional_type is_reference is_variadic T_VARIABLE '=' expr
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($4.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $4.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, $6} $$ = &ast.Parameter{ast.Node{}, $2 != nil, $3 != nil, $1, variable, $6}
@ -2218,7 +2216,6 @@ parameter:
yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden) yylex.(*Parser).setFreeFloating($$, token.Variadic, $4.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Var, $5.Hidden) yylex.(*Parser).setFreeFloating($$, token.Var, $5.Hidden)
yylex.(*Parser).addDollarToken(variable)
// normalize // normalize
if $3 == nil { if $3 == nil {
@ -2448,7 +2445,7 @@ static_var_list:
static_var: static_var:
T_VARIABLE T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtStaticVar{ast.Node{}, variable, nil} $$ = &ast.StmtStaticVar{ast.Node{}, variable, nil}
@ -2459,13 +2456,12 @@ static_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_VARIABLE '=' expr | T_VARIABLE '=' expr
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtStaticVar{ast.Node{}, variable, $3} $$ = &ast.StmtStaticVar{ast.Node{}, variable, $3}
@ -2476,7 +2472,6 @@ static_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden) yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -2975,7 +2970,7 @@ property_list:
property: property:
T_VARIABLE backup_doc_comment T_VARIABLE backup_doc_comment
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtProperty{ast.Node{}, variable, nil} $$ = &ast.StmtProperty{ast.Node{}, variable, nil}
@ -2986,13 +2981,12 @@ property:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_VARIABLE '=' expr backup_doc_comment | T_VARIABLE '=' expr backup_doc_comment
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtProperty{ast.Node{}, variable, $3} $$ = &ast.StmtProperty{ast.Node{}, variable, $3}
@ -3003,7 +2997,6 @@ property:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden) yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -4289,7 +4282,7 @@ lexical_var_list:
lexical_var: lexical_var:
T_VARIABLE T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, identifier} $$ = &ast.ExprVariable{ast.Node{}, identifier}
// save position // save position
@ -4298,13 +4291,12 @@ lexical_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| '&' T_VARIABLE | '&' T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($2.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $2.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.ExprReference{ast.Node{}, variable} $$ = &ast.ExprReference{ast.Node{}, variable}
@ -4316,7 +4308,6 @@ lexical_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating(variable, token.Start, $2.Hidden) yylex.(*Parser).setFreeFloating(variable, token.Start, $2.Hidden)
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -4937,7 +4928,7 @@ variable:
simple_variable: simple_variable:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} name := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, name} $$ = &ast.ExprVariable{ast.Node{}, name}
// save position // save position
@ -4946,7 +4937,6 @@ simple_variable:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -4959,7 +4949,6 @@ simple_variable:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Dollar, yylex.(*Parser).GetFreeFloatingToken($1))
yylex.(*Parser).setFreeFloating($3, token.Start, append($2.Hidden, append(yylex.(*Parser).GetFreeFloatingToken($2), $3.GetNode().Tokens[token.Start]...)...)) yylex.(*Parser).setFreeFloating($3, token.Start, append($2.Hidden, append(yylex.(*Parser).GetFreeFloatingToken($2), $3.GetNode().Tokens[token.Start]...)...))
yylex.(*Parser).setFreeFloating($3, token.End, append($3.GetNode().Tokens[token.End], append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)...)) yylex.(*Parser).setFreeFloating($3, token.End, append($3.GetNode().Tokens[token.End], append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)...))
@ -4974,7 +4963,6 @@ simple_variable:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).setFreeFloating($$, token.Dollar, yylex.(*Parser).GetFreeFloatingToken($1))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -5347,7 +5335,7 @@ encaps_list:
encaps_var: encaps_var:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} name := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, name} $$ = &ast.ExprVariable{ast.Node{}, name}
// save position // save position
@ -5356,13 +5344,12 @@ encaps_var:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_VARIABLE '[' encaps_var_offset ']' | T_VARIABLE '[' encaps_var_offset ']'
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $3} $$ = &ast.ExprArrayDimFetch{ast.Node{}, variable, $3}
@ -5372,7 +5359,6 @@ encaps_var:
$$.GetNode().Position = position.NewTokensPosition($1, $4) $$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating($$, token.Var, append($2.Hidden, yylex.(*Parser).GetFreeFloatingToken($2)...)) yylex.(*Parser).setFreeFloating($$, token.Var, append($2.Hidden, yylex.(*Parser).GetFreeFloatingToken($2)...))
yylex.(*Parser).setFreeFloating($$, token.Expr, append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...)) yylex.(*Parser).setFreeFloating($$, token.Expr, append($4.Hidden, yylex.(*Parser).GetFreeFloatingToken($4)...))
@ -5380,7 +5366,7 @@ encaps_var:
} }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING | T_VARIABLE T_OBJECT_OPERATOR T_STRING
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
variable := &ast.ExprVariable{ast.Node{}, identifier} variable := &ast.ExprVariable{ast.Node{}, identifier}
fetch := &ast.Identifier{ast.Node{}, $3.Value} fetch := &ast.Identifier{ast.Node{}, $3.Value}
$$ = &ast.ExprPropertyFetch{ast.Node{}, variable, fetch} $$ = &ast.ExprPropertyFetch{ast.Node{}, variable, fetch}
@ -5392,7 +5378,6 @@ encaps_var:
$$.GetNode().Position = position.NewTokensPosition($1, $3) $$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
yylex.(*Parser).addDollarToken(variable)
yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden) yylex.(*Parser).setFreeFloating($$, token.Var, $2.Hidden)
yylex.(*Parser).setFreeFloating(fetch, token.Start, $3.Hidden) yylex.(*Parser).setFreeFloating(fetch, token.Start, $3.Hidden)
@ -5519,7 +5504,7 @@ encaps_var_offset:
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{ast.Node{}, bytes.TrimLeftFunc($1.Value, isDollar)} identifier := &ast.Identifier{ast.Node{}, $1.Value}
$$ = &ast.ExprVariable{ast.Node{}, identifier} $$ = &ast.ExprVariable{ast.Node{}, identifier}
// save position // save position
@ -5528,7 +5513,6 @@ encaps_var_offset:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Hidden)
yylex.(*Parser).addDollarToken($$)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
package printer package printer
import ( import (
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/token"
"io" "io"
"strings" "strings"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/token"
) )
type printerState int type printerState int
@ -1860,7 +1861,7 @@ func (p *Printer) printExprVariable(n ast.Vertex) {
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
p.printFreeFloating(nn, token.Dollar) p.printFreeFloating(nn, token.Dollar)
if nn.GetNode().Tokens.IsEmpty() { if _, ok := nn.VarName.(*ast.Identifier); !ok {
io.WriteString(p.w, "$") io.WriteString(p.w, "$")
} }

View File

@ -1084,7 +1084,7 @@ func TestParseAndPrintPhp5Shebang(t *testing.T) {
<?php <?php
$a;?>test<? ` $a;?>test<? `
actual := print(parse(src)) actual := printPhp5(parsePhp5(src))
if src != actual { if src != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) t.Errorf("\nexpected: %s\ngot: %s\n", src, actual)

File diff suppressed because it is too large Load Diff