From 0abe99274bef2ef182cd786290e12f3d7915be0d Mon Sep 17 00:00:00 2001 From: z7zmey Date: Fri, 6 Apr 2018 00:59:22 +0300 Subject: [PATCH] pretty printer: print file --- printer/printer.go | 21 +++++++++++++++++ printer/printer_test.go | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/printer/printer.go b/printer/printer.go index fcd4690..231c855 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -30,6 +30,27 @@ func NewPrinter(w io.Writer, indentStr string) *Printer { } } +func (p *Printer) PrintFile(n *stmt.StmtList) { + if len(n.Stmts) > 0 { + firstStmt := n.Stmts[0] + n.Stmts = n.Stmts[1:] + + switch fs := firstStmt.(type) { + case *stmt.InlineHtml: + io.WriteString(p.w, fs.Value) + io.WriteString(p.w, "HTML"}, + &stmt.Expression{ + Expr: &scalar.Heredoc{ + Label: "\"LBL\"", + Parts: []node.Node{ + &scalar.EncapsedStringPart{Value: "hello world\n"}, + }, + }, + }, + }, + }) + + expected := `
HTML