Skip to content

Commit cd69304

Browse files
committed
Use + instead cat in printer
1 parent fc60417 commit cd69304

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

compiler/AstPrinter.fir

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
Expr.pprint(self): Doc
22
match self:
33
Expr.Var(VarExpr(id, tyArgs)) | Expr.Constr(ConstrExpr(id, tyArgs)):
4-
Doc.str(id.name).cat(_ppTyArgs(tyArgs))
4+
Doc.str(id.name) + _ppTyArgs(tyArgs)
55

66
Expr.ConstrSelect(ConstrSelectExpr(ty, constr, tyArgs)):
7-
Doc.str(ty.name).cat(Doc.char('.')).cat(Doc.str(constr.name)).cat(_ppTyArgs(tyArgs))
7+
Doc.str(ty.name) + Doc.char('.') + Doc.str(constr.name) + _ppTyArgs(tyArgs)
88

99
Expr.FieldSelect(FieldSelectExpr(object, field)):
1010
let addParens = _needsParens(object.node)
1111
let doc = object.node.pprint()
1212
if addParens:
1313
doc = parens(doc)
14-
doc.cat(Doc.char('.')).cat(Doc.str(field.name))
14+
doc + Doc.char('.') + Doc.str(field.name)
1515

1616
Expr.MethodSelect(MethodSelectExpr(object, method, ..)):
1717
# TODO: Print all of the details.
1818
let addParens = _needsParens(object.node)
1919
let doc = object.node.pprint()
2020
if addParens:
2121
doc = parens(doc)
22-
doc.cat(Doc.char('.')).cat(Doc.str(method.name))
22+
doc + Doc.char('.') + Doc.str(method.name)
2323

2424
Expr.AssocFnSelect(AssocFnSelectExpr(ty, member, tyArgs)):
25-
Doc.str(ty.name).cat(Doc.char('.')).cat(Doc.str(member.name)).cat(_ppTyArgs(tyArgs))
25+
Doc.str(ty.name) + Doc.char('.') + Doc.str(member.name) + _ppTyArgs(tyArgs)
2626

2727
Expr.Call(CallExpr(fun, args)):
2828
let addParens = _needsParens(fun.node)
2929
let doc = fun.node.pprint()
3030
if addParens:
3131
doc = parens(doc)
32-
doc.cat(parens(interleave(args.iter().map(CallArg.pprint), Doc.str(", "))))
32+
doc + parens(interleave(args.iter().map(CallArg.pprint), Doc.str(", ")))
3333

3434
Expr.Int(IntExpr(text, ..)):
3535
# TODO: Print all of the details
@@ -41,14 +41,14 @@ Expr.pprint(self): Doc
4141
match part:
4242
StrPart.Str(str):
4343
# TODO: Escapes
44-
doc = doc.cat(Doc.str(str))
44+
doc += Doc.str(str)
4545
StrPart.Expr(expr):
46-
doc = doc.cat(Doc.char('`')).cat(expr.node.pprint()).cat(Doc.char('`'))
46+
doc += Doc.char('`') + expr.node.pprint() + Doc.char('`')
4747
doc
4848

4949
Expr.Char(char):
5050
# TODO: Escapes
51-
Doc.char('\'').cat(Doc.char(char)).cat(Doc.char('\''))
51+
Doc.char('\'') + Doc.char(char) + Doc.char('\'')
5252

5353
Expr.Self:
5454
Doc.str("self")
@@ -57,40 +57,40 @@ Expr.pprint(self): Doc
5757
# TODO: Precedence and parens
5858
# TODO: Operator string
5959
parens(left.node.pprint()) \
60-
.cat(Doc.blank(1)) \
61-
.cat(Doc.str(op.toStr())) \
62-
.cat(Doc.blank(1)) \
63-
.cat(parens(right.node.pprint()))
60+
+ Doc.blank(1) \
61+
+ Doc.str(op.toStr()) \
62+
+ Doc.blank(1) \
63+
+ parens(right.node.pprint())
6464

6565
Expr.UnOp(UnOpExpr(op, expr)):
6666
let opChar = match op:
6767
UnOp.Not: '!'
6868
UnOp.Neg: '-'
69-
Doc.char(opChar).cat(expr.node.pprint())
69+
Doc.char(opChar) + expr.node.pprint()
7070

7171
Expr.Record(fields):
7272
_ppParenNamedFields(fields)
7373

7474
Expr.Variant(VariantExpr(id, args)):
75-
brackets(Doc.str(id.name).cat(_ppParenNamedFields(args)))
75+
brackets(Doc.str(id.name) + _ppParenNamedFields(args))
7676

