Skip to content

Commit

Permalink
julefmt: update to latest stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Oct 1, 2024
1 parent 7c28bb0 commit 8f489d0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/comment.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

use "std/jule/lex"
use "std/jule/token"

struct comment {
row: int
Expand All @@ -15,14 +15,14 @@ struct commentMap {
}

impl commentMap {
static fn build(mut &tokens: []&lex::Token): commentMap {
static fn build(mut &tokens: []&token::Token): commentMap {
mut cm := commentMap{
buf: make([]&comment, 0, 1<<8),
}
mut i := 0
for i < len(tokens) {
token := tokens[i]
if token.Id != lex::TokenId.Comment {
if token.Id != token::Id.Comment {
i++
continue
}
Expand Down
94 changes: 47 additions & 47 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use "std/bytes"
use "std/jule/ast"
use "std/jule/lex"
use "std/jule/token"
use "std/jule/types"
use "std/slices"
use "std/strings"
use "std/unicode/utf8"

struct field {
f: &ast::FieldDecl
token: &lex::Token
token: &token::Token
expr: []byte
}

Expand All @@ -28,7 +28,7 @@ struct formatter {
indentStr: str = "\t"

mut i: int
mut buf: strings::StrBuilder
mut buf: strings::Builder
mut f: &ast::AST
mut indent: []byte
mut cm: commentMap
Expand Down Expand Up @@ -238,7 +238,7 @@ impl formatter {
match {
| i == 0:
self.write(" ")
| arg.Kind != lex::TokenKind.RParent && d.Args[i-1].Kind != lex::TokenKind.LParent:
| arg.Kind != token::Kind.RParent && d.Args[i-1].Kind != token::Kind.LParent:
self.write(" ")
}
self.write(arg.Kind)
Expand Down Expand Up @@ -457,7 +457,7 @@ impl formatter {
}
self.write("self")
} else {
if !lex::IsAnonIdent(p.Ident) {
if !token::IsAnonIdent(p.Ident) {
self.write(p.Ident)
self.write(": ")
} else if p.Reference {
Expand Down Expand Up @@ -505,7 +505,7 @@ impl formatter {
self.write("unsafe ")
}
self.write("fn")
if !lex::IsAnonIdent(d.Ident) {
if !token::IsAnonIdent(d.Ident) {
self.write(" ")
self.write(d.Ident)
}
Expand Down Expand Up @@ -671,7 +671,7 @@ impl formatter {
self.write("static ")
} else if d.Constant {
self.write("const ")
} else if d.Setter == nil || d.Setter.Id == lex::TokenId.Eq {
} else if d.Setter == nil || d.Setter.Id == token::Id.Eq {
self.write("let ")
}
}
Expand Down Expand Up @@ -1129,7 +1129,7 @@ impl typeFormatter {
ret
}
if len(r.Idents) == 1 {
if lex::IsAnonIdent(r.Idents[0].Kind) {
if token::IsAnonIdent(r.Idents[0].Kind) {
self.format(r.Kind.Kind)
ret
}
Expand All @@ -1144,7 +1144,7 @@ impl typeFormatter {
self.write("(")
for (i, mut t) in types {
ident := r.Idents[i]
if lex::IsAnonIdent(ident.Kind) {
if token::IsAnonIdent(ident.Kind) {
self.format(t.Kind)
} else {
self.write(ident.Kind)
Expand Down Expand Up @@ -1402,7 +1402,7 @@ impl scopeFormatter {
}

fn singleAssign(&self, mut &a: &ast::AssignSt) {
if lex::IsIgnoreIdent(a.Left[0].Ident) {
if token::IsIgnoreIdent(a.Left[0].Ident) {
self.write("_ ")
} else {
mut expr := a.Left[0].Expr
Expand All @@ -1415,7 +1415,7 @@ impl scopeFormatter {
}

fn multiAssign(&self, mut &a: &ast::AssignSt) {
letKwUsed := a.Setter.Kind == lex::TokenKind.Eq
letKwUsed := a.Setter.Kind == token::Kind.Eq
if a.Declarative && letKwUsed {
self.write("let (")
}
Expand Down Expand Up @@ -1449,7 +1449,7 @@ impl scopeFormatter {

fn assign(&self, mut a: &ast::AssignSt) {
match {
| lex::IsPostfixOp(a.Setter.Id):
| token::IsPostfixOp(a.Setter.Id):
self.postfix(a)
| len(a.Left) == 1 && !a.Declarative:
self.singleAssign(a)
Expand Down Expand Up @@ -2133,37 +2133,37 @@ struct binaryFormatter {

impl binaryFormatter {
// Reports whether operator should take space for formatting.
static fn isOp(op: lex::TokenId): bool {
ret op == lex::TokenId.DblVline ||
op == lex::TokenId.DblAmper ||
op == lex::TokenId.Gt ||
op == lex::TokenId.Lt ||
op == lex::TokenId.LtEq ||
op == lex::TokenId.GtEq ||
op == lex::TokenId.Eqs ||
op == lex::TokenId.NotEq
static fn isOp(op: token::Id): bool {
ret op == token::Id.DblVline ||
op == token::Id.DblAmper ||
op == token::Id.Gt ||
op == token::Id.Lt ||
op == token::Id.LtEq ||
op == token::Id.GtEq ||
op == token::Id.Eqs ||
op == token::Id.NotEq
}

// Reports whether the operator is have high formatting precedence.
// Returns 1 for high precedence, otherwise returns 0.
static fn opPrec(op: lex::TokenId): int {
static fn opPrec(op: token::Id): int {
match op {
| lex::TokenId.Shl
| lex::TokenId.Shr
| lex::TokenId.Star
| lex::TokenId.Solidus
| lex::TokenId.Percent
| lex::TokenId.Amper:
| token::Id.Shl
| token::Id.Shr
| token::Id.Star
| token::Id.Solidus
| token::Id.Percent
| token::Id.Amper:
ret 1
|:
ret 0
}
}

// Reports whether operator zips operands.
static fn isHardZipOp(op: lex::TokenId): bool {
ret op == lex::TokenId.DblVline ||
op == lex::TokenId.DblAmper
static fn isHardZipOp(op: token::Id): bool {
ret op == token::Id.DblVline ||
op == token::Id.DblAmper
}

fn write(&self, s: str) {
Expand Down Expand Up @@ -2350,22 +2350,22 @@ fn isPrimType(&t: &ast::TypeDecl): bool {
match type t.Kind {
| &ast::IdentTypeDecl:
itd := (&ast::IdentTypeDecl)(t.Kind)
ret itd.Ident == types::TypeKind.I8 ||
itd.Ident == types::TypeKind.I16 ||
itd.Ident == types::TypeKind.I32 ||
itd.Ident == types::TypeKind.I64 ||
itd.Ident == types::TypeKind.U8 ||
itd.Ident == types::TypeKind.U16 ||
itd.Ident == types::TypeKind.U32 ||
itd.Ident == types::TypeKind.U64 ||
itd.Ident == types::TypeKind.Int ||
itd.Ident == types::TypeKind.Uint ||
itd.Ident == types::TypeKind.Uintptr ||
itd.Ident == types::TypeKind.F32 ||
itd.Ident == types::TypeKind.F64 ||
itd.Ident == types::TypeKind.Bool ||
itd.Ident == types::TypeKind.Str ||
itd.Ident == types::TypeKind.Any
ret itd.Ident == types::Kind.I8 ||
itd.Ident == types::Kind.I16 ||
itd.Ident == types::Kind.I32 ||
itd.Ident == types::Kind.I64 ||
itd.Ident == types::Kind.U8 ||
itd.Ident == types::Kind.U16 ||
itd.Ident == types::Kind.U32 ||
itd.Ident == types::Kind.U64 ||
itd.Ident == types::Kind.Int ||
itd.Ident == types::Kind.Uint ||
itd.Ident == types::Kind.Uintptr ||
itd.Ident == types::Kind.F32 ||
itd.Ident == types::Kind.F64 ||
itd.Ident == types::Kind.Bool ||
itd.Ident == types::Kind.Str ||
itd.Ident == types::Kind.Any
}
ret false
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.jule
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use "std/env"
use "std/fs"
use "std/fs/path"
use "std/jule/build"
use "std/jule/lex"
use "std/jule/parser"
use "std/jule/sema"
use "std/jule/token"
use "std/strings"

fn formatFile(path: str) {
mut file := lex::NewFileSet(path)
mut file := token::Fileset.New(path)
file.Fill(fs::File.Read(path) else {
outln("error: file could not read: " + path)
ret
})
mut errors := lex::Lex(file, lex::LexMode.Comment)
mut errors := token::Lex(file, token::Mode.Comment)
if len(errors) > 0 {
outln("error: file could not formatted, have error(s): " + path)
ret
Expand Down

0 comments on commit 8f489d0

Please sign in to comment.