Skip to content

Commit 7c8e084

Browse files
committed
refactor(parser): parse_value, move reserved keyword values check into the SyntaxShape::Any case
1 parent a4711af commit 7c8e084

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

crates/nu-parser/src/parser.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5198,33 +5198,6 @@ pub fn parse_value(
51985198
return garbage(working_set, span);
51995199
}
52005200

5201-
// Check for reserved keyword values
5202-
match bytes {
5203-
b"true" => {
5204-
if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) {
5205-
return Expression::new(working_set, Expr::Bool(true), span, Type::Bool);
5206-
} else {
5207-
working_set.error(ParseError::ExpectedWithStringMsg(shape.to_string(), span));
5208-
return Expression::garbage(working_set, span);
5209-
}
5210-
}
5211-
b"false" => {
5212-
if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) {
5213-
return Expression::new(working_set, Expr::Bool(false), span, Type::Bool);
5214-
} else {
5215-
working_set.error(ParseError::ExpectedWithStringMsg(shape.to_string(), span));
5216-
return Expression::garbage(working_set, span);
5217-
}
5218-
}
5219-
b"null" => {
5220-
return Expression::new(working_set, Expr::Nothing, span, Type::Nothing);
5221-
}
5222-
b"-inf" | b"inf" | b"NaN" => {
5223-
return parse_float(working_set, span);
5224-
}
5225-
_ => {}
5226-
}
5227-
52285201
match bytes[0] {
52295202
b'$' => return parse_dollar_expr(working_set, span),
52305203
b'(' => return parse_paren_expr(working_set, span, shape),
@@ -5326,6 +5299,23 @@ pub fn parse_value(
53265299
}
53275300

53285301
SyntaxShape::Any => {
5302+
// Check for reserved keyword values
5303+
match bytes {
5304+
b"true" => {
5305+
return Expression::new(working_set, Expr::Bool(true), span, Type::Bool);
5306+
}
5307+
b"false" => {
5308+
return Expression::new(working_set, Expr::Bool(false), span, Type::Bool);
5309+
}
5310+
b"null" => {
5311+
return Expression::new(working_set, Expr::Nothing, span, Type::Nothing);
5312+
}
5313+
b"-inf" | b"inf" | b"NaN" => {
5314+
return parse_float(working_set, span);
5315+
}
5316+
_ => {}
5317+
}
5318+
53295319
if bytes.starts_with(b"[") {
53305320
//parse_value(working_set, span, &SyntaxShape::Table)
53315321
parse_full_cell_path(working_set, None, span)

0 commit comments

Comments
 (0)