mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
allow import without as
This commit is contained in:
@@ -95,9 +95,9 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "File does not exist: " + realpath, EXISTS: true}
|
return ArObject{}, ArErr{TYPE: "Import Error", message: "File does not exist: " + path, EXISTS: true}
|
||||||
} else if importing[p] {
|
} else if importing[p] {
|
||||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Circular import: " + realpath, EXISTS: true}
|
return ArObject{}, ArErr{TYPE: "Import Error", message: "Circular import: " + path, EXISTS: true}
|
||||||
} else if _, ok := imported[p]; ok {
|
} else if _, ok := imported[p]; ok {
|
||||||
return imported[p], ArErr{}
|
return imported[p], ArErr{}
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,6 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
|
|||||||
"path": p,
|
"path": p,
|
||||||
}),
|
}),
|
||||||
"main": main,
|
"main": main,
|
||||||
"scope": global,
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
_, runimeErr := ThrowOnNonLoop(run(translated, stack{global, localvars, local}))
|
_, runimeErr := ThrowOnNonLoop(run(translated, stack{global, localvars, local}))
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"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 {
|
type ArImport struct {
|
||||||
filePath any
|
filePath any
|
||||||
@@ -22,18 +22,49 @@ func isGenericImport(code UNPARSEcode) bool {
|
|||||||
func parseGenericImport(code UNPARSEcode, index int, codeline []UNPARSEcode) (ArImport, bool, ArErr, int) {
|
func parseGenericImport(code UNPARSEcode, index int, codeline []UNPARSEcode) (ArImport, bool, ArErr, int) {
|
||||||
trim := strings.Trim(code.code, " ")
|
trim := strings.Trim(code.code, " ")
|
||||||
pathAndAs := trim[6:]
|
pathAndAs := trim[6:]
|
||||||
split := strings.SplitN(pathAndAs, " as ", 2)
|
split := strings.Split(pathAndAs, " as ")
|
||||||
toImportstr := strings.TrimSpace(split[0])
|
var toImport any
|
||||||
asStr := strings.TrimSpace(split[1])
|
var asStr any
|
||||||
toImport, worked, err, i := translateVal(UNPARSEcode{
|
var i = 1
|
||||||
code: toImportstr,
|
if len(split) == 1 {
|
||||||
|
toImportval, worked, err, I := translateVal(UNPARSEcode{
|
||||||
|
code: strings.Trim(split[0], " "),
|
||||||
realcode: code.realcode,
|
realcode: code.realcode,
|
||||||
line: code.line,
|
line: code.line,
|
||||||
path: code.path,
|
path: code.path,
|
||||||
}, index, codeline, 0)
|
}, index, codeline, 0)
|
||||||
if !worked {
|
if !worked || err.EXISTS {
|
||||||
return ArImport{}, false, err, i
|
return ArImport{}, worked, err, I
|
||||||
}
|
}
|
||||||
|
toImport = toImportval
|
||||||
|
i = I
|
||||||
|
} else {
|
||||||
|
for i := 1; i < len(split); i++ {
|
||||||
|
before := strings.Trim(strings.Join(split[:i], " as "), " ")
|
||||||
|
after := strings.Trim(strings.Join(split[i:], " as "), " ")
|
||||||
|
toImportval, worked, err, I := translateVal(UNPARSEcode{
|
||||||
|
code: before,
|
||||||
|
realcode: code.realcode,
|
||||||
|
line: code.line,
|
||||||
|
path: code.path,
|
||||||
|
}, index, codeline, 0)
|
||||||
|
i = I
|
||||||
|
if !worked || err.EXISTS {
|
||||||
|
if i == len(split)-1 {
|
||||||
|
return ArImport{}, worked, err, i
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if after == "" {
|
||||||
|
} else if variableCompile.MatchString(after) {
|
||||||
|
asStr = after
|
||||||
|
} else {
|
||||||
|
return ArImport{}, false, ArErr{"Syntax Error", "invalid variable name '" + after + "'", code.line, code.path, code.realcode, true}, i
|
||||||
|
}
|
||||||
|
toImport = toImportval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ArImport{
|
return ArImport{
|
||||||
toImport,
|
toImport,
|
||||||
asStr,
|
asStr,
|
||||||
|
|||||||
Reference in New Issue
Block a user