pkg/terminal: remove deprecated starlark global options (#3722)
This commit is contained in:
parent
7c7265f4e6
commit
468727c34d
@ -1,8 +1,9 @@
|
|||||||
package starbind
|
package starbind
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.starlark.net/starlark"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"go.starlark.net/starlark"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConv(t *testing.T) {
|
func TestConv(t *testing.T) {
|
||||||
@ -10,7 +11,7 @@ func TestConv(t *testing.T) {
|
|||||||
# A list global that we'll unmarshal into a slice.
|
# A list global that we'll unmarshal into a slice.
|
||||||
x = [1,2]
|
x = [1,2]
|
||||||
`
|
`
|
||||||
globals, err := starlark.ExecFile(&starlark.Thread{}, "test.star", script, nil)
|
globals, err := execFileOptions(nil, &starlark.Thread{}, "test.star", script, nil)
|
||||||
starlarkVal, ok := globals["x"]
|
starlarkVal, ok := globals["x"]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("missing global 'x'")
|
t.Fatal("missing global 'x'")
|
||||||
|
|||||||
@ -116,7 +116,7 @@ func rep(rl *liner.State, thread *starlark.Thread, globals starlark.StringDict,
|
|||||||
if expr := soleExpr(f); expr != nil {
|
if expr := soleExpr(f); expr != nil {
|
||||||
//TODO: check for 'exit'
|
//TODO: check for 'exit'
|
||||||
// eval
|
// eval
|
||||||
v, err := starlark.EvalExpr(thread, expr, globals)
|
v, err := evalExprOptions(nil, thread, expr, globals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printError(err)
|
printError(err)
|
||||||
return nil
|
return nil
|
||||||
@ -194,7 +194,7 @@ func MakeLoad() func(thread *starlark.Thread, module string) (starlark.StringDic
|
|||||||
|
|
||||||
// Load it.
|
// Load it.
|
||||||
thread := &starlark.Thread{Name: "exec " + module, Load: thread.Load}
|
thread := &starlark.Thread{Name: "exec " + module, Load: thread.Load}
|
||||||
globals, err := starlark.ExecFile(thread, module, nil, nil)
|
globals, err := execFileOptions(nil, thread, module, nil, nil)
|
||||||
e = &entry{globals, err}
|
e = &entry{globals, err}
|
||||||
|
|
||||||
// Update the cache.
|
// Update the cache.
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
startime "go.starlark.net/lib/time"
|
startime "go.starlark.net/lib/time"
|
||||||
"go.starlark.net/resolve"
|
|
||||||
"go.starlark.net/starlark"
|
"go.starlark.net/starlark"
|
||||||
|
"go.starlark.net/syntax"
|
||||||
|
|
||||||
"github.com/go-delve/delve/service"
|
"github.com/go-delve/delve/service"
|
||||||
"github.com/go-delve/delve/service/api"
|
"github.com/go-delve/delve/service/api"
|
||||||
@ -32,14 +32,12 @@ const (
|
|||||||
helpBuiltinName = "help"
|
helpBuiltinName = "help"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
var defaultSyntaxFileOpts = &syntax.FileOptions{
|
||||||
resolve.AllowNestedDef = true
|
Set: true,
|
||||||
resolve.AllowLambda = true
|
While: true,
|
||||||
resolve.AllowFloat = true
|
TopLevelControl: true,
|
||||||
resolve.AllowSet = true
|
GlobalReassign: true,
|
||||||
resolve.AllowBitwise = true
|
Recursion: true,
|
||||||
resolve.AllowRecursion = true
|
|
||||||
resolve.AllowGlobalReassign = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context is the context in which starlark scripts are evaluated.
|
// Context is the context in which starlark scripts are evaluated.
|
||||||
@ -220,7 +218,7 @@ func (env *Env) Execute(path string, source interface{}, mainFnName string, args
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
thread := env.newThread()
|
thread := env.newThread()
|
||||||
globals, err := starlark.ExecFile(thread, path, source, env.env)
|
globals, err := execFileOptions(nil, thread, path, source, env.env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return starlark.None, err
|
return starlark.None, err
|
||||||
}
|
}
|
||||||
@ -305,7 +303,7 @@ func (env *Env) createCommand(name string, val starlark.Value) error {
|
|||||||
|
|
||||||
env.ctx.RegisterCommand(name, helpMsg, func(args string) error {
|
env.ctx.RegisterCommand(name, helpMsg, func(args string) error {
|
||||||
thread := env.newThread()
|
thread := env.newThread()
|
||||||
argval, err := starlark.Eval(thread, "<input>", "("+args+")", env.env)
|
argval, err := evalOptions(nil, thread, "<input>", "("+args+")", env.env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -369,3 +367,30 @@ type EchoWriter interface {
|
|||||||
Echo(string)
|
Echo(string)
|
||||||
Flush()
|
Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// execFileOptions is a wrapper around starlark.ExecFileOptions.
|
||||||
|
// If no options are provided, it uses default options.
|
||||||
|
func execFileOptions(opts *syntax.FileOptions, thread *starlark.Thread, path string, source any, env starlark.StringDict) (starlark.StringDict, error) {
|
||||||
|
if opts == nil {
|
||||||
|
opts = defaultSyntaxFileOpts
|
||||||
|
}
|
||||||
|
return starlark.ExecFileOptions(opts, thread, path, source, env)
|
||||||
|
}
|
||||||
|
|
||||||
|
// evalOptions is a wrapper around starlark.EvalOptions.
|
||||||
|
// If no options are provided, it uses default options.
|
||||||
|
func evalOptions(opts *syntax.FileOptions, thread *starlark.Thread, path string, source any, env starlark.StringDict) (starlark.Value, error) {
|
||||||
|
if opts == nil {
|
||||||
|
opts = defaultSyntaxFileOpts
|
||||||
|
}
|
||||||
|
return starlark.EvalOptions(opts, thread, path, source, env)
|
||||||
|
}
|
||||||
|
|
||||||
|
// evalExprOptions is a wrapper around starlark.EvalExprOptions.
|
||||||
|
// If no options are provided, it uses default options.
|
||||||
|
func evalExprOptions(opts *syntax.FileOptions, thread *starlark.Thread, expr syntax.Expr, globals starlark.StringDict) (starlark.Value, error) {
|
||||||
|
if opts == nil {
|
||||||
|
opts = defaultSyntaxFileOpts
|
||||||
|
}
|
||||||
|
return starlark.EvalExprOptions(opts, thread, expr, globals)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user