Skip to content

Commit 2a9e80c

Browse files
committed
syntax: simplify spacedString
1 parent 3db974b commit 2a9e80c

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

syntax/printer.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ func (p *printer) bslashNewl() {
131131
p.incLine()
132132
}
133133

134-
func (p *printer) spacedString(s string, spaceAfter bool) {
134+
func (p *printer) spacedString(s string) {
135135
if p.wantSpace {
136136
p.WriteByte(' ')
137137
}
138138
p.WriteString(s)
139-
p.wantSpace = spaceAfter
139+
p.wantSpace = true
140140
}
141141

142142
func (p *printer) semiOrNewl(s string, pos Pos) {
@@ -376,7 +376,7 @@ func (p *printer) loop(loop Loop) {
376376
case *WordIter:
377377
p.WriteString(x.Name.Value)
378378
if len(x.List) > 0 {
379-
p.spacedString(" in", true)
379+
p.spacedString(" in")
380380
p.wordJoin(x.List, true)
381381
}
382382
case *CStyleLoop:
@@ -506,7 +506,7 @@ func (p *printer) wordJoin(ws []*Word, backslash bool) {
506506

507507
func (p *printer) stmt(s *Stmt) {
508508
if s.Negated {
509-
p.spacedString("!", true)
509+
p.spacedString("!")
510510
}
511511
p.assigns(s.Assigns)
512512
var startRedirs int
@@ -585,7 +585,7 @@ func (p *printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
585585
p.nestedStmts(x.Stmts, x.Rbrace)
586586
p.semiRsrv("}", x.Rbrace, true)
587587
case *IfClause:
588-
p.spacedString("if", true)
588+
p.spacedString("if")
589589
p.nestedStmts(x.CondStmts, 0)
590590
p.semiOrNewl("then", x.Then)
591591
p.nestedStmts(x.ThenStmts, 0)
@@ -608,13 +608,13 @@ func (p *printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
608608
p.nestedStmts(x.Stmts, x.Rparen)
609609
p.sepTok(")", x.Rparen)
610610
case *WhileClause:
611-
p.spacedString("while", true)
611+
p.spacedString("while")
612612
p.nestedStmts(x.CondStmts, 0)
613613
p.semiOrNewl("do", x.Do)
614614
p.nestedStmts(x.DoStmts, 0)
615615
p.semiRsrv("done", x.Done, true)
616616
case *ForClause:
617-
p.spacedString("for ", false)
617+
p.WriteString("for ")
618618
p.loop(x.Loop)
619619
p.semiOrNewl("do", x.Do)
620620
p.nestedStmts(x.DoStmts, 0)
@@ -651,7 +651,7 @@ func (p *printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
651651
p.bslashNewl()
652652
p.indent()
653653
}
654-
p.spacedString(x.Op.String(), true)
654+
p.spacedString(x.Op.String())
655655
p.incLines(x.Y.Pos())
656656
p.stmt(x.Y)
657657
if indent {
@@ -667,15 +667,15 @@ func (p *printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
667667
p.incLines(x.Body.Pos())
668668
p.stmt(x.Body)
669669
case *CaseClause:
670-
p.spacedString("case ", false)
670+
p.WriteString("case ")
671671
p.word(x.Word)
672672
p.WriteString(" in")
673673
p.incLevel()
674674
for _, pl := range x.List {
675675
p.commentsAndSeparate(pl.Patterns[0].Pos())
676676
for i, w := range pl.Patterns {
677677
if i > 0 {
678-
p.spacedString("|", true)
678+
p.spacedString("|")
679679
}
680680
if p.wantSpace {
681681
p.WriteByte(' ')
@@ -691,7 +691,7 @@ func (p *printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
691691
p.commentsUpTo(pl.OpPos)
692692
p.newlines(pl.OpPos)
693693
}
694-
p.spacedString(pl.Op.String(), true)
694+
p.spacedString(pl.Op.String())
695695
p.incLines(pl.OpPos)
696696
p.level--
697697
if sep || pl.OpPos == x.Esac {
@@ -701,7 +701,7 @@ func (p *printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
701701
p.decLevel()
702702
p.semiRsrv("esac", x.Esac, len(x.List) == 0)
703703
case *UntilClause:
704-
p.spacedString("until", true)
704+
p.spacedString("until")
705705
p.nestedStmts(x.CondStmts, 0)
706706
p.semiOrNewl("do", x.Do)
707707
p.nestedStmts(x.DoStmts, 0)
@@ -711,34 +711,34 @@ func (p *printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
711711
p.arithmExpr(x.X, false)
712712
p.WriteString("))")
713713
case *TestClause:
714-
p.spacedString("[[ ", false)
714+
p.WriteString("[[ ")
715715
p.testExpr(x.X)
716-
p.spacedString("]]", true)
716+
p.spacedString("]]")
717717
case *DeclClause:
718718
name := x.Variant
719719
if name == "" {
720720
name = "declare"
721721
}
722-
p.spacedString(name, true)
722+
p.spacedString(name)
723723
for _, w := range x.Opts {
724724
p.WriteByte(' ')
725725
p.word(w)
726726
}
727727
p.assigns(x.Assigns)
728728
case *EvalClause:
729-
p.spacedString("eval", true)
729+
p.spacedString("eval")
730730
if x.Stmt != nil {
731731
p.stmt(x.Stmt)
732732
}
733733
case *CoprocClause:
734-
p.spacedString("coproc", true)
734+
p.spacedString("coproc")
735735
if x.Name != nil {
736736
p.WriteByte(' ')
737737
p.WriteString(x.Name.Value)
738738
}
739739
p.stmt(x.Stmt)
740740
case *LetClause:
741-
p.spacedString("let", true)
741+
p.spacedString("let")
742742
for _, n := range x.Exprs {
743743
p.WriteByte(' ')
744744
p.arithmExpr(n, true)

0 commit comments

Comments
 (0)