get rid of circular imports

This commit is contained in:
2024-04-06 15:48:00 +01:00
parent bf15b435c2
commit e8d25d231c
4 changed files with 10 additions and 18 deletions

View File

@@ -85,11 +85,11 @@ func __runTranslatedImport(translatedImport translatedImport, global ArObject, m
"main": main,
}),
})
imported[translatedImport.p] = local
_, runimeErr := run(translatedImport.translated, stack{global, localvars, local})
if runimeErr.EXISTS {
return ArObject{}, runimeErr
}
imported[translatedImport.p] = local
return local, ArErr{}
}

View File

@@ -5,7 +5,7 @@ import (
"strings"
)
var genericImportCompiled = makeRegex(`import( )+(.|\n)+(( )+as( )+([a-zA-Z_]|(\p{L}\p{M}*))([a-zA-Z0-9_]|(\p{L}\p{M}*))*)?( *)`)
var genericImportCompiled = makeRegex(`( *)import( )+(.|\n)+(( )+as( )+([a-zA-Z_]|(\p{L}\p{M}*))([a-zA-Z0-9_]|(\p{L}\p{M}*))*)?( *)`)
type ArImport struct {
pretranslated bool
@@ -80,20 +80,10 @@ func parseGenericImport(code UNPARSEcode, index int, codeline []UNPARSEcode) (Ar
}
if str, ok := toImport.(string); ok {
resp, err := translateImport(str, filepath.Dir(filepath.ToSlash(code.path)))
if !err.EXISTS {
importOBJ.translated = resp
importOBJ.pretranslated = true
var err ArErr
importOBJ.translated, err = translateImport(str, filepath.Dir(filepath.ToSlash(code.path)))
if err.EXISTS {
if err.line == 0 {
err.line = importOBJ.Line
}
if err.path == "" {
err.path = importOBJ.Path
}
if err.code == "" {
err.code = importOBJ.Code
}
return importOBJ, false, err, i
}
}

View File

@@ -31,7 +31,7 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
err ArErr = ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}
i int = 1
)
if isLine == 3 {
if isLine >= 3 {
if isComment(code) {
resp, worked, err, i = parseComment(code, index, codelines)
if worked {
@@ -251,7 +251,7 @@ func translate(codelines []UNPARSEcode) ([]any, ArErr) {
if currentindent != 0 {
return nil, ArErr{"Syntax Error", "invalid indent", codelines[i].line, codelines[i].path, codelines[i].realcode, true}
}
val, _, err, step := translateVal(codelines[i], i, codelines, 3)
val, _, err, step := translateVal(codelines[i], i, codelines, 4)
i += step
if err.EXISTS {
return nil, err

View File

@@ -1 +1,3 @@
term.log("hello")
import "circular_import"