From 16fbfd04186a637ee9aba73ce76e9affa9ea3c5b Mon Sep 17 00:00:00 2001 From: ikarus Date: Mon, 6 May 2024 09:25:22 +0100 Subject: [PATCH 1/3] ignore empty files and errors on no package --- core/odin/parser/parse_files.odin | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/odin/parser/parse_files.odin b/core/odin/parser/parse_files.odin index 6452faf4c..9911e3a5f 100644 --- a/core/odin/parser/parse_files.odin +++ b/core/odin/parser/parse_files.odin @@ -6,6 +6,7 @@ import "core:path/filepath" import "core:fmt" import "core:os" import "core:slice" +import "core:strings" collect_package :: proc(path: string) -> (pkg: ^ast.Package, success: bool) { NO_POS :: tokenizer.Pos{} @@ -32,11 +33,17 @@ collect_package :: proc(path: string) -> (pkg: ^ast.Package, success: bool) { if !ok { return } + src, ok = os.read_entire_file(fullpath) if !ok { delete(fullpath) return } + if strings.trim_space(string(src)) == "" { + delete(fullpath) + continue + } + file := ast.new(ast.File, NO_POS, NO_POS) file.pkg = pkg file.src = string(src) @@ -69,7 +76,9 @@ parse_package :: proc(pkg: ^ast.Package, p: ^Parser = nil) -> bool { if !parse_file(p, file) { ok = false } - if pkg.name == "" { + if file.pkg_decl == nil { + error(p, p.curr_tok.pos, "Expected pacakge declaration at the start of the file") + } else if pkg.name == "" { pkg.name = file.pkg_decl.name } else if pkg.name != file.pkg_decl.name { error(p, file.pkg_decl.pos, "different package name, expected '%s', got '%s'", pkg.name, file.pkg_decl.name) From 60b6c798a5eaea46660c3158a4ebfbf9ae67d7ed Mon Sep 17 00:00:00 2001 From: ikarus Date: Wed, 8 May 2024 09:07:53 +0100 Subject: [PATCH 2/3] tabs for indentation --- core/odin/parser/parse_files.odin | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/odin/parser/parse_files.odin b/core/odin/parser/parse_files.odin index 9911e3a5f..c1798778b 100644 --- a/core/odin/parser/parse_files.odin +++ b/core/odin/parser/parse_files.odin @@ -39,10 +39,10 @@ collect_package :: proc(path: string) -> (pkg: ^ast.Package, success: bool) { delete(fullpath) return } - if strings.trim_space(string(src)) == "" { - delete(fullpath) - continue - } + if strings.trim_space(string(src)) == "" { + delete(fullpath) + continue + } file := ast.new(ast.File, NO_POS, NO_POS) file.pkg = pkg @@ -76,9 +76,9 @@ parse_package :: proc(pkg: ^ast.Package, p: ^Parser = nil) -> bool { if !parse_file(p, file) { ok = false } - if file.pkg_decl == nil { - error(p, p.curr_tok.pos, "Expected pacakge declaration at the start of the file") - } else if pkg.name == "" { + if file.pkg_decl == nil { + error(p, p.curr_tok.pos, "Expected pacakge declaration at the start of the file") + } else if pkg.name == "" { pkg.name = file.pkg_decl.name } else if pkg.name != file.pkg_decl.name { error(p, file.pkg_decl.pos, "different package name, expected '%s', got '%s'", pkg.name, file.pkg_decl.name) From 3add85e7a725a3b6da0f7ac10df24cfb51591473 Mon Sep 17 00:00:00 2001 From: ikarus Date: Fri, 10 May 2024 14:51:09 +0100 Subject: [PATCH 3/3] fix typo & free memory when skipping empty files --- core/odin/parser/parse_files.odin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/odin/parser/parse_files.odin b/core/odin/parser/parse_files.odin index c1798778b..5f455c749 100644 --- a/core/odin/parser/parse_files.odin +++ b/core/odin/parser/parse_files.odin @@ -41,6 +41,7 @@ collect_package :: proc(path: string) -> (pkg: ^ast.Package, success: bool) { } if strings.trim_space(string(src)) == "" { delete(fullpath) + delete(src) continue } @@ -77,7 +78,7 @@ parse_package :: proc(pkg: ^ast.Package, p: ^Parser = nil) -> bool { ok = false } if file.pkg_decl == nil { - error(p, p.curr_tok.pos, "Expected pacakge declaration at the start of the file") + error(p, p.curr_tok.pos, "Expected a package declaration at the start of the file") } else if pkg.name == "" { pkg.name = file.pkg_decl.name } else if pkg.name != file.pkg_decl.name {