/* SHS: Syntactically Homogeneous Shell * Copyright (C) 2019 Aidan Hahn * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package ast func (t *Token) Eval(funcs FuncTable, vars VarTable) *Token { if t == nil { return nil } var iter *Token eligibleForSystemCall := true var reduce func(*Token) *Token reduce = func(t_ *Token) *Token { if t_.Next != nil { t_.Next = reduce(t_.Next) } switch (t_.Tag) { case SYMBOL: maybeToken := GetVar(t_.Inner.(string), vars) if maybeToken != nil { tok := maybeToken.Eval(funcs, vars) if tok == LIST { eligibleForSystemCall = false } } case LIST: eligibleForSystemCall = false t.Inner = Eval(t_.Inner) } return t_ } ret := reduce(t) if ret.Tag == SYMBOL { f := funcs.GetFunction(ret.Inner) if f == nil { if !eligibleForSystemCall { // TODO: log error return nil } // hook into stdlib exec return } return (*f).CallFunction(ret.Next) } return ret }