#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 scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@@ -23,7 +22,7 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@@ -31,14 +30,14 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Parts: []node.Node{
@@ -46,7 +45,7 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@@ -55,14 +54,14 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "var",
@@ -74,12 +73,12 @@ func TestSimpleVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -92,7 +91,7 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@@ -100,14 +99,14 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Parts: []node.Node{
@@ -115,7 +114,7 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@@ -124,14 +123,14 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@@ -143,12 +142,12 @@ func TestSimpleVarOneChar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -161,7 +160,7 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@@ -169,14 +168,14 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@@ -184,7 +183,7 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@@ -193,14 +192,14 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "var",
@@ -210,7 +209,7 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "\\\"",
@@ -221,12 +220,12 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -239,7 +238,7 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@@ -247,14 +246,14 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Parts: []node.Node{
@@ -262,7 +261,7 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 5,
},
Value: "=",
@@ -271,14 +270,14 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
Value: "a",
@@ -288,14 +287,14 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "b",
@@ -307,12 +306,12 @@ func TestStringVarCurveOpen(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -325,7 +324,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Stmts: []node.Node{
@@ -333,14 +332,14 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Parts: []node.Node{
@@ -348,7 +347,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@@ -357,21 +356,21 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 18,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "foo",
@@ -381,7 +380,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 18,
},
Value: "bar",
@@ -391,7 +390,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "()",
@@ -402,12 +401,12 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -420,7 +419,7 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@@ -428,14 +427,14 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@@ -443,7 +442,7 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@@ -452,14 +451,14 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 14,
},
Value: "foo",
@@ -471,12 +470,12 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -489,7 +488,7 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Stmts: []node.Node{
@@ -497,14 +496,14 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Parts: []node.Node{
@@ -512,7 +511,7 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@@ -521,95 +520,9 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 18,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
Value: "foo",
},
},
Dim: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 16,
},
Value: "0",
},
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestCurlyOpenMethodCall(t *testing.T) {
src := `<? "test {$foo->bar()}";`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 23,
},
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
EndPos: 9,
},
Value: "test ",
},
&expr.MethodCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 21,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
@@ -627,11 +540,97 @@ func TestCurlyOpenMethodCall(t *testing.T) {
Value: "foo",
},
},
Dim: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 16,
},
Value: "0",
},
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestCurlyOpenMethodCall(t *testing.T) {
src := `<? "test {$foo->bar()}";`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 23,
},
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
},
&expr.MethodCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 21,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 14,
},
Value: "foo",
},
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 19,
},
Value: "bar",
@@ -640,7 +639,7 @@ func TestCurlyOpenMethodCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 21,
},
},
@@ -651,12 +650,12 @@ func TestCurlyOpenMethodCall(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@@ -26,7 +25,7 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@@ -34,23 +33,23 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 23,
},
Label: "LBL",
Label: "<<<LBL\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 11,
StartPos: 10,
EndPos: 15,
},
Value: "test ",
@@ -59,31 +58,40 @@ LBL;
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 16,
StartPos: 15,
EndPos: 19,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 16,
StartPos: 15,
EndPos: 19,
},
Value: "var",
},
},
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 19,
EndPos: 20,
},
Value: "\n",
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -99,7 +107,7 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@@ -107,23 +115,23 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 25,
},
Label: "\"LBL\"",
Label: "<<<\"LBL\"\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 13,
StartPos: 12,
EndPos: 17,
},
Value: "test ",
@@ -132,31 +140,40 @@ LBL;
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 18,
StartPos: 17,
EndPos: 21,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 18,
StartPos: 17,
EndPos: 21,
},
Value: "var",
},
},
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 22,
},
Value: "\n",
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -172,7 +189,7 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@@ -180,26 +197,26 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 25,
},
Label: "'LBL'",
Label: "<<<'LBL'\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 13,
EndPos: 21,
StartPos: 12,
EndPos: 22,
},
Value: "test $var",
Value: "test $var\n",
},
},
},
@@ -207,12 +224,12 @@ LBL;
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -227,7 +244,7 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 7,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@@ -235,28 +252,28 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 7,
StartPos: 3,
EndPos: 14,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 7,
StartPos: 3,
EndPos: 13,
},
Label: "CAD",
Label: "<<<CAD\n",
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -272,7 +289,7 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@@ -280,26 +297,26 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 21,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 20,
},
Label: "CAD",
Label: "<<<CAD\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 11,
EndPos: 16,
StartPos: 10,
EndPos: 17,
},
Value: "\thello",
Value: "\thello\n",
},
},
},
@@ -307,12 +324,12 @@ CAD;
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@@ -22,7 +21,7 @@ func TestMagicConstant(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@@ -30,14 +29,14 @@ func TestMagicConstant(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &scalar.MagicConstant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Value: "__DIR__",
@@ -46,12 +45,12 @@ func TestMagicConstant(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@@ -21,7 +20,7 @@ func TestLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@@ -29,14 +28,14 @@ func TestLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Value: "1234567890123456789",
@@ -45,12 +44,12 @@ func TestLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -63,7 +62,7 @@ func TestDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@@ -71,14 +70,14 @@ func TestDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Value: "12345678901234567890",
@@ -87,12 +86,12 @@ func TestDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -105,7 +104,7 @@ func TestFloat(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Stmts: []node.Node{
@@ -113,14 +112,14 @@ func TestFloat(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "0.",
@@ -129,12 +128,12 @@ func TestFloat(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -147,7 +146,7 @@ func TestBinaryLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Stmts: []node.Node{
@@ -155,14 +154,14 @@ func TestBinaryLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 69,
},
Value: "0b0111111111111111111111111111111111111111111111111111111111111111",
@@ -171,12 +170,12 @@ func TestBinaryLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -189,7 +188,7 @@ func TestBinaryDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Stmts: []node.Node{
@@ -197,14 +196,14 @@ func TestBinaryDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 69,
},
Value: "0b1111111111111111111111111111111111111111111111111111111111111111",
@@ -213,12 +212,12 @@ func TestBinaryDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -231,7 +230,7 @@ func TestHLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@@ -239,14 +238,14 @@ func TestHLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Value: "0x007111111111111111",
@@ -255,12 +254,12 @@ func TestHLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -273,7 +272,7 @@ func TestHDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Stmts: []node.Node{
@@ -281,14 +280,14 @@ func TestHDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Value: "0x8111111111111111",
@@ -297,12 +296,12 @@ func TestHDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@@ -21,7 +20,7 @@ func TestDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Stmts: []node.Node{
@@ -29,14 +28,14 @@ func TestDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Value: "\"test\"",
@@ -45,12 +44,12 @@ func TestDoubleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -63,7 +62,7 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@@ -71,14 +70,14 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Value: "\"\\$test\"",
@@ -87,12 +86,12 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -107,7 +106,7 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@@ -115,14 +114,14 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Value: "\"\n\ttest\n\t\"",
@@ -131,12 +130,12 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -149,7 +148,7 @@ func TestSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@@ -157,14 +156,14 @@ func TestSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Value: "'$test'",
@@ -173,12 +172,12 @@ func TestSingleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -193,7 +192,7 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@@ -201,14 +200,14 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Value: "'\n\t$test\n\t'",
@@ -217,12 +216,12 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)