diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 99de64f..8b13789 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,9 +1 @@ -Issue Description -```php -// PHP code trying to parse -``` - -``` -// console output -``` diff --git a/printer/pretty_printer.go b/printer/pretty_printer.go index 9fd17e6..314fcd3 100644 --- a/printer/pretty_printer.go +++ b/printer/pretty_printer.go @@ -551,10 +551,18 @@ func (p *PrettyPrinter) printScalarEncapsedStringPart(n node.Node) { } func (p *PrettyPrinter) printScalarEncapsed(n node.Node) { + nn := n.(*scalar.Encapsed) io.WriteString(p.w, "\"") - for _, nn := range n.(*scalar.Encapsed).Parts { - p.Print(nn) + for _, part := range nn.Parts { + switch part.(type) { + case *scalar.EncapsedStringPart: + p.Print(part) + default: + io.WriteString(p.w, "{") + p.Print(part) + io.WriteString(p.w, "}") + } } io.WriteString(p.w, "\"") @@ -567,8 +575,15 @@ func (p *PrettyPrinter) printScalarHeredoc(n node.Node) { io.WriteString(p.w, nn.Label) io.WriteString(p.w, "\n") - for _, nn := range nn.Parts { - p.Print(nn) + for _, part := range nn.Parts { + switch part.(type) { + case *scalar.EncapsedStringPart: + p.Print(part) + default: + io.WriteString(p.w, "{") + p.Print(part) + io.WriteString(p.w, "}") + } } io.WriteString(p.w, strings.Trim(nn.Label, "\"'")) @@ -1232,7 +1247,14 @@ func (p *PrettyPrinter) printExprShellExec(n node.Node) { io.WriteString(p.w, "`") for _, part := range nn.Parts { - p.Print(part) + switch part.(type) { + case *scalar.EncapsedStringPart: + p.Print(part) + default: + io.WriteString(p.w, "{") + p.Print(part) + io.WriteString(p.w, "}") + } } io.WriteString(p.w, "`") } diff --git a/printer/pretty_printer_test.go b/printer/pretty_printer_test.go index 5d2fd13..14f9880 100644 --- a/printer/pretty_printer_test.go +++ b/printer/pretty_printer_test.go @@ -346,7 +346,7 @@ func TestPrintScalarEncapsed(t *testing.T) { }, }) - if o.String() != `"hello $var world"` { + if o.String() != `"hello {$var} world"` { t.Errorf("TestPrintScalarEncapsed is failed\n") } } @@ -365,7 +365,7 @@ func TestPrintScalarHeredoc(t *testing.T) { }) expected := `<< & $v ) { - ` + "` $v cmd `" + ` ; + ` + "` {$v} cmd `" + ` ; }` actual := print(parse(src)) @@ -714,7 +714,7 @@ func TestParseAndPrintScalar(t *testing.T) { .2 ; 0.2 ; 'Hello' ; - "Hello $world"; + "Hello {$world}"; ` actual := print(parse(src)) diff --git a/printer/printer_test.go b/printer/printer_test.go index 5ec09ac..ead4a44 100644 --- a/printer/printer_test.go +++ b/printer/printer_test.go @@ -555,7 +555,7 @@ func TestPrinterPrintScalarEncapsed(t *testing.T) { }, }) - if o.String() != ` "hello $var world"` { + if o.String() != ` "hello {$var} world"` { t.Errorf("TestPrintScalarEncapsed is failed\n") } } @@ -580,7 +580,7 @@ func TestPrinterPrintScalarHeredoc(t *testing.T) { }) expected := ` <<