Skip to content

Commit

Permalink
julefmt: add formatting support for return types
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 28, 2024
1 parent d1e741d commit 0aa98d9
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ impl Formatter {
}
}
self.write(")")
if d.result != nil {
self.write(": ")
self.tf.result(d.result)
}
if d.scope != nil {
self.write(" ")
let unsafety = d.unsafety
Expand Down Expand Up @@ -806,7 +810,6 @@ impl TypeFormatter {
fn write(self, s: str) {
self.fmt.buf += s
}

fn generics(self, mut g: []&ast::TypeDecl) {
if g.len == 0 {
ret
Expand Down Expand Up @@ -875,6 +878,42 @@ impl TypeFormatter {
self.write("]")
}

fn result(self, mut r: &ast::RetTypeDecl) {
if r.idents.len == 0 {
self.format(r.kind.kind)
ret
}
if r.idents.len == 1 {
if lex::is_ignore_ident(r.idents[0].kind) ||
lex::is_anon_ident(r.idents[0].kind) {
self.format(r.kind.kind)
ret
}
self.write("(")
self.write(r.idents[0].kind)
self.write(": ")
self.format(r.kind.kind)
self.write(")")
}
let mut types = (&ast::TupleTypeDecl)(r.kind.kind).types
self.write("(")
for (i, mut t) in types {
let ident = r.idents[i]
if lex::is_ignore_ident(ident.kind) ||
lex::is_anon_ident(ident.kind) {
self.format(t.kind)
} else {
self.write(ident.kind)
self.write(": ")
self.format(t.kind)
}
if types.len - i > 1 {
self.write(", ")
}
}
self.write(")")
}

fn format(self, mut &kind: any) {
match type kind {
| &ast::IdentTypeDecl:
Expand Down

0 comments on commit 0aa98d9

Please sign in to comment.