#13: the printer prints nodes with meta(comments and whitespaces) saved by the parser

This commit is contained in:
z7zmey
2018-07-02 20:48:55 +03:00
parent c4c0934c51
commit 15a1a81924
30 changed files with 14110 additions and 4465 deletions

View File

@@ -7,7 +7,6 @@ import (
"reflect"
"strings"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
@@ -40,7 +39,7 @@ func (d *Dumper) EnterNode(w walker.Walkable) bool {
if mm := n.GetMeta(); len(mm) > 0 {
fmt.Fprintf(d.Writer, "%v\"Meta\":\n", d.Indent+" ")
for _, m := range mm {
fmt.Fprintf(d.Writer, "%v%q before %q\n", d.Indent+" ", m, meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "%v%q before %q\n", d.Indent+" ", m, m.GetTokenName().String())
}
}

View File

@@ -68,7 +68,7 @@ func ExampleDumper() {
// | [*node.Identifier]
// | "Position": Pos{Line: 4-4 Pos: 35-37}
// | "Meta":
// | " " before "StringToken"
// | " " before "IdentifierToken"
// | "Value": "Bar"
// | "Stmts":
// | [*stmt.ClassMethod]
@@ -87,15 +87,15 @@ func ExampleDumper() {
// | [*node.Identifier]
// | "Position": Pos{Line: 5-5 Pos: 45-50}
// | "Meta":
// | "\n\t\t\t\t" before "PublicToken"
// | "\n\t\t\t\t" before "IdentifierToken"
// | "Value": "public"
// | "Params":
// | [*node.Parameter]
// | "Position": Pos{Line: 5-5 Pos: 74-89}
// | "Meta":
// | " " before "EqualToken"
// | "Variadic": false
// | "ByRef": false
// | "Variadic": false
// | "VariableType":
// | [*name.Name]
// | "Position": Pos{Line: 5-5 Pos: 74-77}
@@ -141,7 +141,7 @@ func ExampleDumper() {
// | "Meta":
// | "\n\t\t\t\t\t" before "VariableToken"
// | "// some comment\n" before "VariableToken"
// | "\n\t\t\t\t\t" before "VariableToken"
// | "\t\t\t\t\t" before "VariableToken"
// | "VarName":
// | [*node.Identifier]
// | "Position": Pos{Line: 8-8 Pos: 124-127}

View File

@@ -35,417 +35,417 @@ func ExampleGoDumper() {
nodes.Walk(dumper)
// Unordered output:
//&node.Root{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Stmts: []node.Node{
// &stmt.Namespace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 1,
// EndLine: 3,
// StartPos: 6,
// EndPos: 9,
// },
// Value: "\n\n\t\t",
// TokenName: 67,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 23,
// EndPos: 23,
// },
// Value: " ",
// TokenName: 133,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 10,
// EndLine: 11,
// StartPos: 139,
// EndPos: 141,
// },
// Value: "\n\t\t",
// TokenName: 134,
// },
// },
// NamespaceName: &name.Name{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 19,
// EndPos: 19,
// },
// Value: " ",
// TokenName: 7,
// },
// },
// Value: "Foo",
// },
// },
// },
// Stmts: []node.Node{
// &stmt.Class{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 10,
// StartPos: 29,
// EndPos: 138,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 4,
// StartPos: 25,
// EndPos: 28,
// },
// Value: "\n\t\t\t",
// TokenName: 48,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 38,
// EndPos: 38,
// },
// Value: " ",
// TokenName: 133,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 9,
// EndLine: 10,
// StartPos: 134,
// EndPos: 137,
// },
// Value: "\n\t\t\t",
// TokenName: 134,
// },
// },
// PhpDocComment: "",
// ClassName: &node.Identifier{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 35,
// EndPos: 37,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 34,
// EndPos: 34,
// },
// Value: " ",
// TokenName: 7,
// },
// },
// Value: "Bar",
// },
// Stmts: []node.Node{
// &stmt.ClassMethod{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 9,
// StartPos: 45,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 51,
// EndPos: 51,
// },
// Value: " ",
// TokenName: 34,
// },
// },
// ReturnsRef: false,
// PhpDocComment: "",
// MethodName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 61,
// EndPos: 72,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 60,
// EndPos: 60,
// },
// Value: " ",
// TokenName: 129,
// },
// },
// Value: "FunctionName",
// },
// Modifiers: []node.Node{
// &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 45,
// EndPos: 50,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 5,
// StartPos: 40,
// EndPos: 44,
// },
// Value: "\n\t\t\t\t",
// TokenName: 91,
// },
// },
// Value: "public",
// },
// },
// Params: []node.Node{
// &node.Parameter{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 83,
// EndPos: 83,
// },
// Value: " ",
// TokenName: 151,
// },
// },
// Variadic: false,
// ByRef: false,
// VariableType: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Value: "Type",
// },
// },
// },
// Variable: &expr.Variable{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 78,
// EndPos: 78,
// },
// Value: " ",
// TokenName: 9,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Value: "var",
// },
// },
// DefaultValue: &expr.ConstFetch{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Constant: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 85,
// EndPos: 85,
// },
// Value: " ",
// TokenName: 7,
// },
// },
// Value: "null",
// },
// },
// },
// },
// },
// },
// Stmt: &stmt.StmtList{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 9,
// StartPos: 96,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 6,
// StartPos: 91,
// EndPos: 95,
// },
// Value: "\n\t\t\t\t",
// TokenName: 133,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 9,
// StartPos: 128,
// EndPos: 132,
// },
// Value: "\n\t\t\t\t",
// TokenName: 134,
// },
// },
// Stmts: []node.Node{
// &stmt.Expression{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 127,
// },
// Expr: &expr.Variable{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 7,
// StartPos: 97,
// EndPos: 102,
// },
// Value: "\n\t\t\t\t\t",
// TokenName: 9,
// },
// &meta.Comment{
// Position: &position.Position{
// StartLine: 7,
// EndLine: 7,
// StartPos: 103,
// EndPos: 117,
// },
// Value: "//some comment\n",
// TokenName: 9,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 7,
// EndLine: 8,
// StartPos: 117,
// EndPos: 122,
// },
// Value: "\n\t\t\t\t\t",
// TokenName: 9,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Value: "var",
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
//}
// &node.Root{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Stmts: []node.Node{
// &stmt.Namespace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// EndPos: 142,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 1,
// EndLine: 3,
// StartPos: 6,
// EndPos: 9,
// },
// Value: "\n\n\t\t",
// TokenName: 65,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 23,
// EndPos: 23,
// },
// Value: " ",
// TokenName: 129,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 10,
// EndLine: 11,
// StartPos: 139,
// EndPos: 141,
// },
// Value: "\n\t\t",
// TokenName: 130,
// },
// },
// NamespaceName: &name.Name{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// EndPos: 22,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 19,
// EndPos: 19,
// },
// Value: " ",
// TokenName: 10,
// },
// },
// Value: "Foo",
// },
// },
// },
// Stmts: []node.Node{
// &stmt.Class{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 10,
// StartPos: 29,
// EndPos: 138,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 3,
// EndLine: 4,
// StartPos: 25,
// EndPos: 28,
// },
// Value: "\n\t\t\t",
// TokenName: 52,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 38,
// EndPos: 38,
// },
// Value: " ",
// TokenName: 129,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 9,
// EndLine: 10,
// StartPos: 134,
// EndPos: 137,
// },
// Value: "\n\t\t\t",
// TokenName: 130,
// },
// },
// PhpDocComment: "",
// ClassName: &node.Identifier{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 35,
// EndPos: 37,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 34,
// EndPos: 34,
// },
// Value: " ",
// TokenName: 125,
// },
// },
// Value: "Bar",
// },
// Stmts: []node.Node{
// &stmt.ClassMethod{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 9,
// StartPos: 45,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 51,
// EndPos: 51,
// },
// Value: " ",
// TokenName: 38,
// },
// },
// ReturnsRef: false,
// PhpDocComment: "",
// MethodName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 61,
// EndPos: 72,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 60,
// EndPos: 60,
// },
// Value: " ",
// TokenName: 125,
// },
// },
// Value: "FunctionName",
// },
// Modifiers: []node.Node{
// &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 45,
// EndPos: 50,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 4,
// EndLine: 5,
// StartPos: 40,
// EndPos: 44,
// },
// Value: "\n\t\t\t\t",
// TokenName: 125,
// },
// },
// Value: "public",
// },
// },
// Params: []node.Node{
// &node.Parameter{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 83,
// EndPos: 83,
// },
// Value: " ",
// TokenName: 147,
// },
// },
// ByRef: false,
// Variadic: false,
// VariableType: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// EndPos: 77,
// },
// Value: "Type",
// },
// },
// },
// Variable: &expr.Variable{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 78,
// EndPos: 78,
// },
// Value: " ",
// TokenName: 12,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 82,
// },
// Value: "var",
// },
// },
// DefaultValue: &expr.ConstFetch{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Constant: &name.Name{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Parts: []node.Node{
// &name.NamePart{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// EndPos: 89,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 85,
// EndPos: 85,
// },
// Value: " ",
// TokenName: 10,
// },
// },
// Value: "null",
// },
// },
// },
// },
// },
// },
// Stmt: &stmt.StmtList{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 9,
// StartPos: 96,
// EndPos: 133,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 5,
// EndLine: 6,
// StartPos: 91,
// EndPos: 95,
// },
// Value: "\n\t\t\t\t",
// TokenName: 129,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 9,
// StartPos: 128,
// EndPos: 132,
// },
// Value: "\n\t\t\t\t",
// TokenName: 130,
// },
// },
// Stmts: []node.Node{
// &stmt.Expression{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 127,
// },
// Expr: &expr.Variable{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Meta: []meta.Meta{
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 6,
// EndLine: 7,
// StartPos: 97,
// EndPos: 102,
// },
// Value: "\n\t\t\t\t\t",
// TokenName: 12,
// },
// &meta.Comment{
// Position: &position.Position{
// StartLine: 7,
// EndLine: 7,
// StartPos: 103,
// EndPos: 117,
// },
// Value: "//some comment\n",
// TokenName: 12,
// },
// &meta.WhiteSpace{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 118,
// EndPos: 122,
// },
// Value: "\t\t\t\t\t",
// TokenName: 12,
// },
// },
// VarName: &node.Identifier{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 123,
// EndPos: 126,
// },
// Value: "var",
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
// },
// }
}

View File

@@ -53,9 +53,9 @@ func (d *JsonDumper) EnterNode(w walker.Walkable) bool {
switch m.(type) {
case *meta.Comment:
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.Comment", "value", m.String(), "tokenName", meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.Comment", "value", m.String(), "tokenName", m.GetTokenName().String())
case *meta.WhiteSpace:
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.WhiteSpace", "value", m.String(), "tokenName", meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "{%q:%q,%q:%q,%q:%q}", "type", "*meta.WhiteSpace", "value", m.String(), "tokenName", m.GetTokenName().String())
}
}

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.WhiteSpace","value":"\n\n\t\t","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","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.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":29,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"ClassToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"CloseCurlyBracesToken"}],"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":35,"endPos":37,"startLine":4,"endLine":4},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"FunctionToken"}],"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":61,"endPos":72,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"IdentifierToken"}],"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":45,"endPos":50,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"PublicToken"}],"Value":"public"}],"Params":[{"type":"*node.Parameter","position":{"startPos":74,"endPos":89,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","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.WhiteSpace","value":" ","tokenName":"VariableToken"}],"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.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":96,"endPos":157,"startLine":6,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"CloseCurlyBracesToken"}],"Stmts":[{"type":"*stmt.Expression","position":{"startPos":147,"endPos":151,"startLine":9,"endLine":9},"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// some comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// second comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"}],"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.WhiteSpace","value":"\n\n\t\t","tokenName":"NamespaceToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","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.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":29,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"ClassToken"},{"type":"*meta.WhiteSpace","value":" ","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t","tokenName":"CloseCurlyBracesToken"}],"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":35,"endPos":37,"startLine":4,"endLine":4},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"IdentifierToken"}],"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"FunctionToken"}],"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":61,"endPos":72,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","value":" ","tokenName":"IdentifierToken"}],"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":45,"endPos":50,"startLine":5,"endLine":5},"meta":[{"type":"*meta.WhiteSpace","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.WhiteSpace","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.WhiteSpace","value":" ","tokenName":"VariableToken"}],"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.WhiteSpace","value":" ","tokenName":"StringToken"}],"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":96,"endPos":157,"startLine":6,"endLine":10},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"OpenCurlyBracesToken"},{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t","tokenName":"CloseCurlyBracesToken"}],"Stmts":[{"type":"*stmt.Expression","position":{"startPos":147,"endPos":151,"startLine":9,"endLine":9},"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"meta":[{"type":"*meta.WhiteSpace","value":"\n\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// some comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\t\t\t\t\t","tokenName":"VariableToken"},{"type":"*meta.Comment","value":"// second comment\n","tokenName":"VariableToken"},{"type":"*meta.WhiteSpace","value":"\t\t\t\t\t","tokenName":"VariableToken"}],"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
}

View File

@@ -156,8 +156,8 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
nsr.ResolveName(t, "")
}
if n.TraitAdaptationList != nil {
for _, a := range n.TraitAdaptationList.Adaptations {
if adaptationList, ok := n.TraitAdaptationList.(*stmt.TraitAdaptationList); ok {
for _, a := range adaptationList.Adaptations {
switch aa := a.(type) {
case *stmt.TraitUsePrecedence:
refTrait := aa.Ref.(*stmt.TraitMethodRef).Trait

View File

@@ -105,7 +105,7 @@ func (d *PrettyJsonDumper) EnterNode(w walker.Walkable) bool {
d.printIndent(d.Writer)
fmt.Fprintf(d.Writer, "%q: %q,\n", "value", m.String())
d.printIndent(d.Writer)
fmt.Fprintf(d.Writer, "%q: %q\n", "tokenName", meta.TokenNames[m.GetTokenName()])
fmt.Fprintf(d.Writer, "%q: %q\n", "tokenName", m.GetTokenName().String())
d.depth--
d.printIndent(d.Writer)
fmt.Fprint(d.Writer, "}")

View File

@@ -45,6 +45,13 @@ func ExamplePrettyJsonDumper() {
// "startLine": 3,
// "endLine": 14
// },
// "meta": [
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t",
// "tokenName": "NodeEnd"
// }
// ],
// "Stmts": [
// {
// "type": "*stmt.Namespace",
@@ -139,7 +146,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*meta.WhiteSpace",
// "value": " ",
// "tokenName": "StringToken"
// "tokenName": "IdentifierToken"
// }
// ],
// "Value": "Bar"
@@ -192,7 +199,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t\t\t",
// "tokenName": "PublicToken"
// "tokenName": "IdentifierToken"
// }
// ],
// "Value": "public"
@@ -354,7 +361,7 @@ func ExamplePrettyJsonDumper() {
// },
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t\t\t\t",
// "value": "\t\t\t\t\t",
// "tokenName": "VariableToken"
// },
// {
@@ -364,7 +371,7 @@ func ExamplePrettyJsonDumper() {
// },
// {
// "type": "*meta.WhiteSpace",
// "value": "\n\t\t\t\t\t",
// "value": "\t\t\t\t\t",
// "tokenName": "VariableToken"
// }
// ],
@@ -420,7 +427,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*meta.WhiteSpace",
// "value": " ",
// "tokenName": "StringToken"
// "tokenName": "IdentifierToken"
// }
// ],
// "Value": "foo"