mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 07:04:29 +00:00
math: Nicer error for non-ascii-lowercase identifiers
This gave a weird error when you did e.g. `math Foo / 6`: "Missing Operator" and only the "F" marked. Adding an operator here anywhere won't help, so calling this an "Unknown function" is closer to the truth. We also get nicer markings because we know the extent of the identifier.
This commit is contained in:
parent
fc7be1c2a3
commit
cdcf460edf
2 changed files with 10 additions and 2 deletions
|
@ -405,12 +405,14 @@ impl<'s> State<'s> {
|
|||
// Look for a function call.
|
||||
// But not when it's an "x" followed by whitespace
|
||||
// - that's the alternative multiplication operator.
|
||||
if next.first()?.is_ascii_lowercase()
|
||||
// We look for alphabetic here even tho all our function names are ASCII,
|
||||
// in order to give a nicer error.
|
||||
if next.first()?.is_alphabetic()
|
||||
&& !(*next.first()? == 'x' && next.len() > 1 && next[1].is_whitespace())
|
||||
{
|
||||
let ident_len = next
|
||||
.iter()
|
||||
.position(|&c| !(c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_'))
|
||||
.position(|&c| !(c.is_alphabetic() || c.is_ascii_digit() || c == '_'))
|
||||
.unwrap_or(next.len());
|
||||
|
||||
let ident = &next[..ident_len];
|
||||
|
|
|
@ -127,6 +127,12 @@ not math 'blah()'
|
|||
# CHECKERR: 'blah()'
|
||||
# CHECKERR: ^~~^
|
||||
|
||||
# There is also no "Blah" function.
|
||||
not math 'Blah()'
|
||||
# CHECKERR: math: Error: Unknown function
|
||||
# CHECKERR: 'Blah()'
|
||||
# CHECKERR: ^~~^
|
||||
|
||||
math n + 4
|
||||
# CHECKERR: math: Error: Unknown function
|
||||
# CHECKERR: 'n + 4'
|
||||
|
|
Loading…
Reference in a new issue