remove StringVar attribute from expr.Variable

This commit is contained in:
z7zmey 2018-10-24 17:04:13 +03:00
parent b805f0b167
commit fd87c9cc34
18 changed files with 3426 additions and 1730 deletions

View File

@ -10,7 +10,6 @@ import (
// Variable node
type Variable struct {
Meta meta.Collection
StringVar bool
Position *position.Position
VarName node.Node
}
@ -38,9 +37,7 @@ func (n *Variable) GetMeta() *meta.Collection {
// Attributes returns node attributes as map
func (n *Variable) Attributes() map[string]interface{} {
return map[string]interface{}{
"StringVar": n.StringVar,
}
return nil
}
// SetVarName reset var name

View File

@ -333,9 +333,7 @@ var nodesToTest = []struct {
{
&expr.Variable{VarName: &node.Identifier{Value: "a"}},
[]string{"VarName"},
map[string]interface{}{
"StringVar": false,
},
map[string]interface{}{},
},
{
&expr.YieldFrom{

View File

@ -453,7 +453,6 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
StartPos: 10,
EndPos: 15,
},
StringVar: true,
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
@ -530,7 +529,6 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
StartPos: 12,
EndPos: 14,
},
StringVar: true,
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,

View File

@ -122,6 +122,14 @@ func (l *Parser) appendMetaToken(n node.Node, t *scanner.Token, tn meta.TokenNam
n.GetMeta().Push(m)
}
func (l *Parser) appendMeta(n node.Node, m *meta.Data, tn meta.TokenName) {
if !l.Lexer.WithMeta {
return
}
n.GetMeta().Push(m)
}
func (l *Parser) prependMetaToken(n node.Node, t *scanner.Token, tn meta.TokenName) {
if !l.Lexer.WithMeta {
return

File diff suppressed because it is too large Load Diff

View File

@ -1388,6 +1388,7 @@ catch_statement:
$1.Meta.SetTokenName(meta.CatchToken).AppendTo(catch.GetMeta())
$2.Meta.SetTokenName(meta.OpenParenthesisToken).AppendTo(catch.GetMeta())
$4.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$5.Meta.SetTokenName(meta.CloseParenthesisToken).AppendTo(catch.GetMeta())
$6.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo(catch.GetMeta())
$8.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo(catch.GetMeta())
@ -1465,6 +1466,7 @@ additional_catch:
$1.Meta.SetTokenName(meta.CatchToken).AppendTo($$.GetMeta())
$2.Meta.SetTokenName(meta.OpenParenthesisToken).AppendTo($$.GetMeta())
$4.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$5.Meta.SetTokenName(meta.CloseParenthesisToken).AppendTo($$.GetMeta())
$6.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
$8.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
@ -2255,6 +2257,7 @@ parameter:
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
}
$4.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2285,6 +2288,7 @@ parameter:
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
}
$4.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$5.Meta.SetTokenName(meta.EqualToken).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -2471,6 +2475,7 @@ global_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2483,6 +2488,8 @@ global_var:
// save comments
$1.Meta.SetTokenName(meta.DollarToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.DollarToken)
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2495,6 +2502,7 @@ global_var:
// save comments
$1.Meta.SetTokenName(meta.DollarToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.DollarToken)
$2.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
$4.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
@ -2519,6 +2527,7 @@ static_var_list:
// save comments
$2.Meta.SetTokenName(meta.NodeEnd).AppendTo(lastNode($1).GetMeta())
$3.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2537,6 +2546,7 @@ static_var_list:
// save comments
$2.Meta.SetTokenName(meta.NodeEnd).AppendTo(lastNode($1).GetMeta())
$3.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$4.Meta.SetTokenName(meta.EqualToken).AppendTo(staticVar.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -2555,6 +2565,7 @@ static_var_list:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2572,6 +2583,7 @@ static_var_list:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.EqualToken).AppendTo(staticVar.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -3059,6 +3071,7 @@ class_variable_declaration:
// save comments
$2.Meta.SetTokenName(meta.NodeEnd).AppendTo(lastNode($1).GetMeta())
$3.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -3077,6 +3090,7 @@ class_variable_declaration:
// save comments
$2.Meta.SetTokenName(meta.NodeEnd).AppendTo(lastNode($1).GetMeta())
$3.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$4.Meta.SetTokenName(meta.EqualToken).AppendTo(property.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -3095,6 +3109,7 @@ class_variable_declaration:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -3112,6 +3127,7 @@ class_variable_declaration:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.EqualToken).AppendTo(property.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -4445,6 +4461,7 @@ lexical_var_list:
// save comments
$2.Meta.SetTokenName(meta.NodeEnd).AppendTo(lastNode($1).GetMeta())
$3.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4464,6 +4481,7 @@ lexical_var_list:
$2.Meta.SetTokenName(meta.NodeEnd).AppendTo(lastNode($1).GetMeta())
$3.Meta.SetTokenName(meta.AmpersandToken).AppendTo(reference.GetMeta())
$4.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4479,6 +4497,7 @@ lexical_var_list:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4497,6 +4516,7 @@ lexical_var_list:
// save comments
$1.Meta.SetTokenName(meta.AmpersandToken).AppendTo(reference.GetMeta())
$2.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5599,6 +5619,7 @@ scalar:
// save comments
$1.Meta.SetTokenName(meta.IdentifierToken).AppendTo(name.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6166,6 +6187,7 @@ compound_variable:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6178,6 +6200,7 @@ compound_variable:
// save comments
$1.Meta.SetTokenName(meta.DollarToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.DollarToken)
$2.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $2, meta.OpenCurlyBracesToken)
$4.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
@ -6308,6 +6331,7 @@ simple_indirect_reference:
// save comments
$1.Meta.SetTokenName(meta.DollarToken).AppendTo(n.GetMeta())
yylex.(*Parser).appendMetaToken(n, $1, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6325,6 +6349,7 @@ simple_indirect_reference:
// save comments
$2.Meta.SetTokenName(meta.DollarToken).AppendTo(n.GetMeta())
yylex.(*Parser).appendMetaToken(n, $2, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6586,6 +6611,7 @@ encaps_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6602,6 +6628,7 @@ encaps_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.OpenSquareBracket).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $2, meta.OpenSquareBracket)
$4.Meta.SetTokenName(meta.CloseSquareBracket).AppendTo($$.GetMeta())
@ -6624,6 +6651,7 @@ encaps_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.ObjectOperatorToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.IdentifierToken).AppendTo(fetch.GetMeta())
@ -6632,7 +6660,6 @@ encaps_var:
| T_DOLLAR_OPEN_CURLY_BRACES expr '}'
{
variable := expr.NewVariable($2)
variable.StringVar = true
$$ = variable
@ -6651,7 +6678,6 @@ encaps_var:
{
name := node.NewIdentifier($2.Value)
variable := expr.NewVariable(name)
variable.StringVar = true
$$ = variable
@ -6672,7 +6698,6 @@ encaps_var:
{
identifier := node.NewIdentifier($2.Value)
variable := expr.NewVariable(identifier)
variable.StringVar = true
$$ = expr.NewArrayDimFetch(variable, $4)
// save position
@ -6748,6 +6773,7 @@ encaps_var_offset:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}

File diff suppressed because it is too large Load Diff

View File

@ -113,6 +113,14 @@ func (l *Parser) appendMetaToken(n node.Node, t *scanner.Token, tn meta.TokenNam
n.GetMeta().Push(m)
}
func (l *Parser) appendMeta(n node.Node, m *meta.Data, tn meta.TokenName) {
if !l.Lexer.WithMeta {
return
}
n.GetMeta().Push(m)
}
func (l *Parser) prependMetaToken(n node.Node, t *scanner.Token, tn meta.TokenName) {
if !l.Lexer.WithMeta {
return

File diff suppressed because it is too large Load Diff

View File

@ -1345,6 +1345,7 @@ catch_list:
$2.Meta.SetTokenName(meta.CatchToken).AppendTo(catch.GetMeta())
$3.Meta.SetTokenName(meta.OpenParenthesisToken).AppendTo(catch.GetMeta())
$5.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$6.Meta.SetTokenName(meta.CloseParenthesisToken).AppendTo(catch.GetMeta())
$7.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo(catch.GetMeta())
$9.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo(catch.GetMeta())
@ -2128,6 +2129,7 @@ parameter:
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
}
$4.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2158,6 +2160,7 @@ parameter:
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
}
$4.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$5.Meta.SetTokenName(meta.EqualToken).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -2385,6 +2388,7 @@ static_var:
// save comments
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2401,6 +2405,7 @@ static_var:
// save comments
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.EqualToken).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -2888,6 +2893,7 @@ property:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -2904,6 +2910,7 @@ property:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.EqualToken).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -4098,6 +4105,7 @@ lexical_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4115,6 +4123,7 @@ lexical_var:
// save comments
$1.Meta.SetTokenName(meta.AmpersandToken).AppendTo($$.GetMeta())
$2.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4734,6 +4743,7 @@ simple_variable:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -4746,6 +4756,7 @@ simple_variable:
// save comments
$1.Meta.SetTokenName(meta.DollarToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.DollarToken)
$2.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $2, meta.OpenCurlyBracesToken)
$4.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
@ -4762,6 +4773,7 @@ simple_variable:
// save comments
$1.Meta.SetTokenName(meta.DollarToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5126,6 +5138,7 @@ encaps_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -5142,6 +5155,7 @@ encaps_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.OpenSquareBracket).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $2, meta.OpenCurlyBracesToken)
$4.Meta.SetTokenName(meta.CloseSquareBracket).AppendTo($$.GetMeta())
@ -5164,6 +5178,7 @@ encaps_var:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo(variable.GetMeta())
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
$2.Meta.SetTokenName(meta.ObjectOperatorToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.IdentifierToken).AppendTo(fetch.GetMeta())
@ -5172,7 +5187,6 @@ encaps_var:
| T_DOLLAR_OPEN_CURLY_BRACES expr '}'
{
variable := expr.NewVariable($2)
variable.StringVar = true
$$ = variable
@ -5191,7 +5205,6 @@ encaps_var:
{
name := node.NewIdentifier($2.Value)
variable := expr.NewVariable(name)
variable.StringVar = true
$$ = variable
@ -5212,7 +5225,6 @@ encaps_var:
{
identifier := node.NewIdentifier($2.Value)
variable := expr.NewVariable(identifier)
variable.StringVar = true
$$ = expr.NewArrayDimFetch(variable, $4)
// save position
@ -5319,6 +5331,7 @@ encaps_var_offset:
// save comments
$1.Meta.SetTokenName(meta.VariableToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMeta($$, &meta.Data{"$", meta.TokenType, nil, meta.DollarToken}, meta.DollarToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}

File diff suppressed because it is too large Load Diff

View File

@ -1791,10 +1791,6 @@ func (p *Printer) printExprVariable(n node.Node) {
p.printMeta(nn, meta.DollarOpenCurlyBracesToken)
p.printMeta(nn, meta.DollarToken)
if !nn.StringVar {
io.WriteString(p.w, "$")
}
p.printMeta(nn, meta.OpenCurlyBracesToken)
p.Print(nn.VarName)
p.printMeta(nn, meta.DollarCloseCurlyBracesToken)

File diff suppressed because it is too large Load Diff

View File

@ -110,7 +110,7 @@ func ExampleDumper() {
// | "Position": Pos{Line: 5-5 Pos: 79-82}
// | "Meta":
// | " " before "VariableToken"
// | "StringVar": false
// | "$" before "DollarToken"
// | "VarName":
// | [*node.Identifier]
// | "Position": Pos{Line: 5-5 Pos: 79-82}
@ -146,7 +146,7 @@ func ExampleDumper() {
// | "\n\t\t\t\t\t" before "VariableToken"
// | "// some comment\n" before "VariableToken"
// | "\t\t\t\t\t" before "VariableToken"
// | "StringVar": false
// | "$" before "DollarToken"
// | "VarName":
// | [*node.Identifier]
// | "Position": Pos{Line: 8-8 Pos: 124-127}

View File

@ -78,6 +78,7 @@ func (d *GoDumper) EnterNode(w walker.Walkable) bool {
d.depth++
printIndent(d.Writer, d.depth)
if m.Position != nil {
fmt.Fprint(d.Writer, "Position: &position.Position{\n")
d.depth++
printIndent(d.Writer, d.depth)
@ -91,6 +92,9 @@ func (d *GoDumper) EnterNode(w walker.Walkable) bool {
d.depth--
printIndent(d.Writer, d.depth)
fmt.Fprint(d.Writer, "},\n")
} else {
fmt.Fprint(d.Writer, "Position: nil,\n")
}
printIndent(d.Writer, d.depth)
fmt.Fprintf(d.Writer, "Value: %q,\n", m.String())

View File

@ -310,8 +310,12 @@ func ExampleGoDumper() {
// Value: " ",
// TokenName: 12,
// },
// &meta.TokenType{
// Position: nil,
// Value: "$",
// TokenName: 145,
// },
// },
// StringVar: false,
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
@ -450,8 +454,12 @@ func ExampleGoDumper() {
// Value: "\t\t\t\t\t",
// TokenName: 12,
// },
// &meta.TokenType{
// Position: nil,
// Value: "$",
// TokenName: 145,
// },
// },
// StringVar: false,
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 8,

View File

@ -37,5 +37,5 @@ func ExampleJsonDumper() {
nodes.Walk(dumper)
// Output:
// {"type":"*node.Root","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"Stmts":[{"type":"*stmt.Namespace","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"meta":[{"type":"*meta.TokenType","value":"<?php","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpaceType","value":"\n\n\t\t","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpaceType","value":"\n\t\t","tokenName":"CloseCurlyBracesToken"}],"NamespaceName":{"type":"*name.Name","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"Parts":[{"type":"*name.NamePart","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"StringToken"}],"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":29,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t","tokenName":"ClassToken"},{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t","tokenName":"CloseCurlyBracesToken"}],"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":35,"endPos":37,"startLine":4,"endLine":4},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"IdentifierToken"}],"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"FunctionToken"}],"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":61,"endPos":72,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"IdentifierToken"}],"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":45,"endPos":50,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t","tokenName":"IdentifierToken"}],"Value":"public"}],"Params":[{"type":"*node.Parameter","position":{"startPos":74,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"EqualToken"}],"ByRef":false,"Variadic":false,"VariableType":{"type":"*name.Name","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"namespacedName":"Foo\\Type","Parts":[{"type":"*name.NamePart","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"Value":"Type"}]},"Variable":{"type":"*expr.Variable","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"VariableToken"}],"StringVar":false,"VarName":{"type":"*node.Identifier","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"Value":"var"}},"DefaultValue":{"type":"*expr.ConstFetch","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"Constant":{"type":"*name.Name","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"namespacedName":"null","Parts":[{"type":"*name.NamePart","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"StringToken"}],"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":96,"endPos":157,"startLine":6,"endLine":10},"meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t","tokenName":"CloseCurlyBracesToken"}],"Stmts":[{"type":"*stmt.Expression","position":{"startPos":147,"endPos":151,"startLine":9,"endLine":9},"meta":[{"type":"*meta.TokenType","value":";","tokenName":"SemiColonToken"}],"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.CommentType","value":"// some comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.CommentType","value":"// second comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"VariableToken"}],"StringVar":false,"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
// {"type":"*node.Root","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"Stmts":[{"type":"*stmt.Namespace","position":{"startPos":10,"endPos":166,"startLine":3,"endLine":12},"meta":[{"type":"*meta.TokenType","value":"<?php","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpaceType","value":"\n\n\t\t","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpaceType","value":"\n\t\t","tokenName":"CloseCurlyBracesToken"}],"NamespaceName":{"type":"*name.Name","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"Parts":[{"type":"*name.NamePart","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"StringToken"}],"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":29,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t","tokenName":"ClassToken"},{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t","tokenName":"CloseCurlyBracesToken"}],"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":35,"endPos":37,"startLine":4,"endLine":4},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"IdentifierToken"}],"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"FunctionToken"}],"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":61,"endPos":72,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"IdentifierToken"}],"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":45,"endPos":50,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t","tokenName":"IdentifierToken"}],"Value":"public"}],"Params":[{"type":"*node.Parameter","position":{"startPos":74,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"EqualToken"}],"ByRef":false,"Variadic":false,"VariableType":{"type":"*name.Name","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"namespacedName":"Foo\\Type","Parts":[{"type":"*name.NamePart","position":{"startPos":74,"endPos":77,"startLine":5,"endLine":5},"Value":"Type"}]},"Variable":{"type":"*expr.Variable","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"VariableToken"},{"type":"*meta.TokenType","value":"$","tokenName":"DollarToken"}],"VarName":{"type":"*node.Identifier","position":{"startPos":79,"endPos":82,"startLine":5,"endLine":5},"Value":"var"}},"DefaultValue":{"type":"*expr.ConstFetch","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"Constant":{"type":"*name.Name","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"namespacedName":"null","Parts":[{"type":"*name.NamePart","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"StringToken"}],"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":96,"endPos":157,"startLine":6,"endLine":10},"meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t","tokenName":"CloseCurlyBracesToken"}],"Stmts":[{"type":"*stmt.Expression","position":{"startPos":147,"endPos":151,"startLine":9,"endLine":9},"meta":[{"type":"*meta.TokenType","value":";","tokenName":"SemiColonToken"}],"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.CommentType","value":"// some comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.CommentType","value":"// second comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.TokenType","value":"$","tokenName":"DollarToken"}],"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
}

View File

@ -265,9 +265,13 @@ func ExamplePrettyJsonDumper() {
// "type": "*meta.WhiteSpaceType",
// "value": " ",
// "tokenName": "VariableToken"
// },
// {
// "type": "*meta.TokenType",
// "value": "$",
// "tokenName": "DollarToken"
// }
// ],
// "StringVar": false,
// "VarName": {
// "type": "*node.Identifier",
// "position": {
@ -388,9 +392,13 @@ func ExamplePrettyJsonDumper() {
// "type": "*meta.WhiteSpaceType",
// "value": "\t\t\t\t\t",
// "tokenName": "VariableToken"
// },
// {
// "type": "*meta.TokenType",
// "value": "$",
// "tokenName": "DollarToken"
// }
// ],
// "StringVar": false,
// "VarName": {
// "type": "*node.Identifier",
// "position": {