Skip to content

Commit

Permalink
julefmt: format source code with julefmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 29, 2024
1 parent 447c070 commit f123803
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/comment.jule
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ impl CommentMap {
self.drop_first()
ret c
}
}
}
80 changes: 40 additions & 40 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RowAlign {
struct Formatter {
indent_len: int = 4
indent_str: str = " "

mut i: int
mut buf: str
mut f: &Ast
Expand Down Expand Up @@ -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
Expand All @@ -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")
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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(", ")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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(", ")
}
}
Expand Down Expand Up @@ -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(",")
Expand Down Expand Up @@ -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,
})
}
Expand Down Expand Up @@ -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 ")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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)
})
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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 {
Expand Down Expand Up @@ -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(", ")
}
}
Expand Down Expand Up @@ -971,7 +971,7 @@ impl TypeFormatter {
self.write(": ")
self.format(t.kind)
}
if types.len - i > 1 {
if types.len-i > 1 {
self.write(", ")
}
}
Expand Down Expand Up @@ -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(", ")
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(", ")
}
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(",")
}
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1890,4 +1890,4 @@ fn is_prim_type(&t: &ast::TypeDecl): bool {
ret (&ast::IdentTypeDecl)(t.kind).is_prim()
}
ret false
}
}
2 changes: 1 addition & 1 deletion src/main.jule
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ fn main() {
ret
}
parse_package(args[1])
}
}

0 comments on commit f123803

Please sign in to comment.