#70: [php7] inherit meta.Data at stmt.Use, stmt.GroupUse, stmt.UseList, name.Name

This commit is contained in:
z7zmey 2018-12-25 10:49:44 +02:00
parent 11d621cb90
commit 86afa319f3
6 changed files with 477 additions and 435 deletions

File diff suppressed because it is too large Load Diff

View File

@ -395,6 +395,9 @@ name:
// save position // save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1)) $$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
// save comments
$1[0].GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_NAMESPACE T_NS_SEPARATOR namespace_name | T_NAMESPACE T_NS_SEPARATOR namespace_name
@ -644,6 +647,8 @@ group_use_declaration:
} }
$6.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta()) $6.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
$1[0].GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo(name.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}' | T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
@ -666,6 +671,8 @@ group_use_declaration:
} }
$7.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta()) $7.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
$2[0].GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo(name.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -689,6 +696,8 @@ mixed_group_use_declaration:
} }
$6.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta()) $6.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
$1[0].GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo(name.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}' | T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
@ -711,6 +720,8 @@ mixed_group_use_declaration:
} }
$7.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta()) $7.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
$2[0].GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo(name.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -785,12 +796,16 @@ inline_use_declaration:
{ {
$$ = $1 $$ = $1
$1.(*stmt.Use).Use.GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| use_type unprefixed_use_declaration | use_type unprefixed_use_declaration
{ {
$$ = $2.(*stmt.Use).SetUseType($1) $$ = $2.(*stmt.Use).SetUseType($1)
$1.GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -805,6 +820,8 @@ unprefixed_use_declaration:
name.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1)) name.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1)) $$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
$1[0].GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo(name.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| namespace_name T_AS T_STRING | namespace_name T_AS T_STRING
@ -822,6 +839,8 @@ unprefixed_use_declaration:
$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[0].GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo(name.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
; ;
@ -831,6 +850,8 @@ use_declaration:
{ {
$$ = $1 $$ = $1
$1.(*stmt.Use).Use.GetMeta().Cut(meta.TokenNameFilter(meta.NodeStart)).AppendTo($$.GetMeta())
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_NS_SEPARATOR unprefixed_use_declaration | T_NS_SEPARATOR unprefixed_use_declaration
@ -838,8 +859,8 @@ use_declaration:
$$ = $2; $$ = $2;
// save comments // save comments
$1.Meta.SetTokenName(meta.UseLeadingNsSeparatorToken).AppendTo($$.GetMeta()) $1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
yylex.(*Parser).appendMetaToken($$, $1, meta.UseLeadingNsSeparatorToken) yylex.(*Parser).appendMetaToken($$, $1, meta.NodeStart)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }

View File

@ -122,11 +122,11 @@ func ExampleDumper() {
// | [*name.Name] // | [*name.Name]
// | "Position": Pos{Line: 5-5 Pos: 86-89} // | "Position": Pos{Line: 5-5 Pos: 86-89}
// | "NamespacedName": "null" // | "NamespacedName": "null"
// | "Meta":
// | " " before "NodeStart"
// | "Parts": // | "Parts":
// | [*name.NamePart] // | [*name.NamePart]
// | "Position": Pos{Line: 5-5 Pos: 86-89} // | "Position": Pos{Line: 5-5 Pos: 86-89}
// | "Meta":
// | " " before "NodeStart"
// | "Value": "null" // | "Value": "null"
// | "Stmt": // | "Stmt":
// | [*stmt.StmtList] // | [*stmt.StmtList]

View File

@ -355,6 +355,19 @@ func ExampleGoDumper() {
// StartPos: 86, // StartPos: 86,
// EndPos: 89, // EndPos: 89,
// }, // },
// Meta: meta.Collection{
// &meta.Data{
// Type: meta.WhiteSpaceType,
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 85,
// EndPos: 85,
// },
// Value: " ",
// TokenName: meta.NodeStart,
// },
// },
// Parts: []node.Node{ // Parts: []node.Node{
// &name.NamePart{ // &name.NamePart{
// Position: &position.Position{ // Position: &position.Position{
@ -363,19 +376,6 @@ func ExampleGoDumper() {
// StartPos: 86, // StartPos: 86,
// EndPos: 89, // EndPos: 89,
// }, // },
// Meta: meta.Collection{
// &meta.Data{
// Type: meta.WhiteSpaceType,
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 85,
// EndPos: 85,
// },
// Value: " ",
// TokenName: meta.NodeStart,
// },
// },
// Value: "null", // Value: "null",
// }, // },
// }, // },

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":"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":"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","Parts":[{"type":"*name.NamePart","position":{"startPos":86,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpaceType","value":" ","tokenName":"NodeStart"}],"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.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":"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":"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":"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":"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.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":"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":"NodeStart"}],"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
} }

View File

@ -300,6 +300,13 @@ func ExamplePrettyJsonDumper() {
// "endLine": 5 // "endLine": 5
// }, // },
// "namespacedName": "null", // "namespacedName": "null",
// "meta": [
// {
// "type": "*meta.WhiteSpaceType",
// "value": " ",
// "tokenName": "NodeStart"
// }
// ],
// "Parts": [ // "Parts": [
// { // {
// "type": "*name.NamePart", // "type": "*name.NamePart",
@ -309,13 +316,6 @@ func ExamplePrettyJsonDumper() {
// "startLine": 5, // "startLine": 5,
// "endLine": 5 // "endLine": 5
// }, // },
// "meta": [
// {
// "type": "*meta.WhiteSpaceType",
// "value": " ",
// "tokenName": "NodeStart"
// }
// ],
// "Value": "null" // "Value": "null"
// } // }
// ] // ]