From f123803c31cfa066ea99d626b752e49003f21ba5 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Sat, 30 Mar 2024 02:25:56 +0300 Subject: [PATCH] julefmt: format source code with julefmt --- src/comment.jule | 2 +- src/format.jule | 80 ++++++++++++++++++++++++------------------------ src/main.jule | 2 +- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/comment.jule b/src/comment.jule index 257ab7a..176346c 100644 --- a/src/comment.jule +++ b/src/comment.jule @@ -66,4 +66,4 @@ impl CommentMap { self.drop_first() ret c } -} +} \ No newline at end of file diff --git a/src/format.jule b/src/format.jule index f1653e9..378ea3c 100644 --- a/src/format.jule +++ b/src/format.jule @@ -27,7 +27,7 @@ struct RowAlign { struct Formatter { indent_len: int = 4 indent_str: str = " " - + mut i: int mut buf: str mut f: &Ast @@ -96,7 +96,7 @@ impl Formatter { if c == nil || (row != -1 && c.row == row) { break } - if c.row - lrow > 1 { + if c.row-lrow > 1 { self.write("\n") } lrow = c.row @@ -114,7 +114,7 @@ impl Formatter { fn add_global_padding_for_comment(&self, row: int) { let c = self.cm.first(row) - if c != nil && c.row - self.row > 1 { + if c != nil && c.row-self.row > 1 { self.write("\n") } } @@ -184,7 +184,7 @@ impl Formatter { match { | i == 0: self.write(" ") - | arg.kind != TokenKind.RParent && d.args[i - 1].kind != TokenKind.LParent: + | arg.kind != TokenKind.RParent && d.args[i-1].kind != TokenKind.LParent: self.write(" ") } self.write(arg.kind) @@ -196,7 +196,7 @@ impl Formatter { ret } let first = dvs[0] - if first.tag.row - self.write_comments_except(first.tag.row) > 1 { + if first.tag.row-self.write_comments_except(first.tag.row) > 1 { self.write("\n") } for i, d in dvs { @@ -256,7 +256,7 @@ impl Formatter { self.write(",") self.pop_row_comments_by(s.row) self.write("\n") - } else if d.selected.len - i > 1 { + } else if d.selected.len-i > 1 { self.write(", ") } } @@ -271,19 +271,19 @@ impl Formatter { ret } let first = self.f.use_decls[0] - if self.cm.first(first.token.row) == nil && first.token.row - self.row > 1 { + if self.cm.first(first.token.row) == nil && first.token.row-self.row > 1 { self.write("\n") } self.add_global_padding_for_comment(first.token.row) self.row = self.write_comments(first.token.row) - if first.token.row - self.row > 1 { + if first.token.row-self.row > 1 { self.write("\n") } for i, decl in self.f.use_decls { self.row = decl.token.row self.write_comments(self.row) self.use_decl(decl) - if self.f.use_decls.len - i > 1 { + if self.f.use_decls.len-i > 1 { self.write("\n") } } @@ -296,7 +296,7 @@ impl Formatter { self.write("[") for i, t in g { self.write(t.ident) - if i + 1 < g.len { + if i+1 < g.len { self.write(", ") } } @@ -394,8 +394,8 @@ impl Formatter { } self.format_type(p.kind) } - if i + 1 < f.params.len { - if f.params[i + 1].token.row != p.token.row { + if i+1 < f.params.len { + if f.params[i+1].token.row != p.token.row { self.pop_row_comments(p.token.row) } self.write(",") @@ -483,7 +483,7 @@ impl Formatter { let mut flds = make([]&Field, 0, fields.len) for (_, mut f) in fields { flds = append(flds, &Field{ - f: f, + f: f, token: f.token, }) } @@ -586,7 +586,7 @@ impl Formatter { } if d.statically { self.write("static ") - } else if d.constant { + } else if d.constant { self.write("const ") } else { self.write("let ") @@ -620,8 +620,8 @@ impl Formatter { let mut field_max = 0 let n = self.buf.len for i < fields.len { - let mut decl = fields[i] - if self.row != -1 && decl.token.row - 1 != self.row { + let mut decl = fields[i] + if self.row != -1 && decl.token.row-1 != self.row { break } self.row = decl.token.row @@ -652,7 +652,7 @@ impl Formatter { let line = self.buf[n:] lines = append(lines, line) let diff = utf8::rune_count_str(line) - if max < diff && f.f.token.row == rows[j - start] { + if max < diff && f.f.token.row == rows[j-start] { max = diff } self.buf = self.buf[:n] @@ -662,7 +662,7 @@ impl Formatter { let row = rows[k] self.write_comments_except(row) self.write(line) - self.pop_row_comments_by_f(row, -1, fn (c: &Comment) { + self.pop_row_comments_by_f(row, -1, fn(c: &Comment) { self.write(strings::repeat(" ", padding_abs(max - line.len) + 1)) self.write_comment(c) }) @@ -690,7 +690,7 @@ impl Formatter { let n = self.buf.len loop: for i < nodes.len { - let mut decl: T = nil + let mut decl: T = nil match type Node { | &ast::EnumItemDecl | &ast::VarDecl: @@ -704,7 +704,7 @@ impl Formatter { break loop } } - if !all && self.row != -1 && decl.token.row - 1 != self.row { + if !all && self.row != -1 && decl.token.row-1 != self.row { break loop } self.row = decl.token.row @@ -789,7 +789,7 @@ impl Formatter { mi++ } if statics != -1 { - if mi > 0 || self.buf[self.buf.len - 1] != '\n' { + if mi > 0 || self.buf[self.buf.len-1] != '\n' { self.write("\n") } let mut vars = d.statics[statics:si] @@ -806,25 +806,25 @@ impl Formatter { fn node(&self, mut &node: ast::Node) { match type node.data { | &ast::TypeAliasDecl: - if node.token.row - self.write_comments_except(node.token.row) > 1 { + if node.token.row-self.write_comments_except(node.token.row) > 1 { self.write("\n") } self.group_decls[&ast::TypeAliasDecl, ast::Node](self.f.nodes, self.i) ret | &ast::VarDecl: - if node.token.row - self.write_comments_except(node.token.row) > 1 { + if node.token.row-self.write_comments_except(node.token.row) > 1 { self.write("\n") } self.group_decls[&ast::VarDecl, ast::Node](self.f.nodes, self.i) ret | &ast::FnDecl: - if node.token.row - self.write_comments_except(node.token.row) > 1 { + if node.token.row-self.write_comments_except(node.token.row) > 1 { self.write("\n") } self.fn_decl((&ast::FnDecl)(node.data)) ret } - if node.token.row - self.write_comments(node.token.row) > 1 { + if node.token.row-self.write_comments(node.token.row) > 1 { self.write("\n") } match type node.data { @@ -882,7 +882,7 @@ impl TypeFormatter { self.write("[") for (i, mut t) in g { self.format(t.kind) - if i + 1 < g.len { + if i+1 < g.len { self.write(", ") } } @@ -971,7 +971,7 @@ impl TypeFormatter { self.write(": ") self.format(t.kind) } - if types.len - i > 1 { + if types.len-i > 1 { self.write(", ") } } @@ -1226,7 +1226,7 @@ impl ScopeFormatter { // Do not write range parentheses for expression parts. // Expression formatter will add. self.fmt.format_expr(l.expr) - if a.left.len - i > 1 { + if a.left.len-i > 1 { self.write(", ") } } @@ -1301,10 +1301,10 @@ impl ScopeFormatter { z = self.fmt.row self.fmt.add_global_padding_for_comment(stmt.token.row - 1) // Use -1 row for avoid inline comments. self.fmt.row = self.fmt.write_comments_except(stmt.token.row) - if stmt.token.row - self.fmt.row == 0 { + if stmt.token.row-self.fmt.row == 0 { self.fmt.row = z } - if stmt.token.row - self.fmt.row > 1 { + if stmt.token.row-self.fmt.row > 1 { self.write("\n") } z = i @@ -1385,7 +1385,7 @@ impl ExprFormatter { fn tuple(&self, mut tup: &ast::TupleExpr) { for (i, mut expr) in tup.expr { self.format(expr) - if i + 1 < tup.expr.len { + if i+1 < tup.expr.len { self.write(", ") } } @@ -1542,7 +1542,7 @@ impl ExprFormatter { self.fmt.pop_row_comments_by_c(expr.token.row, expr.token.column) if newline { self.write(",") - if diff < 2 || lit.exprs[i + 1].token.row != self.fmt.row { + if diff < 2 || lit.exprs[i+1].token.row != self.fmt.row { self.fmt.pop_row_comments(self.fmt.row) } self.write("\n") @@ -1596,7 +1596,7 @@ impl ExprFormatter { self.format(expr) row = expr.token.row col = expr.end.column - if lined || lit.exprs.len - i > 1 { + if lined || lit.exprs.len-i > 1 { self.write(",") } } @@ -1634,13 +1634,13 @@ impl ExprFormatter { } self.fmt.write_comment(c) }) - if exprs.len - i > 1 { + if exprs.len-i > 1 { self.write("\n") self.write(self.fmt.indent) } } self.fmt.done_indent() - if self.fmt.buf[self.fmt.buf.len - 1] == '\n' { + if self.fmt.buf[self.fmt.buf.len-1] == '\n' { self.write(self.fmt.indent) } else if lined { self.write("\n") @@ -1750,10 +1750,10 @@ impl ExprFormatter { } struct BinaryFormatter { - mut ef: &ExprFormatter - mut zip: bool - mut op: bool - mut bin: &ast::BinopExpr + mut ef: &ExprFormatter + mut zip: bool + mut op: bool + mut bin: &ast::BinopExpr mut weak: bool } @@ -1890,4 +1890,4 @@ fn is_prim_type(&t: &ast::TypeDecl): bool { ret (&ast::IdentTypeDecl)(t.kind).is_prim() } ret false -} +} \ No newline at end of file diff --git a/src/main.jule b/src/main.jule index 0d84c9a..3154d28 100644 --- a/src/main.jule +++ b/src/main.jule @@ -65,4 +65,4 @@ fn main() { ret } parse_package(args[1]) -} +} \ No newline at end of file