call system executables from undefined function calls

This commit is contained in:
Aidan 2020-06-28 14:13:44 -07:00
parent 40fba4716b
commit ffef8a96e7
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 26 additions and 16 deletions

View file

@ -19,6 +19,9 @@ package ast
import "gitlab.com/whom/shs/log"
var CallExecutablesFromUndefFuncCalls = false
var CallExecutableToken = "l"
func (t *Token) Eval(funcs FuncTable, vars VarTable) (*Token, bool) {
if t == nil {
return nil, false
@ -69,13 +72,29 @@ func (t *Token) Eval(funcs FuncTable, vars VarTable) (*Token, bool) {
return nil, false
}
//if symbol in front of a list, could be a function call
if ret.Tag == SYMBOL {
f := GetFunction(ret.Inner.(string), funcs)
if f == nil {
log.Log(log.DEBUG,
"could not find definition for symbol " + ret.Inner.(string),
"eval")
return nil, false
if CallExecutablesFromUndefFuncCalls {
f = GetFunction(CallExecutableToken, funcs)
if f == nil {
log.Log(log.DEBUG, "Symbol " + ret.Inner.(string) +
" has no definition in function table. Additionally " +
"the configured LoadExecutableToken is also not defined",
"eval")
return ret, false
}
// see the use of CallFunction below
ret = &Token{Next: ret}
} else {
log.Log(log.DEBUG,
"could not find definition for symbol " + ret.Inner.(string),
"eval")
return ret, false
}
}
return (*f).CallFunction(ret.Next, vars, funcs), true