aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorikarus <ngocnguyen9995@gmail.com>2024-05-06 09:25:22 +0100
committerikarus <ngocnguyen9995@gmail.com>2024-05-06 09:25:22 +0100
commit16fbfd04186a637ee9aba73ce76e9affa9ea3c5b (patch)
tree5b73b1e762a41b56dba7550737b663ca49b705b5
parent15f7148eae89a36696916e15ed4c83fb7fed01c5 (diff)
ignore empty files and errors on no package
-rw-r--r--core/odin/parser/parse_files.odin11
1 files changed, 10 insertions, 1 deletions
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)