mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-19 09:52:46 +08:00

Unlike other builtins, "{" is a separate token, not a keyword-string token. Allow the left brace token as command string; produce it when parsing "{ -h"/"{ --help" (and nowhere else). By using a decorated statement, we reuse logic for redirections etc. Other syntax elements like "and" are in the builtin list, which - adds highlighting logic - adds it to "builtin --names" - makes it runnable as builtin (e.g. "builtin '{'" would hypothetically print the man page) These don't seem very important (highlighting for '{' needs to match '}' anyway). Additionally, making it a real builtin would mean that we'd need to deactivate a few places that unescape "{" to BRACE_BEGIN. Let's not add it to the built in list. Instead, simply synthesize builtin_generic in the right spot. I'm assuming we want "{ -h" to print help, but '"{" -h' to run an external command, since the latter is historical behavior. This works naturally with the above fake builtin approach which never tries to unescape the left brace.
225 lines
4.1 KiB
Fish
225 lines
4.1 KiB
Fish
#RUN: %fish %s
|
|
|
|
echo x-{1}
|
|
#CHECK: x-{1}
|
|
|
|
echo x-{1,2}
|
|
#CHECK: x-1 x-2
|
|
|
|
echo foo-{1,2{3,4}}
|
|
#CHECK: foo-1 foo-23 foo-24
|
|
|
|
echo foo-{} # literal "{}" expands to itself
|
|
#CHECK: foo-{}
|
|
|
|
echo foo-{{},{}} # the inner "{}" expand to themselves, the outer pair expands normally.
|
|
#CHECK: foo-{} foo-{}
|
|
|
|
echo foo-{{a},{}} # also works with something in the braces.
|
|
#CHECK: foo-{a} foo-{}
|
|
|
|
echo foo-{""} # still expands to foo-{}
|
|
#CHECK: foo-{}
|
|
|
|
echo foo-{$undefinedvar} # still expands to nothing
|
|
#CHECK:
|
|
|
|
echo foo-{,,,} # four empty items in the braces.
|
|
#CHECK: foo- foo- foo- foo-
|
|
|
|
echo foo-{,\,,} # an empty item, a "," and an empty item.
|
|
#CHECK: foo- foo-, foo-
|
|
|
|
echo .{ foo bar }. # see 6564
|
|
#CHECK: .{ foo bar }.
|
|
|
|
# whitespace within entries is retained
|
|
for foo in {a, hello
|
|
wo rld }
|
|
echo \'$foo\'
|
|
end
|
|
# CHECK: 'a'
|
|
# CHECK: 'hello
|
|
# CHECK: wo rld'
|
|
|
|
for foo in {hello
|
|
world}
|
|
echo \'$foo\'
|
|
end
|
|
#CHECK: '{hello
|
|
#CHECK: world}'
|
|
|
|
echo {a(echo ,)b}
|
|
#CHECK: {a,b}
|
|
|
|
e{cho,cho,cho}
|
|
# CHECK: echo echo
|
|
|
|
## Compound commands
|
|
|
|
{ echo compound; echo command; }
|
|
# CHECK: compound
|
|
# CHECK: command
|
|
|
|
{;echo -n start with\ ; echo semi; }
|
|
# CHECK: start with semi
|
|
|
|
{ echo no semi }
|
|
# CHECK: no semi
|
|
|
|
# Ambiguous cases
|
|
|
|
{ echo ,comma;}
|
|
# CHECK: ,comma
|
|
|
|
PATH= {echo no space}
|
|
# CHECKERR: fish: Unknown command: '{echo no space}'
|
|
# CHECKERR: {{.*}}/braces.fish (line {{\d+}}):
|
|
# CHECKERR: PATH= {echo no space}
|
|
# CHECKERR: ^~~~~~~~~~~~~~^
|
|
|
|
PATH= {echo comma, no space;}
|
|
# CHECKERR: fish: Unknown command: 'echo comma'
|
|
# CHECKERR: {{.*}}/braces.fish (line {{\d+}}):
|
|
# CHECKERR: PATH= {echo comma, no space;}
|
|
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~^
|
|
|
|
# Ambiguous case with no space
|
|
{echo,hello}
|
|
# CHECK: hello
|
|
|
|
# Trailing tokens
|
|
set -l fish (status fish-path)
|
|
$fish -c '{ :; } true'
|
|
# CHECKERR: fish: '}' does not take arguments. Did you forget a ';'?
|
|
# CHECKERR: { :; } true
|
|
# CHECKERR: ^~~^
|
|
|
|
; { echo semi; }
|
|
# CHECK: semi
|
|
|
|
a=b { echo $a; }
|
|
# CHECK: b
|
|
|
|
time { :; }
|
|
# CHECKERR:
|
|
# CHECKERR: {{_+}}
|
|
# CHECKERR: Executed in {{.*}}
|
|
# CHECKERR: usr time {{.*}}
|
|
# CHECKERR: sys time {{.*}}
|
|
|
|
true & { echo background; }
|
|
# CHECK: background
|
|
|
|
true && { echo conjunction; }
|
|
# CHECK: conjunction
|
|
|
|
true; and { echo and; }
|
|
# CHECK: and
|
|
|
|
true | { echo pipe; }
|
|
# CHECK: pipe
|
|
|
|
true 2>| { echo stderrpipe; }
|
|
# CHECK: stderrpipe
|
|
|
|
false || { echo disjunction; }
|
|
# CHECK: disjunction
|
|
|
|
false; or { echo or; }
|
|
# CHECK: or
|
|
|
|
begin { echo begin }
|
|
end
|
|
# CHECK: begin
|
|
|
|
not { false; true }
|
|
echo $status
|
|
# CHECK: 1
|
|
|
|
! { false }
|
|
echo $status
|
|
# CHECK: 0
|
|
|
|
if { set -l a true; $a && true }
|
|
echo if-true
|
|
end
|
|
# CHECK: if-true
|
|
|
|
{
|
|
set -l condition true
|
|
while $condition
|
|
{
|
|
echo while
|
|
set condition false
|
|
}
|
|
end
|
|
}
|
|
# CHECK: while
|
|
|
|
{ { echo inner}
|
|
echo outer}
|
|
# CHECK: inner
|
|
# CHECK: outer
|
|
|
|
{
|
|
|
|
echo leading blank lines
|
|
}
|
|
# CHECK: leading blank lines
|
|
|
|
complete foo -a '123 456'
|
|
complete -C 'foo {' | sed 1q
|
|
# CHECK: {{\{.*}}
|
|
|
|
complete -C '{'
|
|
echo nothing
|
|
# CHECK: nothing
|
|
complete -C '{ ' | grep ^if\t
|
|
# CHECK: if{{\t}}Evaluate block if condition is true
|
|
|
|
$fish -c '{'
|
|
# CHECKERR: fish: Expected a '}', but found end of the input
|
|
|
|
PATH= "{"
|
|
# CHECKERR: fish: Unknown command: '{'
|
|
# CHECKERR: {{.*}}/braces.fish (line {{\d+}}):
|
|
# CHECKERR: PATH= "{"
|
|
# CHECKERR: ^~^
|
|
|
|
$fish -c '{ -h'
|
|
# CHECKERR: fish: '{': missing man page
|
|
# CHECKERR: Documentation may not be installed.
|
|
# CHECKERR: `help '{'` will show an online version
|
|
|
|
PATH= "{" -h
|
|
# CHECKERR: fish: Unknown command: '{'
|
|
# CHECKERR: {{.*}}/braces.fish (line {{\d+}}):
|
|
# CHECKERR: PATH= "{" -h
|
|
# CHECKERR: ^~^
|
|
|
|
$fish -c 'builtin {'
|
|
# CHECKERR: fish: Expected end of the statement, but found a '{'
|
|
# CHECKERR: builtin {
|
|
# CHECKERR: ^
|
|
|
|
$fish -c 'builtin "{"'
|
|
# CHECKERR: fish: Unknown builtin '"{"'
|
|
# CHECKERR: builtin "{"
|
|
# CHECKERR: ^~~~~~~~~~^
|
|
|
|
$fish -c 'command {'
|
|
# CHECKERR: fish: Expected end of the statement, but found a '{'
|
|
# CHECKERR: command {
|
|
# CHECKERR: ^
|
|
|
|
$fish -c 'exec {'
|
|
# CHECKERR: fish: Expected end of the statement, but found a '{'
|
|
# CHECKERR: exec {
|
|
# CHECKERR: ^
|
|
|
|
$fish -c 'begin; }'
|
|
# CHECKERR: fish: Unexpected '}' for unopened brace
|
|
# CHECKERR: begin; }
|
|
# CHECKERR: ^
|