Removed eval() function from ast interface and implementation. Check on preset control variables is now done in initDefaultVars()
This commit is contained in:
+50
-18
@@ -8,10 +8,11 @@ import "strings"
|
||||
|
||||
// Preset control variables
|
||||
const (
|
||||
ControlLastResult = "last"
|
||||
ControlBoolShortcut = "_bool_shortcut"
|
||||
ControlImportPath = "_import_path"
|
||||
ControlPluginPath = "_plugin_path"
|
||||
ControlPreset = "_preset"
|
||||
ControlLastResult = "last"
|
||||
ControlBoolShortcut = "_bool_shortcut"
|
||||
ControlSearchPath = "_search_path"
|
||||
ControlParentContext = "_parent_context"
|
||||
)
|
||||
|
||||
// Other control variables
|
||||
@@ -21,30 +22,61 @@ const (
|
||||
|
||||
// Initial values
|
||||
const (
|
||||
init_import_path = "~/.local/lib/go-pkg/expr/sources:/usr/local/lib/go-pkg/expr/sources:/usr/lib/go-pkg/expr/sources"
|
||||
init_plugin_path = "~/.local/lib/go-pkg/expr/plugins:/usr/local/lib/go-pkg/expr/plugins:/usr/lib/go-pkg/expr/plugins"
|
||||
init_search_path = "~/.local/lib/go-pkg/expr:/usr/local/lib/go-pkg/expr:/usr/lib/go-pkg/expr"
|
||||
)
|
||||
|
||||
func initDefaultVars(ctx ExprContext) {
|
||||
if _, exists := ctx.GetVar(ControlPreset); exists {
|
||||
return
|
||||
}
|
||||
ctx.SetVar(ControlPreset, true)
|
||||
ctx.SetVar(ControlBoolShortcut, true)
|
||||
ctx.SetVar(ControlImportPath, init_import_path)
|
||||
ctx.SetVar(ControlPluginPath, init_plugin_path)
|
||||
ctx.SetVar(ControlSearchPath, init_search_path)
|
||||
}
|
||||
|
||||
func enable(ctx ExprContext, name string) {
|
||||
if strings.HasPrefix(name, "_") {
|
||||
ctx.SetVar(name, true)
|
||||
} else {
|
||||
ctx.SetVar("_"+name, true)
|
||||
func CtrlEnable(ctx ExprContext, name string) (currentStatus bool) {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
if v, exists := ctx.GetVar(name); exists && IsBool(v) {
|
||||
currentStatus, _ = v.(bool)
|
||||
}
|
||||
|
||||
ctx.SetVar(name, true)
|
||||
return currentStatus
|
||||
}
|
||||
|
||||
func disable(ctx ExprContext, name string) {
|
||||
if strings.HasPrefix(name, "_") {
|
||||
ctx.SetVar(name, false)
|
||||
} else {
|
||||
ctx.SetVar("_"+name, false)
|
||||
func CtrlDisable(ctx ExprContext, name string) (currentStatus bool) {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
if v, exists := ctx.GetVar(name); exists && IsBool(v) {
|
||||
currentStatus, _ = v.(bool)
|
||||
}
|
||||
|
||||
ctx.SetVar(name, false)
|
||||
return currentStatus
|
||||
}
|
||||
|
||||
func CtrlSet(ctx ExprContext, name string, newValue any) (currentValue any) {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
currentValue, _ = ctx.GetVar(name)
|
||||
|
||||
ctx.SetVar(name, newValue)
|
||||
for parent := ctx.GetParent(); parent != nil; parent = parent.GetParent() {
|
||||
parent.SetVar(name, newValue)
|
||||
}
|
||||
return currentValue
|
||||
}
|
||||
|
||||
func CtrlGet(ctx ExprContext, name string) (currentValue any) {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
currentValue, _ = ctx.GetVar(name)
|
||||
return currentValue
|
||||
}
|
||||
|
||||
func isEnabled(ctx ExprContext, name string) (status bool) {
|
||||
|
||||
Reference in New Issue
Block a user