mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
prevent unhashable panic
This commit is contained in:
@@ -42,6 +42,10 @@ func init() {
|
||||
switch y := v.(type) {
|
||||
case ArArray:
|
||||
if len(y) == 2 {
|
||||
keytype := typeof(y[0])
|
||||
if keytype == "array" || keytype == "map" {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot use unhashable value as key: " + keytype, EXISTS: true}
|
||||
}
|
||||
newmap[y[0]] = y[1]
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -433,6 +433,7 @@ func indexGetParse(code UNPARSEcode, index int, codelines []UNPARSEcode) (ArMapG
|
||||
}
|
||||
tival, worked, err, i := translateVal(UNPARSEcode{code: ti, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 0)
|
||||
if !worked {
|
||||
fmt.Println(err)
|
||||
if i == len(split)-1 {
|
||||
return ArMapGet{}, false, err, i
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ func getValuesFromLetter(str string, splitstr string, index int, codelines []UNP
|
||||
if worked {
|
||||
arguments = append(arguments, resp)
|
||||
temp = []string{}
|
||||
if i == len(commasplit)-1 {
|
||||
return arguments, true, ArErr{}
|
||||
}
|
||||
} else if i == len(commasplit)-1 {
|
||||
return nil, false, ArErr{"Syntax Error", "invalid argument", codelines[index].line, codelines[index].path, codelines[index].realcode, true}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
||||
keyval := ""
|
||||
|
||||
if typeof(key) != "string" || !SpacelessVariableCompiled.MatchString(key.(string)) {
|
||||
keyval = anyToArgon(key, true, true, depth-1, indent+1, colored, plain)
|
||||
keyval = anyToArgon(key, true, true, depth, indent+1, colored, plain)
|
||||
} else {
|
||||
outputkeyval := []string{}
|
||||
if colored {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -11,15 +12,20 @@ type UNPARSEcode struct {
|
||||
path string
|
||||
}
|
||||
|
||||
// returns (number | string | nil), success, error, step
|
||||
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
||||
var (
|
||||
resp any = nil
|
||||
worked bool = false
|
||||
err ArErr = ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}
|
||||
i int = 1
|
||||
)
|
||||
if isLine == 2 {
|
||||
if isDeleteVariable(code) {
|
||||
return parseDelete(code, index, codelines)
|
||||
} else if isComment(code) {
|
||||
resp, worked, err, step := parseComment(code, index, codelines)
|
||||
resp, worked, err, i = parseComment(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, step
|
||||
return resp, worked, err, i
|
||||
}
|
||||
} else if isReturn(code) {
|
||||
return parseReturn(code, index, codelines)
|
||||
@@ -47,31 +53,33 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
||||
}
|
||||
|
||||
if isBrackets(code) {
|
||||
bracket, worked, err, step := parseBrackets(code, index, codelines)
|
||||
resp, worked, err, i = parseBrackets(code, index, codelines)
|
||||
if worked {
|
||||
return bracket, worked, err, step
|
||||
return resp, worked, err, i
|
||||
}
|
||||
} else if isnot(code) {
|
||||
return parseNot(code, index, codelines, isLine)
|
||||
}
|
||||
if isSetVariable(code) {
|
||||
setvar, worked, err, step := parseSetVariable(code, index, codelines, isLine)
|
||||
resp, worked, err, i = parseSetVariable(code, index, codelines, isLine)
|
||||
if worked {
|
||||
return setvar, worked, err, step
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isAutoAsignVariable(code) {
|
||||
setvar, worked, err, step := parseAutoAsignVariable(code, index, codelines, isLine)
|
||||
resp, worked, err, i = parseAutoAsignVariable(code, index, codelines, isLine)
|
||||
if worked {
|
||||
return setvar, worked, err, step
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
{
|
||||
operation, worked, err, step := parseOperations(code, index, codelines)
|
||||
if worked {
|
||||
return operation, worked, err, step
|
||||
} else if err.EXISTS {
|
||||
return nil, worked, err, step
|
||||
}
|
||||
}
|
||||
if isNumber(code) {
|
||||
return parseNumber(code)
|
||||
} else if isNegative(code) {
|
||||
@@ -79,9 +87,9 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
||||
} else if isFactorial(code) {
|
||||
return parseFactorial(code, index, codelines)
|
||||
} else if isCall(code) {
|
||||
call, worked, err, step := parseCall(code, index, codelines)
|
||||
resp, worked, err, i = parseCall(code, index, codelines)
|
||||
if worked {
|
||||
return call, worked, err, step
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isBoolean(code) {
|
||||
@@ -89,20 +97,28 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
||||
} else if isVariable(code) {
|
||||
return parseVariable(code)
|
||||
} else if isArray(code) {
|
||||
return parseArray(code, index, codelines)
|
||||
} else if isMapGet(code) {
|
||||
resp, worked, err, i = parseArray(code, index, codelines)
|
||||
fmt.Println(resp, worked, err, i)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isMapGet(code) {
|
||||
return mapGetParse(code, index, codelines)
|
||||
} else if isIndexGet(code) {
|
||||
return indexGetParse(code, index, codelines)
|
||||
} else if isString(code) {
|
||||
resp, worked, err, i = indexGetParse(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isString(code) {
|
||||
return parseString(code)
|
||||
} else if issquareroot(code) {
|
||||
return parseSquareroot(code, index, codelines)
|
||||
}
|
||||
return nil, false, ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}, 1
|
||||
return resp, worked, err, i
|
||||
}
|
||||
|
||||
// returns [](number | string), error
|
||||
func translate(codelines []UNPARSEcode) ([]any, ArErr) {
|
||||
translated := []any{}
|
||||
for i := 0; i < len(codelines); {
|
||||
|
||||
@@ -16,6 +16,8 @@ func typeof(val any) string {
|
||||
return "function"
|
||||
case ArMap:
|
||||
return "map"
|
||||
case ArArray:
|
||||
return "array"
|
||||
case accessVariable:
|
||||
return "variable"
|
||||
}
|
||||
|
||||
@@ -244,6 +244,10 @@ func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
||||
}
|
||||
switch y := respp.(type) {
|
||||
case ArMap:
|
||||
keytype := typeof(key)
|
||||
if keytype == "array" || keytype == "map" {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot use unhashable value as key: " + keytype, EXISTS: true}
|
||||
}
|
||||
varMutex.Lock()
|
||||
y[key] = resp
|
||||
varMutex.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user