mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
pkg/eval: Allow "var a:".
This commit is contained in:
parent
76c23aa7b0
commit
a16cd8dfa6
|
@ -90,7 +90,7 @@ func compileVar(cp *compiler, fn *parse.Form) effectOp {
|
|||
}
|
||||
|
||||
name := pn.Value
|
||||
if strings.Contains(name, NsSuffix) {
|
||||
if !IsUnqualified(name) {
|
||||
cp.errorpf(cn, "variable declared in var must be unqualified")
|
||||
}
|
||||
sigil, name := SplitSigil(name)
|
||||
|
@ -108,6 +108,12 @@ func compileVar(cp *compiler, fn *parse.Form) effectOp {
|
|||
return nopOp{}
|
||||
}
|
||||
|
||||
// IsUnqualified returns whether name is an unqualified variable name.
|
||||
func IsUnqualified(name string) bool {
|
||||
i := strings.IndexByte(name, ':')
|
||||
return i == -1 || i == len(name)-1
|
||||
}
|
||||
|
||||
// SetForm = 'set' { LHS } '=' { Compound }
|
||||
func compileSet(cp *compiler, fn *parse.Form) effectOp {
|
||||
eq := -1
|
||||
|
|
|
@ -20,6 +20,8 @@ func TestVar(t *testing.T) {
|
|||
That("var x", "put $x").Puts(nil),
|
||||
// Declaring one variable whose name needs to be quoted
|
||||
That("var 'a/b'", "put $'a/b'").Puts(nil),
|
||||
// Declaring one variable whose name ends in ":".
|
||||
That("var a:").DoesNothing(),
|
||||
// Declaring multiple variables
|
||||
That("var x y", "put $x $y").Puts(nil, nil),
|
||||
// Declaring one variable with initial value
|
||||
|
|
Loading…
Reference in New Issue
Block a user