runtime(vim): Update base-syntax, match ternary and falsy operators
fixes: #14423 fixes: #16227 closes: #16484 Signed-off-by: Doug Kearns <dougkearns@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
cb848b687f
commit
c273f1ac77
@ -12,7 +12,7 @@ vim9script
|
||||
:help
|
||||
:help
|
||||
: help
|
||||
: help
|
||||
: help # FIXME
|
||||
|
||||
:2match
|
||||
:3match
|
||||
|
||||
@ -2,6 +2,59 @@ vim9script
|
||||
# Vim9-script expressions
|
||||
|
||||
|
||||
# Operators
|
||||
|
||||
# Ternary
|
||||
|
||||
echo expr ? expr : expr
|
||||
|
||||
echo lnum == 1 ? "top" : lnum
|
||||
echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
|
||||
|
||||
echo lnum == 1
|
||||
? "top"
|
||||
: lnum == 1000
|
||||
? "last"
|
||||
: lnum
|
||||
echo lnum == 1 ?
|
||||
"top" :
|
||||
lnum == 1000 ?
|
||||
"last" :
|
||||
lnum
|
||||
|
||||
echo true ? true : false
|
||||
echo 1 ? 1 : 0
|
||||
echo "foo" ? "foo" : "bar"
|
||||
echo foo ? foo : bar
|
||||
echo g:foo ? g:foo : g:bar
|
||||
echo $FOO ? $FOO : $BAR
|
||||
echo True() ? True() : False()
|
||||
echo @a ? @a : @b
|
||||
echo (1) ? (1) : (0)
|
||||
|
||||
# Falsy
|
||||
|
||||
echo expr ?? expr
|
||||
|
||||
echo theList ?? 'list is empty'
|
||||
echo GetName() ?? 'unknown'
|
||||
|
||||
echo theList
|
||||
\ ?? 'list is empty'
|
||||
echo theList ??
|
||||
\ 'list is empty'
|
||||
|
||||
echo true ?? true
|
||||
echo 1 ?? 1
|
||||
echo "foo" ?? "foo"
|
||||
echo foo ?? foo
|
||||
echo g:foo ?? g:foo
|
||||
echo $FOO ?? $FOO
|
||||
echo True() ?? True()
|
||||
echo @a ?? @a
|
||||
echo (1) ?? (1)
|
||||
|
||||
|
||||
# Command {expr} arguments
|
||||
|
||||
if true
|
||||
@ -18,3 +71,37 @@ def Foo(): bool
|
||||
return true
|
||||
enddef
|
||||
|
||||
|
||||
# Issue #14423 (vim.vim: Opt out of vimSearch*)
|
||||
|
||||
:?truthy
|
||||
const truthy: number = false
|
||||
? (0
|
||||
)
|
||||
: (1
|
||||
)
|
||||
echo truthy
|
||||
|
||||
def Foo()
|
||||
:?truthy
|
||||
const truthy: number = false
|
||||
? (0
|
||||
)
|
||||
: (1
|
||||
)
|
||||
echo truthy
|
||||
enddef
|
||||
|
||||
|
||||
# Issue #16227 (Vimscript ternary expression highlighting)
|
||||
|
||||
var foo = 'foo' # comment
|
||||
var bar = foo == 'foo' ? 'bar' : 'baz'
|
||||
var baz = foo == 'foo'
|
||||
\ ? 'baz'
|
||||
\ : 'bar'
|
||||
var qux = foo == 'foo'
|
||||
? 'qux' # comment
|
||||
: 'qux' # comment
|
||||
echo qux ?? 'quux'
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
:help
|
||||
:help
|
||||
: help
|
||||
: help
|
||||
: help # FIXME
|
||||
|
||||
:2match
|
||||
:3match
|
||||
|
||||
@ -87,6 +87,52 @@ echo 0zFF.00.ED.01.5D.AF
|
||||
|
||||
" Operators
|
||||
|
||||
" Ternary
|
||||
echo expr ? expr : expr
|
||||
|
||||
echo lnum == 1 ? "top" : lnum
|
||||
echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
|
||||
|
||||
echo lnum == 1
|
||||
\ ? "top"
|
||||
\ : lnum == 1000
|
||||
\ ? "last"
|
||||
\ : lnum
|
||||
echo lnum == 1 ?
|
||||
\ "top" :
|
||||
\ lnum == 1000 ?
|
||||
\ "last" :
|
||||
\ lnum
|
||||
|
||||
echo 1 ? 1 : 0
|
||||
echo "foo" ? "foo" : "bar"
|
||||
echo foo ? foo : bar
|
||||
echo g:foo ? g:foo : g:bar
|
||||
echo $FOO ? $FOO : $BAR
|
||||
echo True() ? True() : False()
|
||||
echo @a ? @a : @b
|
||||
echo (1) ? (1) : (0)
|
||||
|
||||
" Falsy
|
||||
echo expr ?? expr
|
||||
|
||||
echo theList ?? 'list is empty'
|
||||
echo GetName() ?? 'unknown'
|
||||
|
||||
echo theList
|
||||
\ ?? 'list is empty'
|
||||
echo theList ??
|
||||
\ 'list is empty'
|
||||
|
||||
echo 1 ?? 1
|
||||
echo "foo" ?? "foo"
|
||||
echo foo ?? foo
|
||||
echo g:foo ?? g:foo
|
||||
echo $FOO ?? $FOO
|
||||
echo True() ?? True()
|
||||
echo @a ?? @a
|
||||
echo (1) ?? (1)
|
||||
|
||||
" Comparison - using 'ignorcase'
|
||||
echo expr == expr
|
||||
echo expr != expr
|
||||
@ -126,6 +172,28 @@ echo expr isnot? expr
|
||||
" Unreported issue (incorrectly matches as "echo vimNumber *vimCommand* vimNumber")
|
||||
echo 42 is 42
|
||||
|
||||
|
||||
" Issue #16221 (vimString becomes vimVar when preceded by !)
|
||||
let bar = !'g:bar'->exists()
|
||||
|
||||
|
||||
" Issue #14423 (vim.vim: Opt out of vimSearch*)
|
||||
|
||||
?truthy
|
||||
let truthy = 0
|
||||
\ ? (0
|
||||
\ )
|
||||
\ : (1
|
||||
\ )
|
||||
echo truthy
|
||||
|
||||
function Foo()
|
||||
?truthy
|
||||
let truthy = 0
|
||||
\ ? (0
|
||||
\ )
|
||||
\ : (1
|
||||
\ )
|
||||
echo truthy
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user