Repository navigation
refactor(parser): parse_value, move reserved keyword values check - #16415
Conversation
|
In general, I like this idea. But the semantics get kind of wobbly. This makes ~> def test [arg: oneof<bool, string>] { $arg }
~> test true | describe
bool
~> def test [arg: oneof<string, bool>] { $arg }
~> test true | describe
stringI think it makes sense to coerce literals (and I think Rust and a few other languages have a distinction between strict and weak keywords. The former are forbidden everywhere while the latter are accepted outside of their position (so With that in mind, I think |
|
@kaathewisegit Yeah, there're nasty edge cases of course. Actually, I don't like this kind of context dependent parsing at all. I chose it just because it feels more consistent given how dynamic current nushell already is. Back to the strict/week keywords topic, I don't see what's the difference between def test [arg: oneof<string, int>] { $arg }; test 1 | describe # => stringwhich has nothing to do with keyword values. I can make it behave closer to current release by an extra match branch like this (we should probably allow them to be parsed as path/directory anyway): match shape {
...
// Check for reserved keyword values
SyntaxShape::String
if matches!(bytes, b"true" | b"false")
|| matches!(
bytes.to_ascii_lowercase().as_slice(),
b"-inf" | b"inf" | b"nan"
) =>
{
working_set.error(ParseError::Expected("string", span));
Expression::garbage(working_set, span)
}
SyntaxShape::String => parse_string(working_set, span),
...
}But again, it feels more confusing/inconsistent to me. |
|
What's worse: > def test [foo: string] {}; test 1 # no error
> let foo: string = 1
Error: nu::parser::type_mismatch
× Type mismatch.
╭─[entry #10:1:19]
1 │ let foo: string = 1
· ┬
· ╰── expected string, found int |
|
Yeah, in that regard following the existing rules sounds like the better idea. I feel that Nushell really needs some kind of a formal-ish grammar. The current parsing situation is all over the place |
I have a lot of expectations for new-nu-parser. |
|
Let's make it a non-breaking change in case some users actually use something like |
6edd7c5 to
86ebd34
Compare
A PoC PR regarding the topic discussed in #16408
Description
Better readability in my opinion.
User-Facing Changes
Release notes summary
Fixes the inconsistent parsing of
inf/INF,NaN/nanTests + Formatting
After Submitting