mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 23:24:39 +00:00
fix handling of line continuation in keywords
This behavior is more consistent with line continuation in strings other than keywords. Fixes #2897
This commit is contained in:
parent
6adc35c636
commit
2d5eaed745
5 changed files with 39 additions and 3 deletions
|
@ -1254,6 +1254,12 @@ static parse_keyword_t keyword_with_name(const wchar_t *name)
|
|||
return result;
|
||||
}
|
||||
|
||||
static bool is_keyword_char(wchar_t c)
|
||||
{
|
||||
return (c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z') || (c >= L'0' && c <= L'9')
|
||||
|| c == L'\'' || c == L'"' || c == L'\\' || c == '\n';
|
||||
}
|
||||
|
||||
/* Given a token, returns the keyword it matches, or parse_keyword_none. */
|
||||
static parse_keyword_t keyword_for_token(token_type tok, const wcstring &token)
|
||||
{
|
||||
|
@ -1267,17 +1273,16 @@ static parse_keyword_t keyword_for_token(token_type tok, const wcstring &token)
|
|||
parse_keyword_t result = parse_keyword_none;
|
||||
bool needs_expand = false, all_chars_valid = true;
|
||||
const wchar_t *tok_txt = token.c_str();
|
||||
const wchar_t *chars_allowed_in_keywords = L"abcdefghijklmnopqrstuvwxyz'\"";
|
||||
for (size_t i=0; tok_txt[i] != L'\0'; i++)
|
||||
{
|
||||
wchar_t c = tok_txt[i];
|
||||
if (! wcschr(chars_allowed_in_keywords, c))
|
||||
if (! is_keyword_char(c))
|
||||
{
|
||||
all_chars_valid = false;
|
||||
break;
|
||||
}
|
||||
// If we encounter a quote, we need expansion
|
||||
needs_expand = needs_expand || c == L'"' || c == L'\'';
|
||||
needs_expand = needs_expand || c == L'"' || c == L'\'' || c == L'\\';
|
||||
}
|
||||
|
||||
if (all_chars_valid)
|
||||
|
|
0
tests/line-continuation.err
Normal file
0
tests/line-continuation.err
Normal file
25
tests/line-continuation.in
Normal file
25
tests/line-continuation.in
Normal file
|
@ -0,0 +1,25 @@
|
|||
ech\
|
||||
o echo
|
||||
|
||||
buil\
|
||||
tin echo builtin echo
|
||||
|
||||
true; an\
|
||||
d echo true
|
||||
|
||||
\i\
|
||||
\U00000066\
|
||||
true
|
||||
echo if true
|
||||
\
|
||||
\145n\
|
||||
d\
|
||||
;
|
||||
|
||||
'if'\
|
||||
true
|
||||
echo if true
|
||||
"\
|
||||
en\
|
||||
d\
|
||||
";
|
5
tests/line-continuation.out
Normal file
5
tests/line-continuation.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
echo
|
||||
builtin echo
|
||||
true
|
||||
if true
|
||||
if true
|
1
tests/line-continuation.status
Normal file
1
tests/line-continuation.status
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
Loading…
Reference in a new issue