@@ -494,28 +494,24 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
494494 match self . check_and_consume ( vec ! [ TokType :: Plus , TokType :: Minus ] ) {
495495 None => self . parse_primary ( ) ,
496496 Some ( span) => {
497+ let value = self . parse_unary ( ) ?;
498+ match value {
499+ JSONValue :: Float ( _) | JSONValue :: Integer ( _) | JSONValue :: Infinity | JSONValue :: NaN | JSONValue :: Hexadecimal ( _) | JSONValue :: Exponent ( _) => { }
500+ JSONValue :: Unary { .. } => {
501+ return Err ( self . make_error ( "Only one unary operator is allowed" . to_string ( ) , span. 2 ) )
502+ }
503+ val => {
504+ return Err ( self . make_error ( format ! ( "Unary operations not allowed for value {:?}" , val) , span. 2 ) )
505+ }
506+ }
497507 match span. 1 {
498508 TokType :: Plus => {
499- let value = self . parse_unary ( ) ?;
500- match value {
501- JSONValue :: Float ( _) | JSONValue :: Integer ( _) | JSONValue :: Infinity | JSONValue :: NaN | JSONValue :: Unary { .. } | JSONValue :: Hexadecimal ( _) | JSONValue :: Exponent ( _) => { }
502- val => {
503- return Err ( self . make_error ( format ! ( "Unary operations not allowed for value {:?}" , val) , span. 2 ) )
504- }
505- }
506509 Ok ( JSONValue :: Unary { operator : UnaryOperator :: Plus , value : Box :: new ( value) } )
507510 }
508511 TokType :: Minus => {
509- let value = self . parse_unary ( ) ?;
510- match value {
511- JSONValue :: Float ( _) | JSONValue :: Integer ( _) | JSONValue :: Infinity | JSONValue :: NaN | JSONValue :: Unary { .. } | JSONValue :: Hexadecimal ( _) | JSONValue :: Exponent ( _) => { }
512- val => {
513- return Err ( self . make_error ( format ! ( "Unary operations not allowed for value {:?}" , val) , span. 2 ) )
514- }
515- }
516512 Ok ( JSONValue :: Unary { operator : UnaryOperator :: Minus , value : Box :: new ( value) } )
517513 }
518- _ => unreachable ! ( "no " )
514+ _ => unreachable ! ( "unexpected unary token type " )
519515 }
520516 }
521517 }
0 commit comments