#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

@@ -569,9 +569,7 @@ func (p *PrettyPrinter) printScalarEncapsed(n node.Node) {
func (p *PrettyPrinter) printScalarHeredoc(n node.Node) {
nn := n.(*scalar.Heredoc)
io.WriteString(p.w, "<<<")
io.WriteString(p.w, nn.Label)
io.WriteString(p.w, "\n")
for _, part := range nn.Parts {
switch part.(type) {
@@ -584,7 +582,7 @@ func (p *PrettyPrinter) printScalarHeredoc(n node.Node) {
}
}
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
io.WriteString(p.w, strings.Trim(nn.Label, "<\"'\n"))
}
func (p *PrettyPrinter) printScalarMagicConstant(n node.Node) {

View File

@@ -87,7 +87,7 @@ func TestPrintFileInlineHtml(t *testing.T) {
&stmt.InlineHtml{Value: "<div>HTML</div>"},
&stmt.Expression{
Expr: &scalar.Heredoc{
Label: "\"LBL\"",
Label: "<<<\"LBL\"\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello world\n"},
},
@@ -356,7 +356,7 @@ func TestPrintScalarHeredoc(t *testing.T) {
p := printer.NewPrettyPrinter(o, " ")
p.Print(&scalar.Heredoc{
Label: "LBL",
Label: "<<<LBL\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello "},
&expr.Variable{VarName: &node.Identifier{Value: "var"}},
@@ -379,7 +379,7 @@ func TestPrintScalarNowdoc(t *testing.T) {
p := printer.NewPrettyPrinter(o, " ")
p.Print(&scalar.Heredoc{
Label: "'LBL'",
Label: "<<<'LBL'\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello world\n"},
},

View File

@@ -618,9 +618,7 @@ func (p *Printer) printScalarHeredoc(n node.Node) {
nn := n.(*scalar.Heredoc)
p.printFreeFloating(nn, freefloating.Start)
io.WriteString(p.w, "<<<")
io.WriteString(p.w, nn.Label)
io.WriteString(p.w, "\n")
for _, part := range nn.Parts {
switch part.(type) {
@@ -643,8 +641,7 @@ func (p *Printer) printScalarHeredoc(n node.Node) {
}
}
io.WriteString(p.w, "\n")
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
io.WriteString(p.w, strings.Trim(nn.Label, "<\"'\n"))
p.printFreeFloating(nn, freefloating.End)
}

View File

@@ -10,7 +10,7 @@ import (
)
func parsePhp5(src string) node.Node {
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.WithFreeFloating()
php5parser.Parse()

View File

@@ -29,7 +29,7 @@ abstract class Bar extends Baz
// parse
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()
@@ -61,7 +61,7 @@ abstract class Bar extends Baz
}
func parse(src string) node.Node {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()

View File

@@ -425,13 +425,13 @@ func TestPrinterPrintScalarHeredoc(t *testing.T) {
p := printer.NewPrinter(o)
p.Print(&scalar.Heredoc{
Label: "LBL",
Label: "<<<LBL\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello "},
&expr.Variable{
VarName: &node.Identifier{Value: "var"},
},
&scalar.EncapsedStringPart{Value: " world"},
&scalar.EncapsedStringPart{Value: " world\n"},
},
})
@@ -450,9 +450,9 @@ func TestPrinterPrintScalarNowdoc(t *testing.T) {
p := printer.NewPrinter(o)
p.Print(&scalar.Heredoc{
Label: "'LBL'",
Label: "<<<'LBL'\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello world"},
&scalar.EncapsedStringPart{Value: "hello world\n"},
},
})