mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
fix variable unable to be assigned on the same line
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"*.ar": "lua"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"name": "argon-v3",
|
"name": "argon-v3",
|
||||||
"version": "1.0.0"
|
"version": "3.0.1"
|
||||||
}
|
}
|
||||||
@@ -26,3 +26,20 @@ func ArValidToAny(a any) any {
|
|||||||
}
|
}
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ArValidToHash(a any) (any, ArErr) {
|
||||||
|
switch a := a.(type) {
|
||||||
|
case ArObject:
|
||||||
|
if callable, ok := a.obj["__hash__"]; ok {
|
||||||
|
value, err := runCall(call{
|
||||||
|
Callable: callable,
|
||||||
|
Args: []any{},
|
||||||
|
}, stack{}, 0)
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return value, ArErr{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return a, ArErr{}
|
||||||
|
}
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ func makeGlobal() ArObject {
|
|||||||
}}
|
}}
|
||||||
vars["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
vars["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
||||||
vars["sequence"] = builtinFunc{"sequence", ArSequence}
|
vars["sequence"] = builtinFunc{"sequence", ArSequence}
|
||||||
vars["exit"] = builtinFunc{"exit", func(a ...any) (any, ArErr) {
|
vars["|"] = builtinFunc{"exit", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
@@ -235,29 +235,6 @@ func makeGlobal() ArObject {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}}
|
}}
|
||||||
vars["error"] = builtinFunc{"error", func(a ...any) (any, ArErr) {
|
|
||||||
if len(a) < 1 || len(a) > 2 {
|
|
||||||
return nil, ArErr{TYPE: "error", message: "error takes 1 or 2 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
|
|
||||||
}
|
|
||||||
if len(a) == 1 {
|
|
||||||
a[0] = ArValidToAny(a[0])
|
|
||||||
switch x := a[0].(type) {
|
|
||||||
case string:
|
|
||||||
return nil, ArErr{TYPE: "Error", message: x, EXISTS: true}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
a[0] = ArValidToAny(a[0])
|
|
||||||
a[1] = ArValidToAny(a[1])
|
|
||||||
switch x := a[0].(type) {
|
|
||||||
case string:
|
|
||||||
switch y := a[1].(type) {
|
|
||||||
case string:
|
|
||||||
return nil, ArErr{TYPE: x, message: y, EXISTS: true}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create error from '" + typeof(a[0]) + "'", EXISTS: true}
|
|
||||||
}}
|
|
||||||
vars["chr"] = builtinFunc{"chr", func(a ...any) (any, ArErr) {
|
vars["chr"] = builtinFunc{"chr", func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{TYPE: "chr", message: "chr takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
return nil, ArErr{TYPE: "chr", message: "chr takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var Args = os.Args[1:]
|
|||||||
|
|
||||||
type stack = []ArObject
|
type stack = []ArObject
|
||||||
|
|
||||||
const VERSION = "3.0.0"
|
const VERSION = "3.0.1"
|
||||||
|
|
||||||
// Example struct
|
// Example struct
|
||||||
type Person struct {
|
type Person struct {
|
||||||
|
|||||||
@@ -11,21 +11,10 @@ type UNPARSEcode struct {
|
|||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
var knownFailures = []string{}
|
var knownFailures = map[string]ArErr{}
|
||||||
var knownFailuresErrs = []ArErr{}
|
|
||||||
|
|
||||||
func StringExists(arr []string, target string) (bool, ArErr) {
|
|
||||||
for i, str := range arr {
|
|
||||||
if str == target {
|
|
||||||
return true, knownFailuresErrs[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, ArErr{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
||||||
known, knownErr := StringExists(knownFailures, code.code)
|
if knownErr, ok := knownFailures[code.code]; ok {
|
||||||
if known {
|
|
||||||
return nil, false, ArErr{
|
return nil, false, ArErr{
|
||||||
knownErr.TYPE,
|
knownErr.TYPE,
|
||||||
knownErr.message,
|
knownErr.message,
|
||||||
@@ -45,8 +34,7 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
if isDeleteVariable(code) {
|
if isDeleteVariable(code) {
|
||||||
resp, worked, err, i = parseDelete(code, index, codelines)
|
resp, worked, err, i = parseDelete(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isComment(code) {
|
} else if isComment(code) {
|
||||||
@@ -57,64 +45,55 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
} else if isReturn(code) {
|
} else if isReturn(code) {
|
||||||
resp, worked, err, i = parseReturn(code, index, codelines)
|
resp, worked, err, i = parseReturn(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isBreak(code) {
|
} else if isBreak(code) {
|
||||||
resp, worked, err, i = parseBreak(code)
|
resp, worked, err, i = parseBreak(code)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isContinue(code) {
|
} else if isContinue(code) {
|
||||||
resp, worked, err, i = parseContinue(code)
|
resp, worked, err, i = parseContinue(code)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isIfStatement(code) {
|
} else if isIfStatement(code) {
|
||||||
resp, worked, err, i = parseIfStatement(code, index, codelines)
|
resp, worked, err, i = parseIfStatement(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isWhileLoop(code) {
|
} else if isWhileLoop(code) {
|
||||||
resp, worked, err, i = parseWhileLoop(code, index, codelines)
|
resp, worked, err, i = parseWhileLoop(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isForeverLoop(code) {
|
} else if isForeverLoop(code) {
|
||||||
resp, worked, err, i = parseForeverLoop(code, index, codelines)
|
resp, worked, err, i = parseForeverLoop(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isForLoop(code) {
|
} else if isForLoop(code) {
|
||||||
resp, worked, err, i = parseForLoop(code, index, codelines)
|
resp, worked, err, i = parseForLoop(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isGenericImport(code) {
|
} else if isGenericImport(code) {
|
||||||
resp, worked, err, i = parseGenericImport(code, index, codelines)
|
resp, worked, err, i = parseGenericImport(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isTryCatch(code) {
|
} else if isTryCatch(code) {
|
||||||
resp, worked, err, i = parseTryCatch(code, index, codelines)
|
resp, worked, err, i = parseTryCatch(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
@@ -124,8 +103,7 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
if isDoWrap(code) {
|
if isDoWrap(code) {
|
||||||
resp, worked, err, i = parseDoWrap(code, index, codelines)
|
resp, worked, err, i = parseDoWrap(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
@@ -164,15 +142,13 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
if isNumber(code) {
|
if isNumber(code) {
|
||||||
resp, worked, err, i = parseNumber(code)
|
resp, worked, err, i = parseNumber(code)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isString(code) {
|
} else if isString(code) {
|
||||||
resp, worked, err, i = parseString(code)
|
resp, worked, err, i = parseString(code)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if issquareroot(code) {
|
} else if issquareroot(code) {
|
||||||
@@ -190,8 +166,7 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
if isVariable(code) {
|
if isVariable(code) {
|
||||||
resp, worked, err, i = parseVariable(code)
|
resp, worked, err, i = parseVariable(code)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
@@ -226,15 +201,13 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
if isNegative(code) {
|
if isNegative(code) {
|
||||||
resp, worked, err, i = parseNegative(code, index, codelines)
|
resp, worked, err, i = parseNegative(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isMapGet(code) {
|
} else if isMapGet(code) {
|
||||||
resp, worked, err, i = mapGetParse(code, index, codelines)
|
resp, worked, err, i = mapGetParse(code, index, codelines)
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
} else if isIndexGet(code) {
|
} else if isIndexGet(code) {
|
||||||
@@ -244,8 +217,7 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !worked {
|
if !worked {
|
||||||
knownFailures = append(knownFailures, code.code)
|
knownFailures[code.code] = err
|
||||||
knownFailuresErrs = append(knownFailuresErrs, err)
|
|
||||||
}
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,19 +171,47 @@ func parseSetVariable(code UNPARSEcode, index int, lines []UNPARSEcode, isLine i
|
|||||||
return setVariable{TYPE: "let", toset: toset, value: value, function: function, params: params, line: code.line, code: code.code, path: code.path}, true, ArErr{}, i + namei - 1
|
return setVariable{TYPE: "let", toset: toset, value: value, function: function, params: params, line: code.line, code: code.code, path: code.path}, true, ArErr{}, i + namei - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var operationsToInt = map[byte]int{
|
||||||
|
'+': 10,
|
||||||
|
'-': 11,
|
||||||
|
'*': 12,
|
||||||
|
'/': 15,
|
||||||
|
'^': 16,
|
||||||
|
'&': 0,
|
||||||
|
'|': 1,
|
||||||
|
}
|
||||||
|
|
||||||
func parseAutoAsignVariable(code UNPARSEcode, index int, lines []UNPARSEcode, isLine int) (setVariable, bool, ArErr, int) {
|
func parseAutoAsignVariable(code UNPARSEcode, index int, lines []UNPARSEcode, isLine int) (setVariable, bool, ArErr, int) {
|
||||||
trim := strings.TrimSpace(code.code)
|
trim := strings.TrimSpace(code.code)
|
||||||
equalsplit := strings.SplitN(trim, "=", 2)
|
equalsplit := strings.Split(trim, "=")
|
||||||
name := strings.TrimSpace(equalsplit[0])
|
for i := 1; i < len(equalsplit); i++ {
|
||||||
|
name := strings.TrimSpace(strings.Join(equalsplit[:i], "="))
|
||||||
|
if name == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
operation := name[len(name)-1]
|
||||||
|
var operationtype int = -1
|
||||||
|
if operation == '+' || operation == '-' || operation == '*' || operation == '/' || operation == '^' || operation == '&' || operation == '|' {
|
||||||
|
name = strings.TrimSpace(name[:len(name)-1])
|
||||||
|
if n, ok := operationsToInt[operation]; ok {
|
||||||
|
operationtype = n
|
||||||
|
}
|
||||||
|
}
|
||||||
params := []string{}
|
params := []string{}
|
||||||
function := false
|
function := false
|
||||||
if blockedVariableNames[name] {
|
if blockedVariableNames[name] {
|
||||||
|
if i == len(equalsplit)-1 {
|
||||||
return setVariable{}, false, ArErr{"Naming Error", "\"" + name + "\" is a reserved keyword", code.line, code.path, code.realcode, true}, 1
|
return setVariable{}, false, ArErr{"Naming Error", "\"" + name + "\" is a reserved keyword", code.line, code.path, code.realcode, true}, 1
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
toset, success, err, namei := nameToTranslated(UNPARSEcode{code: name, realcode: code.realcode, line: code.line, path: code.path}, index, lines)
|
toset, success, err, namei := nameToTranslated(UNPARSEcode{code: name, realcode: code.realcode, line: code.line, path: code.path}, index, lines)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
|
if i == len(equalsplit)-1 {
|
||||||
return setVariable{}, success, err, namei
|
return setVariable{}, success, err, namei
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
switch x := toset.(type) {
|
switch x := toset.(type) {
|
||||||
case accessVariable:
|
case accessVariable:
|
||||||
break
|
break
|
||||||
@@ -194,14 +222,28 @@ func parseAutoAsignVariable(code UNPARSEcode, index int, lines []UNPARSEcode, is
|
|||||||
params = x.params
|
params = x.params
|
||||||
toset = x.toset
|
toset = x.toset
|
||||||
default:
|
default:
|
||||||
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean '=='?", code.line, code.path, code.realcode, true}, 1
|
if i == len(equalsplit)-1 {
|
||||||
|
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean to put 'let' before?", code.line, code.path, code.realcode, true}, 1
|
||||||
}
|
}
|
||||||
value, success, err, i := translateVal(UNPARSEcode{code: equalsplit[1], realcode: code.realcode, line: code.line, path: code.path}, index, lines, isLine)
|
continue
|
||||||
|
}
|
||||||
|
value, success, err, i := translateVal(UNPARSEcode{code: strings.Join(equalsplit[i:], "="), realcode: code.realcode, line: code.line, path: code.path}, index, lines, isLine)
|
||||||
if !success {
|
if !success {
|
||||||
return setVariable{}, false, err, i
|
return setVariable{}, false, err, i
|
||||||
}
|
}
|
||||||
|
if operationtype != -1 {
|
||||||
|
value = operationType{
|
||||||
|
operation: operationtype,
|
||||||
|
values: []any{toset, value},
|
||||||
|
line: code.line,
|
||||||
|
code: code.code,
|
||||||
|
path: code.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
return setVariable{TYPE: "auto", toset: toset, value: value, function: function, params: params, line: code.line, code: code.code, path: code.path}, true, ArErr{}, i + namei - 1
|
return setVariable{TYPE: "auto", toset: toset, value: value, function: function, params: params, line: code.line, code: code.code, path: code.path}, true, ArErr{}, i + namei - 1
|
||||||
}
|
}
|
||||||
|
return setVariable{}, false, ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}, 1
|
||||||
|
}
|
||||||
|
|
||||||
func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
||||||
var resp any
|
var resp any
|
||||||
|
|||||||
Reference in New Issue
Block a user