7777
Expr.Return(expr):
78-
Doc.str("return ").cat(expr.node.pprint())
78+
Doc.str("return ") + expr.node.pprint()
7979

8080
Expr.Match(MatchExpr(scrutinee, alts)):
81-
Doc.str("match ").cat(scrutinee.node.pprint()).cat(Doc.char(':')).cat(Doc.hardLine()) \
82-
.cat(interleave(alts.iter().map(_ppAlt), Doc.hardLine())) \
83-
.cat(Doc.hardLine())
81+
Doc.str("match ") + scrutinee.node.pprint() + Doc.char(':') + Doc.hardLine() \
82+
+ interleave(alts.iter().map(_ppAlt), Doc.hardLine()) \
83+
+ Doc.hardLine()
8484

8585
Expr.If(IfExpr(branches, else_branch)):
8686
let doc = _ppIfBranch("if", branches.get(0).guard, branches.get(0).body)
8787
for branch: (guard: L[Expr], body: Vec[L[Stmt]]) in branches.iter().skip(1):
88-
doc = doc.cat(_ppIfBranch("elif", branch.guard, branch.body))
88+
doc += _ppIfBranch("elif", branch.guard, branch.body)
8989
match else_branch:
9090
Option.None: ()
9191
Option.Some(stmts):
9292
for stmt: L[Stmt] in stmts.iter():
93-
doc = doc.cat(stmt.node.pprint()).cat(Doc.hardLine())
93+
doc += stmt.node.pprint() + Doc.hardLine()
9494
doc
9595

9696
Expr.Fn_(FnExpr(sig, body, ..)):
@@ -99,7 +99,7 @@ Expr.pprint(self): Doc
9999
Type.pprint(self): Doc
100100
match self:
101101
Type.Named(NamedType(name, args)):
102-
Doc.str(name.name).cat(_ppTyArgs(args))
102+
Doc.str(name.name) + _ppTyArgs(args)
103103

104104
Type.Var(var_):
105105
Doc.str(var_.name)
@@ -112,7 +112,7 @@ Type.pprint(self): Doc
112112
if fields.len() == 0:
113113
doc = Doc.str("..")
114114
else:
115-
doc = doc.cat(Doc.str(", .."))
115+
doc += Doc.str(", ..")
116116
parens(doc)
117117

118118
Type.Variant(alts, extension): panic("")
@@ -145,23 +145,23 @@ _ppNamedList(namedList: Vec[Named[L[a]]], ppItem: Fn(a): exn Doc): exn Doc
145145
_ppNamed(named: Named[L[a]], ppItem: Fn(a): exn Doc): exn Doc
146146
let doc = match named.name:
147147
Option.Some(name):
148-
Doc.str(name.name).cat(Doc.str(" = "))
148+
Doc.str(name.name) + Doc.str(" = ")
149149
Option.None:
150150
Doc.empty()
151-
doc.cat(ppItem(named.node.node))
151+
doc + ppItem(named.node.node)
152152

153153
_ppAlt(alt: Alt): Doc
154154
panic("TODO")
155155

156156
_ppIfBranch(prefix: Str, guard: L[Expr], body: Vec[L[Stmt]]): Doc
157157
let doc = Doc.str(prefix) \
158-
.cat(Doc.break_(1)) \
159-
.cat(guard.node.pprint()) \
160-
.cat(Doc.char(':')) \
161-
.cat(Doc.hardLine())
158+
+ Doc.break_(1) \
159+
+ guard.node.pprint() \
160+
+ Doc.char(':') \
161+
+ Doc.hardLine()
162162

163163
for stmt: L[Stmt] in body.iter():
164-
doc = doc.cat(stmt.node.pprint()).cat(Doc.hardLine())
164+
doc += stmt.node.pprint() + Doc.hardLine()
165165

166166
doc
167167

@@ -181,12 +181,12 @@ interleave[Iterator[iter, Doc, exn]](iter: iter, sep: Doc): exn Doc
181181
Option.Some(doc): doc
182182

183183
for item: Doc in iter:
184-
doc = doc.cat(sep).cat(item)
184+
doc += sep + item
185185

186186
doc
187187

188188
parens(doc: Doc): Doc
189-
Doc.char('(').cat(doc).cat(Doc.char(')'))
189+
Doc.char('(') + doc + Doc.char(')')
190190

191191
brackets(doc: Doc): Doc
192-
Doc.char('[').cat(doc).cat(Doc.char(']'))
192+
Doc.char('[') + doc + Doc.char(']')

0 commit comments

Comments
 (0)