comments support, script loading support

This commit is contained in:
Aidan 2020-07-15 18:41:54 -07:00
parent 654e8bd55b
commit bd22b84699
No known key found for this signature in database
GPG key ID: 327711E983899316
11 changed files with 145 additions and 69 deletions

View file

@ -254,8 +254,14 @@ func read_cmd(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
}
}
output := out.String()
olen := len(output)
if olen > 0 && output[olen - 1] == '\n' {
output = output[:olen - 1]
}
ret := &ast.Token{Tag: ast.STRING}
ret.Set(out.String())
ret.Set(output)
return ret
}

View file

@ -60,30 +60,34 @@ func decl_func(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.To
ASTSYNCSTATE := ast.SyncTablesWithOSEnviron
inner := func(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
temp := in.Eval(ft, vt, false)
if temp == nil {
log.Log(log.ERR,
"error parsing arguments",
name.Value())
return nil
}
ast.SyncTablesWithOSEnviron = false
key_iter := args.Expand()
val_iter := temp
for key_iter != nil {
if val_iter == nil {
var temp *ast.Token
if numArgs != 0 || in != nil {
temp = in.Eval(ft, vt, false)
if temp == nil {
log.Log(log.ERR,
"Not enough arguments supplied",
"error parsing arguments",
name.Value())
return nil
}
ast.SetVar(key_iter.Value(), val_iter, vt)
key_iter = key_iter.Next
val_iter = val_iter.Next
ast.SyncTablesWithOSEnviron = false
key_iter := args.Expand()
val_iter := temp
for key_iter != nil {
if val_iter == nil {
log.Log(log.ERR,
"Not enough arguments supplied",
name.Value())
}
ast.SetVar(key_iter.Value(), val_iter, vt)
key_iter = key_iter.Next
val_iter = val_iter.Next
}
}
// maybe we actually should put the inner scope var into the env
ast.SyncTablesWithOSEnviron = ASTSYNCSTATE
ret := form.Eval(ft, vt, false)
ast.SyncTablesWithOSEnviron = false

View file

@ -22,6 +22,7 @@ import (
"fmt"
"gitlab.com/whom/shs/log"
"gitlab.com/whom/shs/ast"
"gitlab.com/whom/shs/util"
)
func GenFuncTable() ast.FuncTable {
@ -62,13 +63,20 @@ func GenFuncTable() ast.FuncTable {
Args: 2,
},
"input": &ast.Function{
"input": &ast.Function{
Function: input,
Name: "input",
TimesCalled: 0,
Args: 1,
},
"load": &ast.Function{
Function: load,
Name: "load",
TimesCalled: 0,
Args: 1,
},
"...": &ast.Function{
Function: expand,
Name: "...",
@ -337,3 +345,18 @@ func input(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
ret.Set(output)
return ret
}
func load(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, true)
if in.Tag != ast.STRING {
log.Log(log.ERR,
"argument to load must be a string",
"load")
return nil
}
bp := in.Value()
bp = AbsPath(bp)
util.LoadScript(bp, vt, ft)
return nil
}