Let: Let works now, somehow. I fixed a bunch of things but this cart is still fundimentaly broken
This commit is contained in:
parent
c2ba92518e
commit
75819e9abc
24
src/fsh.nim
24
src/fsh.nim
|
@ -19,13 +19,14 @@ for k, v in envPairs():
|
|||
envVariables[k]=v
|
||||
|
||||
# list of builtin commands
|
||||
let builtins: array[6, string] = [
|
||||
let builtins: array[7, string] = [
|
||||
"set",
|
||||
"setenv",
|
||||
"echo",
|
||||
"exit",
|
||||
"if",
|
||||
"cd",
|
||||
"let",
|
||||
]
|
||||
|
||||
# number of frames to be used for builtins like set
|
||||
|
@ -92,8 +93,10 @@ proc readLiteral(strm: Stream): string =
|
|||
case c:
|
||||
of '{':
|
||||
numbraces.inc
|
||||
result.add('{')
|
||||
of '}':
|
||||
numbraces = numbraces - 1
|
||||
if numbraces != 0: result.add('}')
|
||||
of '\\':
|
||||
if strm.peekChar notin {'{', '}'}: result.add(strm.readChar)
|
||||
result.add(strm.readChar)
|
||||
|
@ -195,7 +198,7 @@ proc readVariable(strm: Stream): string =
|
|||
# evalVariable finds a value of a variable
|
||||
proc evalVariable(vari: string): string =
|
||||
if vari == "$": return "$"
|
||||
for i in shellVariables.high..shellVariables.low:
|
||||
for i in countdown((numframes-1), 0):
|
||||
let frame = shellVariables[i]
|
||||
if frame.hasKey(vari): return frame[vari]
|
||||
if envVariables.hasKey(vari):
|
||||
|
@ -329,6 +332,23 @@ proc runBuiltin(builtin: string, args: openArray[string]): (string, int) =
|
|||
return ("", 0)
|
||||
except OsError as e:
|
||||
raise newShellCommandException("No such directory", "cd")
|
||||
of "let":
|
||||
if args.len < 2:
|
||||
raise newShellCommandException("Not enough arguments provided", "let")
|
||||
shellVariables.add(newStringTable(modeCaseSensitive))
|
||||
numframes.inc
|
||||
let varvals = args[0].parseCommand
|
||||
for varval in varvals:
|
||||
let varval_parsed = varval.parseCommand
|
||||
if varval_parsed.len < 2:
|
||||
raise newShellCommandException("Missingvalue to go with key", "let")
|
||||
let vari = varval_parsed[0]
|
||||
let val = varval_parsed[1]
|
||||
shellVariables[numframes-1][vari]=val
|
||||
result[0] = args[1].eval
|
||||
discard shellVariables.pop
|
||||
numframes.dec
|
||||
result[1] = 0
|
||||
else:
|
||||
raise newShellCommandException("No such builtin implemented", builtin)
|
||||
|
||||
|
|
Loading…
Reference in New Issue