call system executables from undefined function calls
This commit is contained in:
parent
40fba4716b
commit
ffef8a96e7
4 changed files with 26 additions and 16 deletions
21
ast/eval.go
21
ast/eval.go
|
|
@ -19,6 +19,9 @@ package ast
|
||||||
|
|
||||||
import "gitlab.com/whom/shs/log"
|
import "gitlab.com/whom/shs/log"
|
||||||
|
|
||||||
|
var CallExecutablesFromUndefFuncCalls = false
|
||||||
|
var CallExecutableToken = "l"
|
||||||
|
|
||||||
func (t *Token) Eval(funcs FuncTable, vars VarTable) (*Token, bool) {
|
func (t *Token) Eval(funcs FuncTable, vars VarTable) (*Token, bool) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
|
|
@ -69,13 +72,29 @@ func (t *Token) Eval(funcs FuncTable, vars VarTable) (*Token, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if symbol in front of a list, could be a function call
|
||||||
if ret.Tag == SYMBOL {
|
if ret.Tag == SYMBOL {
|
||||||
f := GetFunction(ret.Inner.(string), funcs)
|
f := GetFunction(ret.Inner.(string), funcs)
|
||||||
if f == nil {
|
if f == nil {
|
||||||
|
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,
|
log.Log(log.DEBUG,
|
||||||
"could not find definition for symbol " + ret.Inner.(string),
|
"could not find definition for symbol " + ret.Inner.(string),
|
||||||
"eval")
|
"eval")
|
||||||
return nil, false
|
return ret, false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*f).CallFunction(ret.Next, vars, funcs), true
|
return (*f).CallFunction(ret.Next, vars, funcs), true
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ func setLogLvl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
ast.CallExecutablesFromUndefFuncCalls = true
|
||||||
|
|
||||||
debug := os.Getenv("SH_DEBUG_MODE")
|
debug := os.Getenv("SH_DEBUG_MODE")
|
||||||
hist := os.Getenv("SH_HIST_FILE")
|
hist := os.Getenv("SH_HIST_FILE")
|
||||||
prompt := os.Getenv("SHS_SH_PROMPT")
|
prompt := os.Getenv("SHS_SH_PROMPT")
|
||||||
|
|
|
||||||
7
go.mod
7
go.mod
|
|
@ -2,9 +2,4 @@ module gitlab.com/whom/shs
|
||||||
|
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
|
||||||
gitlab.com/whom/shs/ast v0.0.0-20200628205108-baa4ce030060 // indirect
|
|
||||||
gitlab.com/whom/shs/log v0.0.0-20200628205108-baa4ce030060 // indirect
|
|
||||||
gitlab.com/whom/shs/stdlib v0.0.0-20200628205108-baa4ce030060 // indirect
|
|
||||||
)
|
|
||||||
|
|
|
||||||
6
go.sum
6
go.sum
|
|
@ -1,8 +1,2 @@
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||||
gitlab.com/whom/shs/ast v0.0.0-20200628205108-baa4ce030060 h1:q8VtryYSdSIeYlgJbZswVUAjy0LvmMsydQZmi1Qb+gc=
|
|
||||||
gitlab.com/whom/shs/ast v0.0.0-20200628205108-baa4ce030060/go.mod h1:uez84wOTSf9wSv/Um4BOhpsZgRNN8xkRRCZ86k7M7uU=
|
|
||||||
gitlab.com/whom/shs/log v0.0.0-20200628205108-baa4ce030060 h1:9kXRXS6ItnGKJlavvevLiIMJZVVipWlhCDwKmi+7600=
|
|
||||||
gitlab.com/whom/shs/log v0.0.0-20200628205108-baa4ce030060/go.mod h1:ns9Wf5kw0cdOZH8SDcGpUiSwlABF+XTZBJwZyzQdM/w=
|
|
||||||
gitlab.com/whom/shs/stdlib v0.0.0-20200628205108-baa4ce030060 h1:Khuo4tniRsU2fGYiRbyucS5l8UksSvfdLkNb6ivq4/A=
|
|
||||||
gitlab.com/whom/shs/stdlib v0.0.0-20200628205108-baa4ce030060/go.mod h1:noPvbzvyEtapi7VS/D/tcSBAM3cXUU+/AtkBNJWBnn4=
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue