#70: [php7] inherit meta.Data at node.Argument, stmt.PropertyList, stmt.ClassConstList, stmt.ClassMethod, stmt.TraitUsePrecedence, stmt.TraitUseAlias, stmt.TraitMethodRef

This commit is contained in:
z7zmey 2018-12-26 12:09:54 +02:00
parent 1654b63fd1
commit 254f7a2167
7 changed files with 328 additions and 286 deletions

View File

@ -349,6 +349,7 @@ const yyErrCode = 2
const yyInitialStackSize = 16 const yyInitialStackSize = 16
//line php5/php5.y:6988 //line php5/php5.y:6988
type simpleIndirectReference struct { type simpleIndirectReference struct {
all []*expr.Variable all []*expr.Variable
last *expr.Variable last *expr.Variable

File diff suppressed because it is too large Load Diff

View File

@ -2352,6 +2352,9 @@ argument:
// save position // save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition($1)) $$.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition($1))
// save comments
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_ELLIPSIS expr | T_ELLIPSIS expr
@ -2362,7 +2365,7 @@ argument:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2)) $$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2))
// save comments // save comments
$1.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta()) $1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -2478,6 +2481,8 @@ class_statement:
$3.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta()) $3.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $3, meta.SemiColonToken) yylex.(*Parser).appendMetaToken($$, $3, meta.SemiColonToken)
$1[0].GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| method_modifiers T_CONST class_const_list ';' | method_modifiers T_CONST class_const_list ';'
@ -2492,6 +2497,8 @@ class_statement:
$4.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta()) $4.Meta.SetTokenName(meta.SemiColonToken).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $4, meta.SemiColonToken) yylex.(*Parser).appendMetaToken($$, $4, meta.SemiColonToken)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_USE name_list trait_adaptations | T_USE name_list trait_adaptations
@ -2528,6 +2535,10 @@ class_statement:
$6.Meta.SetTokenName(meta.OpenParenthesisToken).AppendTo($$.GetMeta()) $6.Meta.SetTokenName(meta.OpenParenthesisToken).AppendTo($$.GetMeta())
$8.Meta.SetTokenName(meta.CloseParenthesisToken).AppendTo($$.GetMeta()) $8.Meta.SetTokenName(meta.CloseParenthesisToken).AppendTo($$.GetMeta())
if len($1) > 0 {
$1[0].GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -2639,6 +2650,8 @@ trait_precedence:
// save comments // save comments
$2.Meta.SetTokenName(meta.InsteadofToken).AppendTo($$.GetMeta()) $2.Meta.SetTokenName(meta.InsteadofToken).AppendTo($$.GetMeta())
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -2657,6 +2670,8 @@ trait_alias:
$2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta()) $2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta()) $3.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| trait_method_reference T_AS reserved_non_modifiers | trait_method_reference T_AS reserved_non_modifiers
@ -2672,6 +2687,8 @@ trait_alias:
$2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta()) $2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta()) $3.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| trait_method_reference T_AS member_modifier identifier | trait_method_reference T_AS member_modifier identifier
@ -2687,6 +2704,8 @@ trait_alias:
$2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta()) $2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta()) $4.Meta.SetTokenName(meta.NodeStart).AppendTo(alias.GetMeta())
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| trait_method_reference T_AS member_modifier | trait_method_reference T_AS member_modifier
@ -2699,6 +2718,8 @@ trait_alias:
// save comments // save comments
$2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta()) $2.Meta.SetTokenName(meta.AsToken).AppendTo($$.GetMeta())
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -2714,7 +2735,7 @@ trait_method_reference:
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1)) $$.SetPosition(yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments // save comments
$1.Meta.SetTokenName(meta.NodeStart).AppendTo(name.GetMeta()) $1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -2740,6 +2761,8 @@ absolute_trait_method_reference:
$2.Meta.SetTokenName(meta.PaamayimNekudotayimToken).AppendTo($$.GetMeta()) $2.Meta.SetTokenName(meta.PaamayimNekudotayimToken).AppendTo($$.GetMeta())
$3.Meta.SetTokenName(meta.NodeStart).AppendTo(target.GetMeta()) $3.Meta.SetTokenName(meta.NodeStart).AppendTo(target.GetMeta())
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;

View File

@ -75,6 +75,7 @@ func ExampleDumper() {
// | [*stmt.ClassMethod] // | [*stmt.ClassMethod]
// | "Position": Pos{Line: 5-9 Pos: 45-134} // | "Position": Pos{Line: 5-9 Pos: 45-134}
// | "Meta": // | "Meta":
// | "\n\t\t\t\t" before "NodeStart"
// | " " before "FunctionToken" // | " " before "FunctionToken"
// | "ReturnsRef": false // | "ReturnsRef": false
// | "PhpDocComment": "" // | "PhpDocComment": ""
@ -87,8 +88,6 @@ func ExampleDumper() {
// | "Modifiers": // | "Modifiers":
// | [*node.Identifier] // | [*node.Identifier]
// | "Position": Pos{Line: 5-5 Pos: 45-50} // | "Position": Pos{Line: 5-5 Pos: 45-50}
// | "Meta":
// | "\n\t\t\t\t" before "NodeStart"
// | "Value": "public" // | "Value": "public"
// | "Params": // | "Params":
// | [*node.Parameter] // | [*node.Parameter]

View File

@ -206,6 +206,17 @@ func ExampleGoDumper() {
// &meta.Data{ // &meta.Data{
// Type: meta.WhiteSpaceType, // Type: meta.WhiteSpaceType,
// Position: &position.Position{ // Position: &position.Position{
// StartLine: 4,
// EndLine: 5,
// StartPos: 40,
// EndPos: 44,
// },
// Value: "\n\t\t\t\t",
// TokenName: meta.NodeStart,
// },
// &meta.Data{
// Type: meta.WhiteSpaceType,
// Position: &position.Position{
// StartLine: 5, // StartLine: 5,
// EndLine: 5, // EndLine: 5,
// StartPos: 51, // StartPos: 51,
@ -247,19 +258,6 @@ func ExampleGoDumper() {
// StartPos: 45, // StartPos: 45,
// EndPos: 50, // EndPos: 50,
// }, // },
// Meta: meta.Collection{
// &meta.Data{
// Type: meta.WhiteSpaceType,
// Position: &position.Position{
// StartLine: 4,
// EndLine: 5,
// StartPos: 40,
// EndPos: 44,
// },
// Value: "\n\t\t\t\t",
// TokenName: meta.NodeStart,
// },
// },
// Value: "public", // Value: "public",
// }, // },
// }, // },

View File

@ -37,5 +37,5 @@ func ExampleJsonDumper() {
nodes.Walk(dumper) nodes.Walk(dumper)
// Output: // 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":"NodeStart"},{"type":"*meta.WhiteSpaceType","value":"\n\n\t\t","tokenName":"NodeStart"},{"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":"NodeStart"}],"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":"NodeStart"},{"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":"NodeStart"}],"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":"NodeStart"}],"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":"NodeStart"}],"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":"NodeStart"},{"type":"*meta.TokenType","value":"$","tokenName":"NodeStart"}],"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","meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"NodeStart"}],"Parts":[{"type":"*name.NamePart","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"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":"NodeStart"},{"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.WhiteSpaceType","value":"\n\t\t\t\t\t","tokenName":"NodeStart"},{"type":"*meta.CommentType","value":"// some comment\n","tokenName":"NodeStart"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"NodeStart"},{"type":"*meta.CommentType","value":"// second comment\n","tokenName":"NodeStart"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"NodeStart"},{"type":"*meta.TokenType","value":";","tokenName":"SemiColonToken"}],"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.TokenType","value":"$","tokenName":"NodeStart"}],"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":"NodeStart"},{"type":"*meta.WhiteSpaceType","value":"\n\n\t\t","tokenName":"NodeStart"},{"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":"NodeStart"}],"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":"NodeStart"},{"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":"NodeStart"}],"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"meta":[{"type":"*meta.WhiteSpaceType","value":"\n\t\t\t\t","tokenName":"NodeStart"},{"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":"NodeStart"}],"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":45,"endPos":50,"startLine":5,"endLine":5},"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":"NodeStart"},{"type":"*meta.TokenType","value":"$","tokenName":"NodeStart"}],"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","meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"NodeStart"}],"Parts":[{"type":"*name.NamePart","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"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":"NodeStart"},{"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.WhiteSpaceType","value":"\n\t\t\t\t\t","tokenName":"NodeStart"},{"type":"*meta.CommentType","value":"// some comment\n","tokenName":"NodeStart"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"NodeStart"},{"type":"*meta.CommentType","value":"// second comment\n","tokenName":"NodeStart"},{"type":"*meta.WhiteSpaceType","value":"\t\t\t\t\t","tokenName":"NodeStart"},{"type":"*meta.TokenType","value":";","tokenName":"SemiColonToken"}],"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.TokenType","value":"$","tokenName":"NodeStart"}],"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
} }

View File

@ -170,6 +170,11 @@ func ExamplePrettyJsonDumper() {
// "meta": [ // "meta": [
// { // {
// "type": "*meta.WhiteSpaceType", // "type": "*meta.WhiteSpaceType",
// "value": "\n\t\t\t\t",
// "tokenName": "NodeStart"
// },
// {
// "type": "*meta.WhiteSpaceType",
// "value": " ", // "value": " ",
// "tokenName": "FunctionToken" // "tokenName": "FunctionToken"
// } // }
@ -202,13 +207,6 @@ func ExamplePrettyJsonDumper() {
// "startLine": 5, // "startLine": 5,
// "endLine": 5 // "endLine": 5
// }, // },
// "meta": [
// {
// "type": "*meta.WhiteSpaceType",
// "value": "\n\t\t\t\t",
// "tokenName": "NodeStart"
// }
// ],
// "Value": "public" // "Value": "public"
// } // }
// ], // ],