From d2655bd75b5216c427449dc57762c640bcc6e7b5 Mon Sep 17 00:00:00 2001 From: Vadym Slizov Date: Mon, 9 Jul 2018 21:19:33 +0300 Subject: [PATCH 1/2] Update ISSUE_TEMPLATE.md --- ISSUE_TEMPLATE.md | 8 -------- 1 file changed, 8 deletions(-) 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 -``` From 6d554c0468596ce633490e01f7d7cb179c7dabab Mon Sep 17 00:00:00 2001 From: z7zmey Date: Mon, 9 Jul 2018 21:37:07 +0300 Subject: [PATCH 2/2] #49: pretty printer wraps variables by curly braced in double-quoted strings --- printer/printer.go | 31 ++++++++++++++++++++++++++----- printer/printer_test.go | 6 +++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/printer/printer.go b/printer/printer.go index f1a40e1..0c8a7f2 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -553,8 +553,15 @@ func (p *Printer) printScalarEncapsedStringPart(n node.Node) { func (p *Printer) printScalarEncapsed(n node.Node) { io.WriteString(p.w, "\"") - for _, nn := range n.(*scalar.Encapsed).Parts { - p.Print(nn) + for _, part := range n.(*scalar.Encapsed).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 +574,15 @@ func (p *Printer) 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 +1246,14 @@ func (p *Printer) 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/printer_test.go b/printer/printer_test.go index e99f2bc..900dadb 100644 --- a/printer/printer_test.go +++ b/printer/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 := `<<