#70: [php7] inherit meta.Data at stmt.Class and node.Parameter
This commit is contained in:
parent
f406a441a9
commit
1654b63fd1
666
php7/php7.go
666
php7/php7.go
File diff suppressed because it is too large
Load Diff
22
php7/php7.y
22
php7/php7.y
@ -1508,6 +1508,8 @@ class_declaration_statement:
|
|||||||
$7.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
|
$7.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
|
||||||
$9.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
|
$9.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
|
||||||
|
|
||||||
|
$1[0].GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
|
||||||
|
|
||||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||||
}
|
}
|
||||||
| T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
|
| T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
|
||||||
@ -1520,7 +1522,7 @@ class_declaration_statement:
|
|||||||
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $8))
|
$$.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $8))
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
$1.Meta.SetTokenName(meta.ClassToken).AppendTo($$.GetMeta())
|
$1.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||||
$2.Meta.SetTokenName(meta.NodeStart).AppendTo(name.GetMeta())
|
$2.Meta.SetTokenName(meta.NodeStart).AppendTo(name.GetMeta())
|
||||||
$6.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
|
$6.Meta.SetTokenName(meta.OpenCurlyBracesToken).AppendTo($$.GetMeta())
|
||||||
$8.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
|
$8.Meta.SetTokenName(meta.CloseCurlyBracesToken).AppendTo($$.GetMeta())
|
||||||
@ -2145,13 +2147,20 @@ parameter:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
|
if $1 != nil {
|
||||||
|
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
|
||||||
|
}
|
||||||
if $2 != nil {
|
if $2 != nil {
|
||||||
$2.Meta.SetTokenName(meta.AmpersandToken).AppendTo($$.GetMeta())
|
$2.Meta.SetTokenName(meta.AmpersandToken).AppendTo($$.GetMeta())
|
||||||
}
|
}
|
||||||
if $3 != nil {
|
if $3 != nil {
|
||||||
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
|
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
|
||||||
}
|
}
|
||||||
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(variable.GetMeta())
|
if $1 == nil && $2 == nil && $3 == nil {
|
||||||
|
$4.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||||
|
} else {
|
||||||
|
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(variable.GetMeta())
|
||||||
|
}
|
||||||
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.NodeStart}, meta.NodeStart)
|
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.NodeStart}, meta.NodeStart)
|
||||||
|
|
||||||
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
|
||||||
@ -2176,13 +2185,20 @@ parameter:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
|
if $1 != nil {
|
||||||
|
$1.GetMeta().Cut(inheritMetaFilter).PrependTo($$.GetMeta())
|
||||||
|
}
|
||||||
if $2 != nil {
|
if $2 != nil {
|
||||||
$2.Meta.SetTokenName(meta.AmpersandToken).AppendTo($$.GetMeta())
|
$2.Meta.SetTokenName(meta.AmpersandToken).AppendTo($$.GetMeta())
|
||||||
}
|
}
|
||||||
if $3 != nil {
|
if $3 != nil {
|
||||||
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
|
$3.Meta.SetTokenName(meta.EllipsisToken).AppendTo($$.GetMeta())
|
||||||
}
|
}
|
||||||
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(variable.GetMeta())
|
if $1 == nil && $2 == nil && $3 == nil {
|
||||||
|
$4.Meta.SetTokenName(meta.NodeStart).AppendTo($$.GetMeta())
|
||||||
|
} else {
|
||||||
|
$4.Meta.SetTokenName(meta.NodeStart).AppendTo(variable.GetMeta())
|
||||||
|
}
|
||||||
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.NodeStart}, meta.NodeStart)
|
yylex.(*Parser).appendMeta(variable, &meta.Data{"$", meta.TokenType, nil, meta.NodeStart}, meta.NodeStart)
|
||||||
$5.Meta.SetTokenName(meta.EqualToken).AppendTo($$.GetMeta())
|
$5.Meta.SetTokenName(meta.EqualToken).AppendTo($$.GetMeta())
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ func ExampleDumper() {
|
|||||||
// | "Position": Pos{Line: 4-10 Pos: 29-139}
|
// | "Position": Pos{Line: 4-10 Pos: 29-139}
|
||||||
// | "NamespacedName": "Foo\\Bar"
|
// | "NamespacedName": "Foo\\Bar"
|
||||||
// | "Meta":
|
// | "Meta":
|
||||||
// | "\n\t\t\t" before "ClassToken"
|
// | "\n\t\t\t" before "NodeStart"
|
||||||
// | " " before "OpenCurlyBracesToken"
|
// | " " before "OpenCurlyBracesToken"
|
||||||
// | "\n\t\t\t" before "CloseCurlyBracesToken"
|
// | "\n\t\t\t" before "CloseCurlyBracesToken"
|
||||||
// | "PhpDocComment": ""
|
// | "PhpDocComment": ""
|
||||||
|
@ -146,7 +146,7 @@ func ExampleGoDumper() {
|
|||||||
// EndPos: 28,
|
// EndPos: 28,
|
||||||
// },
|
// },
|
||||||
// Value: "\n\t\t\t",
|
// Value: "\n\t\t\t",
|
||||||
// TokenName: meta.ClassToken,
|
// TokenName: meta.NodeStart,
|
||||||
// },
|
// },
|
||||||
// &meta.Data{
|
// &meta.Data{
|
||||||
// Type: meta.WhiteSpaceType,
|
// Type: meta.WhiteSpaceType,
|
||||||
|
@ -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","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":" ","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"}}}]}}]}]}]}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func ExamplePrettyJsonDumper() {
|
|||||||
// {
|
// {
|
||||||
// "type": "*meta.WhiteSpaceType",
|
// "type": "*meta.WhiteSpaceType",
|
||||||
// "value": "\n\t\t\t",
|
// "value": "\n\t\t\t",
|
||||||
// "tokenName": "ClassToken"
|
// "tokenName": "NodeStart"
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// "type": "*meta.WhiteSpaceType",
|
// "type": "*meta.WhiteSpaceType",
|
||||||
|
Loading…
Reference in New Issue
Block a user