@@ -7274,22 +7274,6 @@ impl<'a> Parser<'a> {
7274
7274
let placeholder = tok. to_string ( ) + & ident. value ;
7275
7275
Ok ( Value :: Placeholder ( placeholder) )
7276
7276
}
7277
- tok @ Token :: Minus | tok @ Token :: Plus => {
7278
- let next_token = self . next_token ( ) ;
7279
- match next_token. token {
7280
- Token :: Number ( n, l) => {
7281
- if tok == Token :: Minus {
7282
- Ok ( Value :: Number (
7283
- Self :: parse ( tok. to_string ( ) + & n, location) ?,
7284
- l,
7285
- ) )
7286
- } else {
7287
- Ok ( Value :: Number ( Self :: parse ( n, location) ?, l) )
7288
- }
7289
- }
7290
- _ => self . expected ( "number" , next_token) ,
7291
- }
7292
- }
7293
7277
unexpected => self . expected (
7294
7278
"a value" ,
7295
7279
TokenWithLocation {
@@ -7300,6 +7284,7 @@ impl<'a> Parser<'a> {
7300
7284
}
7301
7285
}
7302
7286
7287
+ /// Parse an unsigned numeric literal
7303
7288
pub fn parse_number_value ( & mut self ) -> Result < Value , ParserError > {
7304
7289
match self . parse_value ( ) ? {
7305
7290
v @ Value :: Number ( _, _) => Ok ( v) ,
@@ -7311,6 +7296,26 @@ impl<'a> Parser<'a> {
7311
7296
}
7312
7297
}
7313
7298
7299
+ /// Parse a numeric literal and return Expr::UnaryOp if the number is signed,
7300
+ /// otherwise return Expr::Value
7301
+ pub fn parse_number_value_with_sign ( & mut self ) -> Result < Expr , ParserError > {
7302
+ let next_token = self . next_token ( ) ;
7303
+ match next_token. token {
7304
+ Token :: Plus => Ok ( Expr :: UnaryOp {
7305
+ op : UnaryOperator :: Plus ,
7306
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
7307
+ } ) ,
7308
+ Token :: Minus => Ok ( Expr :: UnaryOp {
7309
+ op : UnaryOperator :: Minus ,
7310
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
7311
+ } ) ,
7312
+ _ => {
7313
+ self . prev_token ( ) ;
7314
+ Ok ( Expr :: Value ( self . parse_number_value ( ) ?) )
7315
+ }
7316
+ }
7317
+ }
7318
+
7314
7319
fn parse_introduced_string_value ( & mut self ) -> Result < Value , ParserError > {
7315
7320
let next_token = self . next_token ( ) ;
7316
7321
let location = next_token. location ;
@@ -11625,29 +11630,29 @@ impl<'a> Parser<'a> {
11625
11630
if self . parse_keywords ( & [ Keyword :: INCREMENT ] ) {
11626
11631
if self . parse_keywords ( & [ Keyword :: BY ] ) {
11627
11632
sequence_options. push ( SequenceOptions :: IncrementBy (
11628
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11633
+ self . parse_number_value_with_sign ( ) ?,
11629
11634
true ,
11630
11635
) ) ;
11631
11636
} else {
11632
11637
sequence_options. push ( SequenceOptions :: IncrementBy (
11633
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11638
+ self . parse_number_value_with_sign ( ) ?,
11634
11639
false ,
11635
11640
) ) ;
11636
11641
}
11637
11642
}
11638
11643
//[ MINVALUE minvalue | NO MINVALUE ]
11639
11644
if self . parse_keyword ( Keyword :: MINVALUE ) {
11640
- sequence_options. push ( SequenceOptions :: MinValue ( Some ( Expr :: Value (
11641
- self . parse_number_value ( ) ?,
11642
- ) ) ) ) ;
11645
+ sequence_options. push ( SequenceOptions :: MinValue ( Some (
11646
+ self . parse_number_value_with_sign ( ) ?,
11647
+ ) ) ) ;
11643
11648
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MINVALUE ] ) {
11644
11649
sequence_options. push ( SequenceOptions :: MinValue ( None ) ) ;
11645
11650
}
11646
11651
//[ MAXVALUE maxvalue | NO MAXVALUE ]
11647
11652
if self . parse_keywords ( & [ Keyword :: MAXVALUE ] ) {
11648
- sequence_options. push ( SequenceOptions :: MaxValue ( Some ( Expr :: Value (
11649
- self . parse_number_value ( ) ?,
11650
- ) ) ) ) ;
11653
+ sequence_options. push ( SequenceOptions :: MaxValue ( Some (
11654
+ self . parse_number_value_with_sign ( ) ?,
11655
+ ) ) ) ;
11651
11656
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MAXVALUE ] ) {
11652
11657
sequence_options. push ( SequenceOptions :: MaxValue ( None ) ) ;
11653
11658
}
@@ -11656,21 +11661,19 @@ impl<'a> Parser<'a> {
11656
11661
if self . parse_keywords ( & [ Keyword :: START ] ) {
11657
11662
if self . parse_keywords ( & [ Keyword :: WITH ] ) {
11658
11663
sequence_options. push ( SequenceOptions :: StartWith (
11659
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11664
+ self . parse_number_value_with_sign ( ) ?,
11660
11665
true ,
11661
11666
) ) ;
11662
11667
} else {
11663
11668
sequence_options. push ( SequenceOptions :: StartWith (
11664
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11669
+ self . parse_number_value_with_sign ( ) ?,
11665
11670
false ,
11666
11671
) ) ;
11667
11672
}
11668
11673
}
11669
11674
//[ CACHE cache ]
11670
11675
if self . parse_keywords ( & [ Keyword :: CACHE ] ) {
11671
- sequence_options. push ( SequenceOptions :: Cache ( Expr :: Value (
11672
- self . parse_number_value ( ) ?,
11673
- ) ) ) ;
11676
+ sequence_options. push ( SequenceOptions :: Cache ( self . parse_number_value_with_sign ( ) ?) ) ;
11674
11677
}
11675
11678
// [ [ NO ] CYCLE ]
11676
11679
if self . parse_keywords ( & [ Keyword :: NO , Keyword :: CYCLE ] ) {
0 commit comments