package printer import ( "strings" "olexsmir.xyz/clerk/journal/ast" ) func (p *printer) writeIncludeDirective(i *ast.IncludeDirective) { p.buf.WriteString("include ") p.buf.WriteString(quoteString(i.Path)) p.writeInlineComment(i.Comment) } func (p *printer) writeAccountDirective(a *ast.AccountDirective) { p.buf.WriteString("account ") p.buf.WriteString(a.Account.Name) p.writeInlineComment(a.Comment) } func (p *printer) writeCommodityDirective(c *ast.CommodityDirective) { p.buf.WriteString("commodity ") p.buf.WriteString(c.Commodity) p.writeInlineComment(c.Comment) } func (p *printer) writeAliasDirective(a *ast.AliasDirective) { p.buf.WriteString("alias ") p.buf.WriteString(a.From) p.buf.WriteString(" = ") p.buf.WriteString(a.To) p.writeInlineComment(a.Comment) } func (p *printer) writePayeeDirective(pd *ast.PayeeDirective) { p.buf.WriteString("payee ") p.buf.WriteString(quoteString(pd.Name)) p.writeInlineComment(pd.Comment) } func (p *printer) writeTagDirective(t *ast.TagDirective) { p.buf.WriteString("tag ") p.buf.WriteString(quoteString(t.Name)) p.writeInlineComment(t.Comment) } func (p *printer) writeYearDirective(y *ast.YearDirective) { p.buf.WriteString("year ") p.writeInt(y.Year, 4) p.writeInlineComment(y.Comment) } func (p *printer) writeDecimalMarkDirective(d *ast.DecimalMarkDirective) { p.buf.WriteString("decimal ") p.buf.WriteByte(d.Mark) p.writeInlineComment(d.Comment) } func (p *printer) writeDefaultCommodityDirective(d *ast.DefaultCommodityDirective) { p.buf.WriteString("D ") p.writeAmount(&d.Amount, p.cfg.CommodityPos) p.writeInlineComment(d.Comment) } func (p *printer) writeConversionDirective(c *ast.ConversionDirective) { p.buf.WriteString("C ") p.writeAmount(&c.From, CommodityAfter) // TODO: support CommodityBefore p.buf.WriteString(" = ") p.writeAmount(&c.To, CommodityAfter) // TODO: support CommodityBefore p.writeInlineComment(c.Comment) } func (p *printer) writeMarketPriceDirective(m *ast.MarketPriceDirective) { p.buf.WriteString("P ") p.writeDate(m.DateTime.Date) if m.DateTime.Time != nil { p.buf.WriteByte(' ') p.writeInt(m.DateTime.Time.Hour, 2) p.buf.WriteByte(':') p.writeInt(m.DateTime.Time.Minute, 2) p.buf.WriteByte(':') p.writeInt(m.DateTime.Time.Second, 2) } p.buf.WriteByte(' ') p.buf.WriteString(m.Commodity) p.buf.WriteByte(' ') p.writeAmount(&m.Amount, p.cfg.CommodityPos) p.writeInlineComment(m.Comment) } func (p *printer) writeCommentBlockDirective(cb *ast.CommentBlockDirective) { p.buf.WriteString("comment") if cb.Header != "" { p.buf.WriteByte(' ') p.buf.WriteString(cb.Header) } p.buf.WriteByte('\n') if cb.Content != "" { p.buf.WriteString(cb.Content) if !strings.HasSuffix(cb.Content, "\n") { p.buf.WriteByte('\n') } } p.buf.WriteString("end") if cb.Header != "" { p.buf.WriteByte(' ') p.buf.WriteString(cb.Header) } } func (p *printer) writeApplyDirective(a *ast.ApplyDirective) { p.buf.WriteString("apply ") p.buf.WriteString(a.Expr) p.writeInlineComment(a.Comment) } func (p *printer) writeEndDirective(e *ast.EndDirective) { p.buf.WriteString("end") if e.Expr != "" { p.buf.WriteByte(' ') p.buf.WriteString(e.Expr) } p.writeInlineComment(e.Comment) }