control: exported all control variables by renaming them in upper case

This commit is contained in:
Celestino Amoroso 2024-04-13 05:16:23 +02:00
parent ad6b4b872f
commit 838ab9fd7e
4 changed files with 9 additions and 9 deletions

2
ast.go
View File

@ -119,7 +119,7 @@ func (self *ast) eval(ctx ExprContext, preset bool) (result any, err error) {
if self.forest != nil { if self.forest != nil {
for _, root := range self.forest { for _, root := range self.forest {
if result, err = root.compute(ctx); err == nil { if result, err = root.compute(ctx); err == nil {
ctx.SetVar(control_last_result, result) ctx.SetVar(ControlLastResult, result)
} else { } else {
//err = fmt.Errorf("error in expression nr %d: %v", i+1, err) //err = fmt.Errorf("error in expression nr %d: %v", i+1, err)
break break

View File

@ -5,9 +5,9 @@ import "strings"
// Preset control variables // Preset control variables
const ( const (
control_last_result = "_last" ControlLastResult = "last"
control_bool_shortcut = "_bool_shortcut" ControlBoolShortcut = "_bool_shortcut"
control_import_path = "_import_path" ControlImportPath = "_import_path"
) )
// Other control variables // Other control variables
@ -21,8 +21,8 @@ const (
) )
func initDefaultVars(ctx ExprContext) { func initDefaultVars(ctx ExprContext) {
ctx.SetVar(control_bool_shortcut, true) ctx.SetVar(ControlBoolShortcut, true)
ctx.SetVar(control_import_path, init_import_path) ctx.SetVar(ControlImportPath, init_import_path)
} }
func enable(ctx ExprContext, name string) { func enable(ctx ExprContext, name string) {

View File

@ -51,7 +51,7 @@ func addEnvImportDirs(dirList []string) []string {
} }
func addPresetImportDirs(ctx ExprContext, dirList []string) []string { func addPresetImportDirs(ctx ExprContext, dirList []string) []string {
if dirSpec, exists := getControlString(ctx, control_import_path); exists { if dirSpec, exists := getControlString(ctx, ControlImportPath); exists {
dirs := strings.Split(dirSpec, ":") dirs := strings.Split(dirSpec, ":")
if dirList == nil { if dirList == nil {
dirList = dirs dirList = dirs

View File

@ -48,7 +48,7 @@ func newAndTerm(tk *Token) (inst *term) {
} }
func evalAnd(ctx ExprContext, self *term) (v any, err error) { func evalAnd(ctx ExprContext, self *term) (v any, err error) {
if isEnabled(ctx, control_bool_shortcut) { if isEnabled(ctx, ControlBoolShortcut) {
v, err = evalAndWithShortcut(ctx, self) v, err = evalAndWithShortcut(ctx, self)
} else { } else {
v, err = evalAndWithoutShortcut(ctx, self) v, err = evalAndWithoutShortcut(ctx, self)
@ -117,7 +117,7 @@ func newOrTerm(tk *Token) (inst *term) {
} }
func evalOr(ctx ExprContext, self *term) (v any, err error) { func evalOr(ctx ExprContext, self *term) (v any, err error) {
if isEnabled(ctx, control_bool_shortcut) { if isEnabled(ctx, ControlBoolShortcut) {
v, err = evalOrWithShortcut(ctx, self) v, err = evalOrWithShortcut(ctx, self)
} else { } else {
v, err = evalOrWithoutShortcut(ctx, self) v, err = evalOrWithoutShortcut(ctx, self)