#80 implement Ragel based lexer

This commit is contained in:
z7zmey
2019-03-10 23:37:01 +02:00
parent 9ca7109abe
commit 2c649159c7
108 changed files with 30415 additions and 18534 deletions

View File

@@ -1,7 +1,6 @@
package visitor_test
import (
"bytes"
"os"
"github.com/z7zmey/php-parser/php7"
@@ -21,7 +20,7 @@ func ExampleDumper() {
}
}`
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()
nodes := php7parser.GetRootNode()
@@ -38,27 +37,27 @@ func ExampleDumper() {
// Unordered output:
// | [*node.Root]
// | "Position": Pos{Line: 3-11 Pos: 10-144}
// | "Position": Pos{Line: 3-11 Pos: 9-144}
// | "Stmts":
// | [*stmt.Namespace]
// | "Position": Pos{Line: 3-11 Pos: 10-144}
// | "Position": Pos{Line: 3-11 Pos: 9-144}
// | "freefloating":
// | "Start": "<?php"
// | "Start": "\n\n\t\t"
// | "Stmts": "\n\t\t"
// | "NamespaceName":
// | [*name.Name]
// | "Position": Pos{Line: 3-3 Pos: 20-22}
// | "Position": Pos{Line: 3-3 Pos: 19-22}
// | "freefloating":
// | "Start": " "
// | "End": " "
// | "Parts":
// | [*name.NamePart]
// | "Position": Pos{Line: 3-3 Pos: 20-22}
// | "Position": Pos{Line: 3-3 Pos: 19-22}
// | "Value": "Foo"
// | "Stmts":
// | [*stmt.Class]
// | "Position": Pos{Line: 4-10 Pos: 29-140}
// | "Position": Pos{Line: 4-10 Pos: 28-140}
// | "NamespacedName": "Foo\\Bar"
// | "freefloating":
// | "Start": "\n\t\t\t"
@@ -67,13 +66,13 @@ func ExampleDumper() {
// | "PhpDocComment": ""
// | "ClassName":
// | [*node.Identifier]
// | "Position": Pos{Line: 4-4 Pos: 35-37}
// | "Position": Pos{Line: 4-4 Pos: 34-37}
// | "freefloating":
// | "Start": " "
// | "Value": "Bar"
// | "Stmts":
// | [*stmt.ClassMethod]
// | "Position": Pos{Line: 5-9 Pos: 46-135}
// | "Position": Pos{Line: 5-9 Pos: 45-135}
// | "freefloating":
// | "Start": " \n\t\t\t\t"
// | "ModifierList": " "
@@ -82,15 +81,15 @@ func ExampleDumper() {
// | "PhpDocComment": ""
// | "MethodName":
// | [*node.Identifier]
// | "Position": Pos{Line: 5-5 Pos: 62-73}
// | "Position": Pos{Line: 5-5 Pos: 61-73}
// | "Value": "FunctionName"
// | "Modifiers":
// | [*node.Identifier]
// | "Position": Pos{Line: 5-5 Pos: 46-51}
// | "Position": Pos{Line: 5-5 Pos: 45-51}
// | "Value": "public"
// | "Params":
// | [*node.Parameter]
// | "Position": Pos{Line: 5-5 Pos: 75-90}
// | "Position": Pos{Line: 5-5 Pos: 74-90}
// | "freefloating":
// | "OptionalType": " "
// | "Var": " "
@@ -98,43 +97,43 @@ func ExampleDumper() {
// | "ByRef": false
// | "VariableType":
// | [*name.Name]
// | "Position": Pos{Line: 5-5 Pos: 75-78}
// | "Position": Pos{Line: 5-5 Pos: 74-78}
// | "NamespacedName": "Foo\\Type"
// | "Parts":
// | [*name.NamePart]
// | "Position": Pos{Line: 5-5 Pos: 75-78}
// | "Position": Pos{Line: 5-5 Pos: 74-78}
// | "Value": "Type"
// | "Variable":
// | [*expr.Variable]
// | "Position": Pos{Line: 5-5 Pos: 80-83}
// | "Position": Pos{Line: 5-5 Pos: 79-83}
// | "freefloating":
// | "Dollar": "$"
// | "VarName":
// | [*node.Identifier]
// | "Position": Pos{Line: 5-5 Pos: 80-83}
// | "Position": Pos{Line: 5-5 Pos: 79-83}
// | "Value": "var"
// | "DefaultValue":
// | [*expr.ConstFetch]
// | "Position": Pos{Line: 5-5 Pos: 87-90}
// | "Position": Pos{Line: 5-5 Pos: 86-90}
// | "freefloating":
// | "Start": " "
// | "Constant":
// | [*name.Name]
// | "Position": Pos{Line: 5-5 Pos: 87-90}
// | "Position": Pos{Line: 5-5 Pos: 86-90}
// | "NamespacedName": "null"
// | "Parts":
// | [*name.NamePart]
// | "Position": Pos{Line: 5-5 Pos: 87-90}
// | "Position": Pos{Line: 5-5 Pos: 86-90}
// | "Value": "null"
// | "Stmt":
// | [*stmt.StmtList]
// | "Position": Pos{Line: 6-9 Pos: 97-135}
// | "Position": Pos{Line: 6-9 Pos: 96-135}
// | "freefloating":
// | "Start": "\n\t\t\t\t"
// | "Stmts": "\n\t\t\t\t"
// | "Stmts":
// | [*stmt.Expression]
// | "Position": Pos{Line: 8-8 Pos: 125-129}
// | "Position": Pos{Line: 8-8 Pos: 124-129}
// | "freefloating":
// | "SemiColon": ";"
// | "Start": "\n\t\t\t\t\t"
@@ -142,11 +141,11 @@ func ExampleDumper() {
// | "Start": "\t\t\t\t\t"
// | "Expr":
// | [*expr.Variable]
// | "Position": Pos{Line: 8-8 Pos: 125-128}
// | "Position": Pos{Line: 8-8 Pos: 124-128}
// | "freefloating":
// | "Dollar": "$"
// | "VarName":
// | [*node.Identifier]
// | "Position": Pos{Line: 8-8 Pos: 125-128}
// | "Position": Pos{Line: 8-8 Pos: 124-128}
// | "Value": "var"
}

View File

@@ -1,7 +1,6 @@
package visitor_test
import (
"bytes"
"os"
"github.com/z7zmey/php-parser/php7"
@@ -21,7 +20,7 @@ func ExampleGoDumper() {
}
}`
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()
nodes := php7parser.GetRootNode()
@@ -39,7 +38,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// StartPos: 9,
// EndPos: 143,
// },
// Stmts: []node.Node{
@@ -47,7 +46,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 3,
// EndLine: 11,
// StartPos: 10,
// StartPos: 9,
// EndPos: 143,
// },
// FreeFloating: freefloating.Collection{
@@ -57,7 +56,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 10,
// EndLine: 11,
// StartPos: 140,
// StartPos: 139,
// EndPos: 142,
// },
// Value: "\n\t\t",
@@ -69,7 +68,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 1,
// EndLine: 1,
// StartPos: 1,
// StartPos: 0,
// EndPos: 5,
// },
// Value: "<?php",
@@ -79,7 +78,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 1,
// EndLine: 3,
// StartPos: 6,
// StartPos: 5,
// EndPos: 9,
// },
// Value: "\n\n\t\t",
@@ -90,7 +89,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// StartPos: 19,
// EndPos: 22,
// },
// FreeFloating: freefloating.Collection{
@@ -100,7 +99,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 19,
// StartPos: 18,
// EndPos: 19,
// },
// Value: " ",
@@ -112,7 +111,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 23,
// StartPos: 22,
// EndPos: 23,
// },
// Value: " ",
@@ -124,7 +123,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 3,
// EndLine: 3,
// StartPos: 20,
// StartPos: 19,
// EndPos: 22,
// },
// Value: "Foo",
@@ -136,7 +135,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 4,
// EndLine: 10,
// StartPos: 29,
// StartPos: 28,
// EndPos: 139,
// },
// FreeFloating: freefloating.Collection{
@@ -146,7 +145,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 3,
// EndLine: 4,
// StartPos: 25,
// StartPos: 24,
// EndPos: 28,
// },
// Value: "\n\t\t\t",
@@ -158,7 +157,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 38,
// StartPos: 37,
// EndPos: 38,
// },
// Value: " ",
@@ -170,7 +169,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 9,
// EndLine: 10,
// StartPos: 135,
// StartPos: 134,
// EndPos: 138,
// },
// Value: "\n\t\t\t",
@@ -182,7 +181,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 35,
// StartPos: 34,
// EndPos: 37,
// },
// FreeFloating: freefloating.Collection{
@@ -192,7 +191,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 4,
// EndLine: 4,
// StartPos: 34,
// StartPos: 33,
// EndPos: 34,
// },
// Value: " ",
@@ -206,7 +205,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 9,
// StartPos: 45,
// StartPos: 44,
// EndPos: 134,
// },
// FreeFloating: freefloating.Collection{
@@ -216,7 +215,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 4,
// EndLine: 5,
// StartPos: 40,
// StartPos: 39,
// EndPos: 44,
// },
// Value: "\n\t\t\t\t",
@@ -228,7 +227,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 51,
// StartPos: 50,
// EndPos: 51,
// },
// Value: " ",
@@ -240,7 +239,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 60,
// StartPos: 59,
// EndPos: 60,
// },
// Value: " ",
@@ -253,7 +252,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 61,
// StartPos: 60,
// EndPos: 72,
// },
// Value: "FunctionName",
@@ -263,7 +262,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 45,
// StartPos: 44,
// EndPos: 50,
// },
// Value: "public",
@@ -274,7 +273,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// StartPos: 73,
// EndPos: 89,
// },
// FreeFloating: freefloating.Collection{
@@ -284,7 +283,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 78,
// StartPos: 77,
// EndPos: 78,
// },
// Value: " ",
@@ -296,7 +295,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 83,
// StartPos: 82,
// EndPos: 83,
// },
// Value: " ",
@@ -309,7 +308,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// StartPos: 73,
// EndPos: 77,
// },
// Parts: []node.Node{
@@ -317,7 +316,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 74,
// StartPos: 73,
// EndPos: 77,
// },
// Value: "Type",
@@ -328,7 +327,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// StartPos: 78,
// EndPos: 82,
// },
// FreeFloating: freefloating.Collection{
@@ -338,8 +337,8 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// EndPos: 80,
// StartPos: 78,
// EndPos: 79,
// },
// Value: "$",
// },
@@ -349,7 +348,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 79,
// StartPos: 78,
// EndPos: 82,
// },
// Value: "var",
@@ -359,7 +358,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// StartPos: 85,
// EndPos: 89,
// },
// FreeFloating: freefloating.Collection{
@@ -369,7 +368,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 85,
// StartPos: 84,
// EndPos: 85,
// },
// Value: " ",
@@ -380,7 +379,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// StartPos: 85,
// EndPos: 89,
// },
// Parts: []node.Node{
@@ -388,7 +387,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 5,
// EndLine: 5,
// StartPos: 86,
// StartPos: 85,
// EndPos: 89,
// },
// Value: "null",
@@ -402,41 +401,41 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 6,
// EndLine: 9,
// StartPos: 96,
// StartPos: 95,
// EndPos: 134,
// },
// FreeFloating: freefloating.Collection{
// "Stmts": []freefloating.String{
// freefloating.String{
// Type: freefloating.WhiteSpaceType,
// Position: &position.Position{
// StartLine: 8,
// EndLine: 9,
// StartPos: 129,
// EndPos: 133,
// },
// Value: "\n\t\t\t\t",
// },
// },
// "Start": []freefloating.String{
// freefloating.String{
// Type: freefloating.WhiteSpaceType,
// Position: &position.Position{
// StartLine: 5,
// EndLine: 6,
// StartPos: 91,
// StartPos: 90,
// EndPos: 95,
// },
// Value: "\n\t\t\t\t",
// },
// },
// "Stmts": []freefloating.String{
// freefloating.String{
// Type: freefloating.WhiteSpaceType,
// Position: &position.Position{
// StartLine: 8,
// EndLine: 9,
// StartPos: 128,
// EndPos: 133,
// },
// Value: "\n\t\t\t\t",
// },
// },
// },
// Stmts: []node.Node{
// &stmt.Expression{
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 124,
// StartPos: 123,
// EndPos: 128,
// },
// FreeFloating: freefloating.Collection{
@@ -446,7 +445,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 6,
// EndLine: 7,
// StartPos: 97,
// StartPos: 96,
// EndPos: 102,
// },
// Value: "\n\t\t\t\t\t",
@@ -456,7 +455,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 7,
// EndLine: 7,
// StartPos: 103,
// StartPos: 102,
// EndPos: 118,
// },
// Value: "// some comment\n",
@@ -466,7 +465,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 119,
// StartPos: 118,
// EndPos: 123,
// },
// Value: "\t\t\t\t\t",
@@ -478,7 +477,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 128,
// StartPos: 127,
// EndPos: 128,
// },
// Value: ";",
@@ -489,7 +488,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 124,
// StartPos: 123,
// EndPos: 127,
// },
// FreeFloating: freefloating.Collection{
@@ -499,8 +498,8 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 124,
// EndPos: 125,
// StartPos: 123,
// EndPos: 124,
// },
// Value: "$",
// },
@@ -510,7 +509,7 @@ func ExampleGoDumper() {
// Position: &position.Position{
// StartLine: 8,
// EndLine: 8,
// StartPos: 124,
// StartPos: 123,
// EndPos: 127,
// },
// Value: "var",

View File

@@ -1,7 +1,6 @@
package visitor_test
import (
"bytes"
"os"
"github.com/z7zmey/php-parser/php7"
@@ -22,7 +21,7 @@ func ExampleJsonDumper() {
}
}`
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()
nodes := php7parser.GetRootNode()
@@ -37,5 +36,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},"freefloating":{"Start": [{"type":"freefloating.TokenType","value":"<?php"},{"type":"freefloating.WhiteSpaceType","value":"\n\n\t\t"}],"Stmts": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t"}]},"NamespaceName":{"type":"*name.Name","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":" "}],"End": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"Parts":[{"type":"*name.NamePart","position":{"startPos":20,"endPos":22,"startLine":3,"endLine":3},"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":29,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t"}],"Name": [{"type":"freefloating.WhiteSpaceType","value":" "}],"Stmts": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t"}]},"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":35,"endPos":37,"startLine":4,"endLine":4},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":45,"endPos":157,"startLine":5,"endLine":10},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t"}],"Function": [{"type":"freefloating.WhiteSpaceType","value":" "}],"ModifierList": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":61,"endPos":72,"startLine":5,"endLine":5},"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},"freefloating":{"Var": [{"type":"freefloating.WhiteSpaceType","value":" "}],"OptionalType": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"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},"freefloating":{"Dollar": [{"type":"freefloating.TokenType","value":"$"}]},"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},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"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},"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":96,"endPos":157,"startLine":6,"endLine":10},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t"}],"Stmts": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t"}]},"Stmts":[{"type":"*stmt.Expression","position":{"startPos":147,"endPos":151,"startLine":9,"endLine":9},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t\t"},{"type":"freefloating.CommentType","value":"// some comment\n"},{"type":"freefloating.WhiteSpaceType","value":"\t\t\t\t\t"},{"type":"freefloating.CommentType","value":"// second comment\n"},{"type":"freefloating.WhiteSpaceType","value":"\t\t\t\t\t"}],"SemiColon": [{"type":"freefloating.TokenType","value":";"}]},"Expr":{"type":"*expr.Variable","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"freefloating":{"Dollar": [{"type":"freefloating.TokenType","value":"$"}]},"VarName":{"type":"*node.Identifier","position":{"startPos":147,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
// {"type":"*node.Root","position":{"startPos":9,"endPos":166,"startLine":3,"endLine":12},"Stmts":[{"type":"*stmt.Namespace","position":{"startPos":9,"endPos":166,"startLine":3,"endLine":12},"freefloating":{"Start": [{"type":"freefloating.TokenType","value":"<?php"},{"type":"freefloating.WhiteSpaceType","value":"\n\n\t\t"}],"Stmts": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t"}]},"NamespaceName":{"type":"*name.Name","position":{"startPos":19,"endPos":22,"startLine":3,"endLine":3},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":" "}],"End": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"Parts":[{"type":"*name.NamePart","position":{"startPos":19,"endPos":22,"startLine":3,"endLine":3},"Value":"Foo"}]},"Stmts":[{"type":"*stmt.Class","position":{"startPos":28,"endPos":162,"startLine":4,"endLine":11},"namespacedName":"Foo\\Bar","freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t"}],"Name": [{"type":"freefloating.WhiteSpaceType","value":" "}],"Stmts": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t"}]},"PhpDocComment":"","ClassName":{"type":"*node.Identifier","position":{"startPos":34,"endPos":37,"startLine":4,"endLine":4},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"Value":"Bar"},"Stmts":[{"type":"*stmt.ClassMethod","position":{"startPos":44,"endPos":157,"startLine":5,"endLine":10},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t"}],"Function": [{"type":"freefloating.WhiteSpaceType","value":" "}],"ModifierList": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"PhpDocComment":"","ReturnsRef":false,"MethodName":{"type":"*node.Identifier","position":{"startPos":60,"endPos":72,"startLine":5,"endLine":5},"Value":"FunctionName"},"Modifiers":[{"type":"*node.Identifier","position":{"startPos":44,"endPos":50,"startLine":5,"endLine":5},"Value":"public"}],"Params":[{"type":"*node.Parameter","position":{"startPos":73,"endPos":89,"startLine":5,"endLine":5},"freefloating":{"Var": [{"type":"freefloating.WhiteSpaceType","value":" "}],"OptionalType": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"ByRef":false,"Variadic":false,"VariableType":{"type":"*name.Name","position":{"startPos":73,"endPos":77,"startLine":5,"endLine":5},"namespacedName":"Foo\\Type","Parts":[{"type":"*name.NamePart","position":{"startPos":73,"endPos":77,"startLine":5,"endLine":5},"Value":"Type"}]},"Variable":{"type":"*expr.Variable","position":{"startPos":78,"endPos":82,"startLine":5,"endLine":5},"freefloating":{"Dollar": [{"type":"freefloating.TokenType","value":"$"}]},"VarName":{"type":"*node.Identifier","position":{"startPos":78,"endPos":82,"startLine":5,"endLine":5},"Value":"var"}},"DefaultValue":{"type":"*expr.ConstFetch","position":{"startPos":85,"endPos":89,"startLine":5,"endLine":5},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":" "}]},"Constant":{"type":"*name.Name","position":{"startPos":85,"endPos":89,"startLine":5,"endLine":5},"namespacedName":"null","Parts":[{"type":"*name.NamePart","position":{"startPos":85,"endPos":89,"startLine":5,"endLine":5},"Value":"null"}]}}}],"Stmt":{"type":"*stmt.StmtList","position":{"startPos":95,"endPos":157,"startLine":6,"endLine":10},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t"}],"Stmts": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t"}]},"Stmts":[{"type":"*stmt.Expression","position":{"startPos":146,"endPos":151,"startLine":9,"endLine":9},"freefloating":{"Start": [{"type":"freefloating.WhiteSpaceType","value":"\n\t\t\t\t\t"},{"type":"freefloating.CommentType","value":"// some comment\n"},{"type":"freefloating.WhiteSpaceType","value":"\t\t\t\t\t"},{"type":"freefloating.CommentType","value":"// second comment\n"},{"type":"freefloating.WhiteSpaceType","value":"\t\t\t\t\t"}],"SemiColon": [{"type":"freefloating.TokenType","value":";"}]},"Expr":{"type":"*expr.Variable","position":{"startPos":146,"endPos":150,"startLine":9,"endLine":9},"freefloating":{"Dollar": [{"type":"freefloating.TokenType","value":"$"}]},"VarName":{"type":"*node.Identifier","position":{"startPos":146,"endPos":150,"startLine":9,"endLine":9},"Value":"var"}}}]}}]}]}]}
}

View File

@@ -1,7 +1,6 @@
package visitor_test
import (
"bytes"
"os"
"github.com/z7zmey/php-parser/php7"
@@ -27,7 +26,7 @@ func ExamplePrettyJsonDumper() {
}
`
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()
nodes := php7parser.GetRootNode()
@@ -42,7 +41,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*node.Root",
// "position": {
// "startPos": 10,
// "startPos": 9,
// "endPos": 198,
// "startLine": 3,
// "endLine": 16
@@ -59,7 +58,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*stmt.Namespace",
// "position": {
// "startPos": 10,
// "startPos": 9,
// "endPos": 198,
// "startLine": 3,
// "endLine": 16
@@ -85,19 +84,19 @@ func ExamplePrettyJsonDumper() {
// "NamespaceName": {
// "type": "*name.Name",
// "position": {
// "startPos": 20,
// "startPos": 19,
// "endPos": 22,
// "startLine": 3,
// "endLine": 3
// },
// "freefloating": {
// "End": [
// "Start": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
// }
// ],
// "Start": [
// "End": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
@@ -108,7 +107,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*name.NamePart",
// "position": {
// "startPos": 20,
// "startPos": 19,
// "endPos": 22,
// "startLine": 3,
// "endLine": 3
@@ -121,7 +120,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*stmt.Class",
// "position": {
// "startPos": 29,
// "startPos": 28,
// "endPos": 162,
// "startLine": 4,
// "endLine": 11
@@ -151,7 +150,7 @@ func ExamplePrettyJsonDumper() {
// "ClassName": {
// "type": "*node.Identifier",
// "position": {
// "startPos": 35,
// "startPos": 34,
// "endPos": 37,
// "startLine": 4,
// "endLine": 4
@@ -170,7 +169,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*stmt.ClassMethod",
// "position": {
// "startPos": 45,
// "startPos": 44,
// "endPos": 157,
// "startLine": 5,
// "endLine": 10
@@ -193,12 +192,6 @@ func ExamplePrettyJsonDumper() {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
// }
// ],
// "Name": [
// ],
// "ParameterList": [
// ]
// },
// "ReturnsRef": false,
@@ -206,7 +199,7 @@ func ExamplePrettyJsonDumper() {
// "MethodName": {
// "type": "*node.Identifier",
// "position": {
// "startPos": 61,
// "startPos": 60,
// "endPos": 72,
// "startLine": 5,
// "endLine": 5
@@ -217,7 +210,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*node.Identifier",
// "position": {
// "startPos": 45,
// "startPos": 44,
// "endPos": 50,
// "startLine": 5,
// "endLine": 5
@@ -229,26 +222,17 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*node.Parameter",
// "position": {
// "startPos": 74,
// "startPos": 73,
// "endPos": 89,
// "startLine": 5,
// "endLine": 5
// },
// "freefloating": {
// "Ref": [
// ],
// "OptionalType": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
// }
// ],
// "Start": [
// ],
// "Variadic": [
// ],
// "Var": [
// {
@@ -262,7 +246,7 @@ func ExamplePrettyJsonDumper() {
// "VariableType": {
// "type": "*name.Name",
// "position": {
// "startPos": 74,
// "startPos": 73,
// "endPos": 77,
// "startLine": 5,
// "endLine": 5
@@ -272,7 +256,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*name.NamePart",
// "position": {
// "startPos": 74,
// "startPos": 73,
// "endPos": 77,
// "startLine": 5,
// "endLine": 5
@@ -284,7 +268,7 @@ func ExamplePrettyJsonDumper() {
// "Variable": {
// "type": "*expr.Variable",
// "position": {
// "startPos": 79,
// "startPos": 78,
// "endPos": 82,
// "startLine": 5,
// "endLine": 5
@@ -300,7 +284,7 @@ func ExamplePrettyJsonDumper() {
// "VarName": {
// "type": "*node.Identifier",
// "position": {
// "startPos": 79,
// "startPos": 78,
// "endPos": 82,
// "startLine": 5,
// "endLine": 5
@@ -311,7 +295,7 @@ func ExamplePrettyJsonDumper() {
// "DefaultValue": {
// "type": "*expr.ConstFetch",
// "position": {
// "startPos": 86,
// "startPos": 85,
// "endPos": 89,
// "startLine": 5,
// "endLine": 5
@@ -327,7 +311,7 @@ func ExamplePrettyJsonDumper() {
// "Constant": {
// "type": "*name.Name",
// "position": {
// "startPos": 86,
// "startPos": 85,
// "endPos": 89,
// "startLine": 5,
// "endLine": 5
@@ -337,7 +321,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*name.NamePart",
// "position": {
// "startPos": 86,
// "startPos": 85,
// "endPos": 89,
// "startLine": 5,
// "endLine": 5
@@ -352,19 +336,19 @@ func ExamplePrettyJsonDumper() {
// "Stmt": {
// "type": "*stmt.StmtList",
// "position": {
// "startPos": 96,
// "startPos": 95,
// "endPos": 157,
// "startLine": 6,
// "endLine": 10
// },
// "freefloating": {
// "Start": [
// "Stmts": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": "\n\t\t\t\t"
// }
// ],
// "Stmts": [
// "Start": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": "\n\t\t\t\t"
@@ -375,7 +359,7 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*stmt.Expression",
// "position": {
// "startPos": 147,
// "startPos": 146,
// "endPos": 151,
// "startLine": 9,
// "endLine": 9
@@ -402,9 +386,6 @@ func ExamplePrettyJsonDumper() {
// "type": "freefloating.WhiteSpaceType",
// "value": "\t\t\t\t\t"
// }
// ],
// "Expr": [
// ],
// "SemiColon": [
// {
@@ -416,15 +397,12 @@ func ExamplePrettyJsonDumper() {
// "Expr": {
// "type": "*expr.Variable",
// "position": {
// "startPos": 147,
// "startPos": 146,
// "endPos": 150,
// "startLine": 9,
// "endLine": 9
// },
// "freefloating": {
// "Start": [
// ],
// "Dollar": [
// {
// "type": "freefloating.TokenType",
@@ -435,7 +413,7 @@ func ExamplePrettyJsonDumper() {
// "VarName": {
// "type": "*node.Identifier",
// "position": {
// "startPos": 147,
// "startPos": 146,
// "endPos": 150,
// "startLine": 9,
// "endLine": 9
@@ -452,37 +430,25 @@ func ExamplePrettyJsonDumper() {
// {
// "type": "*stmt.Function",
// "position": {
// "startPos": 168,
// "startPos": 167,
// "endPos": 194,
// "startLine": 13,
// "endLine": 15
// },
// "namespacedName": "Foo\\foo",
// "freefloating": {
// "Params": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
// }
// ],
// "Start": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": "\n\n\t\t\t"
// }
// ],
// "Function": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
// }
// ],
// "Name": [
// ],
// "ParamList": [
// ],
// "ReturnType": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
// }
// ],
// "Stmts": [
// {
// "type": "freefloating.WhiteSpaceType",
@@ -495,18 +461,26 @@ func ExamplePrettyJsonDumper() {
// "FunctionName": {
// "type": "*node.Identifier",
// "position": {
// "startPos": 177,
// "startPos": 176,
// "endPos": 179,
// "startLine": 13,
// "endLine": 13
// },
// "freefloating": {
// "Start": [
// {
// "type": "freefloating.WhiteSpaceType",
// "value": " "
// }
// ]
// },
// "Value": "foo"
// },
// "Stmts": [
// {
// "type": "*stmt.Nop",
// "position": {
// "startPos": 189,
// "startPos": 188,
// "endPos": 189,
// "startLine": 14,
// "endLine": 14