@@ -494,28 +494,24 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
494
494
match self . check_and_consume ( vec ! [ TokType :: Plus , TokType :: Minus ] ) {
495
495
None => self . parse_primary ( ) ,
496
496
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
+ }
497
507
match span. 1 {
498
508
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
- }
506
509
Ok ( JSONValue :: Unary { operator : UnaryOperator :: Plus , value : Box :: new ( value) } )
507
510
}
508
511
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
- }
516
512
Ok ( JSONValue :: Unary { operator : UnaryOperator :: Minus , value : Box :: new ( value) } )
517
513
}
518
- _ => unreachable ! ( "no " )
514
+ _ => unreachable ! ( "unexpected unary token type " )
519
515
}
520
516
}
521
517
}
0 commit comments