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) {
|
switch y := v.(type) {
|
||||||
case ArArray:
|
case ArArray:
|
||||||
if len(y) == 2 {
|
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]
|
newmap[y[0]] = y[1]
|
||||||
continue
|
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)
|
tival, worked, err, i := translateVal(UNPARSEcode{code: ti, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 0)
|
||||||
if !worked {
|
if !worked {
|
||||||
|
fmt.Println(err)
|
||||||
if i == len(split)-1 {
|
if i == len(split)-1 {
|
||||||
return ArMapGet{}, false, err, i
|
return ArMapGet{}, false, err, i
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ func getValuesFromLetter(str string, splitstr string, index int, codelines []UNP
|
|||||||
if worked {
|
if worked {
|
||||||
arguments = append(arguments, resp)
|
arguments = append(arguments, resp)
|
||||||
temp = []string{}
|
temp = []string{}
|
||||||
|
if i == len(commasplit)-1 {
|
||||||
|
return arguments, true, ArErr{}
|
||||||
|
}
|
||||||
} else if i == len(commasplit)-1 {
|
} else if i == len(commasplit)-1 {
|
||||||
return nil, false, ArErr{"Syntax Error", "invalid argument", codelines[index].line, codelines[index].path, codelines[index].realcode, true}
|
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 := ""
|
keyval := ""
|
||||||
|
|
||||||
if typeof(key) != "string" || !SpacelessVariableCompiled.MatchString(key.(string)) {
|
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 {
|
} else {
|
||||||
outputkeyval := []string{}
|
outputkeyval := []string{}
|
||||||
if colored {
|
if colored {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,15 +12,20 @@ type UNPARSEcode struct {
|
|||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns (number | string | nil), success, error, step
|
|
||||||
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) {
|
||||||
|
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 isLine == 2 {
|
||||||
if isDeleteVariable(code) {
|
if isDeleteVariable(code) {
|
||||||
return parseDelete(code, index, codelines)
|
return parseDelete(code, index, codelines)
|
||||||
} else if isComment(code) {
|
} else if isComment(code) {
|
||||||
resp, worked, err, step := parseComment(code, index, codelines)
|
resp, worked, err, i = parseComment(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, step
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isReturn(code) {
|
} else if isReturn(code) {
|
||||||
return parseReturn(code, index, codelines)
|
return parseReturn(code, index, codelines)
|
||||||
@@ -47,30 +53,32 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
}
|
}
|
||||||
|
|
||||||
if isBrackets(code) {
|
if isBrackets(code) {
|
||||||
bracket, worked, err, step := parseBrackets(code, index, codelines)
|
resp, worked, err, i = parseBrackets(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return bracket, worked, err, step
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isnot(code) {
|
} else if isnot(code) {
|
||||||
return parseNot(code, index, codelines, isLine)
|
return parseNot(code, index, codelines, isLine)
|
||||||
}
|
}
|
||||||
if isSetVariable(code) {
|
if isSetVariable(code) {
|
||||||
setvar, worked, err, step := parseSetVariable(code, index, codelines, isLine)
|
resp, worked, err, i = parseSetVariable(code, index, codelines, isLine)
|
||||||
if worked {
|
if worked {
|
||||||
return setvar, worked, err, step
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isAutoAsignVariable(code) {
|
if isAutoAsignVariable(code) {
|
||||||
setvar, worked, err, step := parseAutoAsignVariable(code, index, codelines, isLine)
|
resp, worked, err, i = parseAutoAsignVariable(code, index, codelines, isLine)
|
||||||
if worked {
|
if worked {
|
||||||
return setvar, worked, err, step
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
operation, worked, err, step := parseOperations(code, index, codelines)
|
{
|
||||||
if worked {
|
operation, worked, err, step := parseOperations(code, index, codelines)
|
||||||
return operation, worked, err, step
|
if worked {
|
||||||
} else if err.EXISTS {
|
return operation, worked, err, step
|
||||||
return nil, worked, err, step
|
} else if err.EXISTS {
|
||||||
|
return nil, worked, err, step
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if isNumber(code) {
|
if isNumber(code) {
|
||||||
return parseNumber(code)
|
return parseNumber(code)
|
||||||
@@ -79,9 +87,9 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
} else if isFactorial(code) {
|
} else if isFactorial(code) {
|
||||||
return parseFactorial(code, index, codelines)
|
return parseFactorial(code, index, codelines)
|
||||||
} else if isCall(code) {
|
} else if isCall(code) {
|
||||||
call, worked, err, step := parseCall(code, index, codelines)
|
resp, worked, err, i = parseCall(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return call, worked, err, step
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isBoolean(code) {
|
if isBoolean(code) {
|
||||||
@@ -89,20 +97,28 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
} else if isVariable(code) {
|
} else if isVariable(code) {
|
||||||
return parseVariable(code)
|
return parseVariable(code)
|
||||||
} else if isArray(code) {
|
} else if isArray(code) {
|
||||||
return parseArray(code, index, codelines)
|
resp, worked, err, i = parseArray(code, index, codelines)
|
||||||
} else if isMapGet(code) {
|
fmt.Println(resp, worked, err, i)
|
||||||
|
if worked {
|
||||||
|
return resp, worked, err, i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isMapGet(code) {
|
||||||
return mapGetParse(code, index, codelines)
|
return mapGetParse(code, index, codelines)
|
||||||
} else if isIndexGet(code) {
|
} else if isIndexGet(code) {
|
||||||
return indexGetParse(code, index, codelines)
|
resp, worked, err, i = indexGetParse(code, index, codelines)
|
||||||
} else if isString(code) {
|
if worked {
|
||||||
|
return resp, worked, err, i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isString(code) {
|
||||||
return parseString(code)
|
return parseString(code)
|
||||||
} else if issquareroot(code) {
|
} else if issquareroot(code) {
|
||||||
return parseSquareroot(code, index, codelines)
|
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) {
|
func translate(codelines []UNPARSEcode) ([]any, ArErr) {
|
||||||
translated := []any{}
|
translated := []any{}
|
||||||
for i := 0; i < len(codelines); {
|
for i := 0; i < len(codelines); {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ func typeof(val any) string {
|
|||||||
return "function"
|
return "function"
|
||||||
case ArMap:
|
case ArMap:
|
||||||
return "map"
|
return "map"
|
||||||
|
case ArArray:
|
||||||
|
return "array"
|
||||||
case accessVariable:
|
case accessVariable:
|
||||||
return "variable"
|
return "variable"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,6 +244,10 @@ func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
switch y := respp.(type) {
|
switch y := respp.(type) {
|
||||||
case ArMap:
|
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()
|
varMutex.Lock()
|
||||||
y[key] = resp
|
y[key] = resp
|
||||||
varMutex.Unlock()
|
varMutex.Unlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user