Skip to content

Commit

Permalink
Refactor the writer functionality into a package (#22)
Browse files Browse the repository at this point in the history
* Refactoring the writer into a package

* Fixing things up and trimming some fat
  • Loading branch information
UnstoppableMango authored Feb 1, 2025
1 parent 8ce4974 commit d659ab8
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 570 deletions.
3 changes: 2 additions & 1 deletion e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/unmango/go-make"
"github.com/unmango/go-make/printer"
"github.com/unmango/go-make/token"
"github.com/unmango/go-make/writer"
)

//go:embed testdata
Expand Down Expand Up @@ -58,7 +59,7 @@ var _ = Describe("E2E", func() {
Expect(err).NotTo(HaveOccurred())

buf := &bytes.Buffer{}
w := make.NewWriter(buf)
w := writer.New(buf)

Expect(printer.Fprint(w, f)).To(BeNumerically(">", 0))
Expect(buf.String()).To(Equal(input))
Expand Down
12 changes: 11 additions & 1 deletion printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (p *printer) recipeList(l []*ast.Recipe) {
}

func (p *printer) rule(r *ast.Rule) {
if r == nil {
return
}

p.targetList(r.Targets)
fillSpace(p, r.Colon)
p.tok(p.posFor(r.Colon), token.COLON)
Expand All @@ -118,6 +122,10 @@ func (p *printer) rule(r *ast.Rule) {
}

func (p *printer) variable(v *ast.Variable) {
if v == nil {
return
}

p.expr(v.Name)
fillSpace(p, v.OpPos)
p.tok(p.posFor(v.OpPos), v.Op)
Expand All @@ -143,7 +151,9 @@ func (p *printer) declList(l []ast.Decl) {
}

func (p *printer) file(file *ast.File) {
p.declList(file.Decls)
if file != nil {
p.declList(file.Decls)
}
}

func (p *printer) printNode(node any) error {
Expand Down
238 changes: 0 additions & 238 deletions write.go

This file was deleted.

Loading

0 comments on commit d659ab8

Please sign in to comment.