Skip to content

Commit 03f52dd

Browse files
committed
sema: fix parsing of the stdlib module
1 parent 68dac13 commit 03f52dd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

std/jule/importer/importer.jule

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ impl sema::Importer for importer {
7676
if len(newModPath) == 0 {
7777
self.mod = nil
7878
} else if self.mod == nil || newModPath != self.mod.Path {
79-
mut newMod, mut errs := mod::ParseFile(newModPath)
79+
isStd := newModPath == build::ModStdlib().Path
80+
mut newMod, mut errs := mod::ParseFile(newModPath, mod::ParseOptions{
81+
AllowStd: isStd,
82+
})
8083
if len(errs) != 0 {
8184
ret nil, errs
8285
}

std/jule/mod/parse.jule

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ impl parser {
130130

131131
// Checks the mandatory module information.
132132
#disable nilptr
133-
fn checkMod(modfile: str, mod: &Mod, mut &logs: *[]log::Log) {
133+
fn checkMod(options: ParseOptions, modfile: str, mod: &Mod, mut &logs: *[]log::Log) {
134134
if mod.Name == "" {
135135
*logs = append(*logs, log::Log{
136136
Kind: log::Error,
137137
Text: "module file must be have name",
138138
Path: modfile,
139139
})
140-
} else if mod.Name == "std" {
140+
} else if !options.AllowStd && mod.Name == "std" {
141141
*logs = append(*logs, log::Log{
142142
Kind: log::Error,
143143
Text: "module name \"std\" is a reserved name",
@@ -147,8 +147,14 @@ fn checkMod(modfile: str, mod: &Mod, mut &logs: *[]log::Log) {
147147
}
148148
}
149149

150+
// Options for the module file parsing.
151+
struct ParseOptions {
152+
// Allows using the reserved "std" module name.
153+
AllowStd: bool
154+
}
155+
150156
// Parse module from the module file path.
151-
fn ParseFile(path: str): (&Mod, []log::Log) {
157+
fn ParseFile(path: str, options: ParseOptions): (&Mod, []log::Log) {
152158
modfile := filepath::Join(path, jule::ModuleFile)
153159
mut bytes := os::ReadFile(modfile) else {
154160
ret nil, [{
@@ -170,7 +176,7 @@ fn ParseFile(path: str): (&Mod, []log::Log) {
170176
if len(parser.logs) > 0 {
171177
ret parser.mod, parser.logs
172178
}
173-
checkMod(parser.modfile, parser.mod, &parser.logs)
179+
checkMod(options, parser.modfile, parser.mod, &parser.logs)
174180
ret parser.mod, parser.logs
175181
}
176182

0 commit comments

Comments
 (0)