@@ -5254,33 +5254,6 @@ pub fn parse_value(
52545254 return garbage ( working_set, span) ;
52555255 }
52565256
5257- // Check for reserved keyword values
5258- match bytes {
5259- b"true" => {
5260- if matches ! ( shape, SyntaxShape :: Boolean ) || matches ! ( shape, SyntaxShape :: Any ) {
5261- return Expression :: new ( working_set, Expr :: Bool ( true ) , span, Type :: Bool ) ;
5262- } else {
5263- working_set. error ( ParseError :: ExpectedWithStringMsg ( shape. to_string ( ) , span) ) ;
5264- return Expression :: garbage ( working_set, span) ;
5265- }
5266- }
5267- b"false" => {
5268- if matches ! ( shape, SyntaxShape :: Boolean ) || matches ! ( shape, SyntaxShape :: Any ) {
5269- return Expression :: new ( working_set, Expr :: Bool ( false ) , span, Type :: Bool ) ;
5270- } else {
5271- working_set. error ( ParseError :: ExpectedWithStringMsg ( shape. to_string ( ) , span) ) ;
5272- return Expression :: garbage ( working_set, span) ;
5273- }
5274- }
5275- b"null" => {
5276- return Expression :: new ( working_set, Expr :: Nothing , span, Type :: Nothing ) ;
5277- }
5278- b"-inf" | b"inf" | b"NaN" => {
5279- return parse_float ( working_set, span) ;
5280- }
5281- _ => { }
5282- }
5283-
52845257 match bytes[ 0 ] {
52855258 b'$' => return parse_dollar_expr ( working_set, span) ,
52865259 b'(' => return parse_paren_expr ( working_set, span, shape) ,
@@ -5299,12 +5272,12 @@ pub fn parse_value(
52995272 . iter ( )
53005273 . any ( |s| matches ! ( s, SyntaxShape :: List ( _) ) )
53015274 {
5302- working_set. error ( ParseError :: Expected ( "non-[] value" , span) ) ;
5275+ working_set. error ( ParseError :: ExpectedWithStringMsg ( shape . to_string ( ) , span) ) ;
53035276 return Expression :: garbage ( working_set, span) ;
53045277 }
53055278 }
53065279 _ => {
5307- working_set. error ( ParseError :: Expected ( "non-[] value" , span) ) ;
5280+ working_set. error ( ParseError :: ExpectedWithStringMsg ( shape . to_string ( ) , span) ) ;
53085281 return Expression :: garbage ( working_set, span) ;
53095282 }
53105283 } ,
@@ -5324,49 +5297,43 @@ pub fn parse_value(
53245297 SyntaxShape :: Range => {
53255298 parse_range ( working_set, span) . unwrap_or_else ( || garbage ( working_set, span) )
53265299 }
5300+ // Check for reserved keyword values
5301+ SyntaxShape :: Nothing | SyntaxShape :: Any if bytes == b"null" => {
5302+ Expression :: new ( working_set, Expr :: Nothing , span, Type :: Nothing )
5303+ }
5304+ SyntaxShape :: Boolean | SyntaxShape :: Any if bytes == b"true" => {
5305+ Expression :: new ( working_set, Expr :: Bool ( true ) , span, Type :: Bool )
5306+ }
5307+ SyntaxShape :: Boolean | SyntaxShape :: Any if bytes == b"false" => {
5308+ Expression :: new ( working_set, Expr :: Bool ( false ) , span, Type :: Bool )
5309+ }
5310+ SyntaxShape :: Filepath
5311+ | SyntaxShape :: Directory
5312+ | SyntaxShape :: GlobPattern
5313+ // TODO: this serves for backward compatibility.
5314+ // As a consequence, for commands like `def foo [foo: string] {}`,
5315+ // it forbids usage like `foo true`, have to call it explicitly with `foo "true"`.
5316+ // On the other hand, given current `SyntaxShape` based `parse_value`, `foo 10.0` doesn't raise any error.
5317+ // We want to fix this discrepancy in the future.
5318+ | SyntaxShape :: String
5319+ if matches ! ( bytes, b"true" | b"false" | b"null" ) =>
5320+ {
5321+ working_set. error ( ParseError :: ExpectedWithStringMsg ( shape. to_string ( ) , span) ) ;
5322+ garbage ( working_set, span)
5323+ }
53275324 SyntaxShape :: Filepath => parse_filepath ( working_set, span) ,
53285325 SyntaxShape :: Directory => parse_directory ( working_set, span) ,
53295326 SyntaxShape :: GlobPattern => parse_glob_pattern ( working_set, span) ,
53305327 SyntaxShape :: String => parse_string ( working_set, span) ,
53315328 SyntaxShape :: Binary => parse_binary ( working_set, span) ,
5332- SyntaxShape :: Signature => {
5333- if bytes. starts_with ( b"[" ) {
5334- parse_signature ( working_set, span)
5335- } else {
5336- working_set. error ( ParseError :: Expected ( "signature" , span) ) ;
5337-
5338- Expression :: garbage ( working_set, span)
5339- }
5340- }
5341- SyntaxShape :: List ( elem) => {
5342- if bytes. starts_with ( b"[" ) {
5343- parse_table_expression ( working_set, span, elem)
5344- } else {
5345- working_set. error ( ParseError :: Expected ( "list" , span) ) ;
5346-
5347- Expression :: garbage ( working_set, span)
5348- }
5329+ SyntaxShape :: Signature if bytes. starts_with ( b"[" ) => parse_signature ( working_set, span) ,
5330+ SyntaxShape :: List ( elem) if bytes. starts_with ( b"[" ) => {
5331+ parse_table_expression ( working_set, span, elem)
53495332 }
5350- SyntaxShape :: Table ( _) => {
5351- if bytes. starts_with ( b"[" ) {
5352- parse_table_expression ( working_set, span, & SyntaxShape :: Any )
5353- } else {
5354- working_set. error ( ParseError :: Expected ( "table" , span) ) ;
5355-
5356- Expression :: garbage ( working_set, span)
5357- }
5333+ SyntaxShape :: Table ( _) if bytes. starts_with ( b"[" ) => {
5334+ parse_table_expression ( working_set, span, & SyntaxShape :: Any )
53585335 }
53595336 SyntaxShape :: CellPath => parse_simple_cell_path ( working_set, span) ,
5360- SyntaxShape :: Boolean => {
5361- // Redundant, though we catch bad boolean parses here
5362- if bytes == b"true" || bytes == b"false" {
5363- Expression :: new ( working_set, Expr :: Bool ( true ) , span, Type :: Bool )
5364- } else {
5365- working_set. error ( ParseError :: Expected ( "bool" , span) ) ;
5366-
5367- Expression :: garbage ( working_set, span)
5368- }
5369- }
53705337
53715338 // Be sure to return ParseError::Expected(..) if invoked for one of these shapes, but lex
53725339 // stream doesn't start with '{'} -- parsing in SyntaxShape::Any arm depends on this error variant.
@@ -5422,11 +5389,8 @@ pub fn parse_value(
54225389 garbage ( working_set, span)
54235390 }
54245391 }
5425- x => {
5426- working_set. error ( ParseError :: ExpectedWithStringMsg (
5427- x. to_type ( ) . to_string ( ) ,
5428- span,
5429- ) ) ;
5392+ _ => {
5393+ working_set. error ( ParseError :: ExpectedWithStringMsg ( shape. to_string ( ) , span) ) ;
54305394 garbage ( working_set, span)
54315395 }
54325396 }
0 commit comments