@@ -7411,6 +7411,7 @@ impl<'a> Parser<'a> {
7411
7411
}
7412
7412
}
7413
7413
7414
+ /// Parse an unsigned numeric literal
7414
7415
pub fn parse_number_value ( & mut self ) -> Result < Value , ParserError > {
7415
7416
match self . parse_value ( ) ? {
7416
7417
v @ Value :: Number ( _, _) => Ok ( v) ,
@@ -7422,6 +7423,26 @@ impl<'a> Parser<'a> {
7422
7423
}
7423
7424
}
7424
7425
7426
+ /// Parse a numeric literal as an expression. Returns a [`Expr::UnaryOp`] if the number is signed,
7427
+ /// otherwise returns a [`Expr::Value`]
7428
+ pub fn parse_number ( & mut self ) -> Result < Expr , ParserError > {
7429
+ let next_token = self . next_token ( ) ;
7430
+ match next_token. token {
7431
+ Token :: Plus => Ok ( Expr :: UnaryOp {
7432
+ op : UnaryOperator :: Plus ,
7433
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
7434
+ } ) ,
7435
+ Token :: Minus => Ok ( Expr :: UnaryOp {
7436
+ op : UnaryOperator :: Minus ,
7437
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
7438
+ } ) ,
7439
+ _ => {
7440
+ self . prev_token ( ) ;
7441
+ Ok ( Expr :: Value ( self . parse_number_value ( ) ?) )
7442
+ }
7443
+ }
7444
+ }
7445
+
7425
7446
fn parse_introduced_string_value ( & mut self ) -> Result < Value , ParserError > {
7426
7447
let next_token = self . next_token ( ) ;
7427
7448
let location = next_token. location ;
@@ -11741,53 +11762,35 @@ impl<'a> Parser<'a> {
11741
11762
//[ INCREMENT [ BY ] increment ]
11742
11763
if self . parse_keywords ( & [ Keyword :: INCREMENT ] ) {
11743
11764
if self . parse_keywords ( & [ Keyword :: BY ] ) {
11744
- sequence_options. push ( SequenceOptions :: IncrementBy (
11745
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11746
- true ,
11747
- ) ) ;
11765
+ sequence_options. push ( SequenceOptions :: IncrementBy ( self . parse_number ( ) ?, true ) ) ;
11748
11766
} else {
11749
- sequence_options. push ( SequenceOptions :: IncrementBy (
11750
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11751
- false ,
11752
- ) ) ;
11767
+ sequence_options. push ( SequenceOptions :: IncrementBy ( self . parse_number ( ) ?, false ) ) ;
11753
11768
}
11754
11769
}
11755
11770
//[ MINVALUE minvalue | NO MINVALUE ]
11756
11771
if self . parse_keyword ( Keyword :: MINVALUE ) {
11757
- sequence_options. push ( SequenceOptions :: MinValue ( Some ( Expr :: Value (
11758
- self . parse_number_value ( ) ?,
11759
- ) ) ) ) ;
11772
+ sequence_options. push ( SequenceOptions :: MinValue ( Some ( self . parse_number ( ) ?) ) ) ;
11760
11773
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MINVALUE ] ) {
11761
11774
sequence_options. push ( SequenceOptions :: MinValue ( None ) ) ;
11762
11775
}
11763
11776
//[ MAXVALUE maxvalue | NO MAXVALUE ]
11764
11777
if self . parse_keywords ( & [ Keyword :: MAXVALUE ] ) {
11765
- sequence_options. push ( SequenceOptions :: MaxValue ( Some ( Expr :: Value (
11766
- self . parse_number_value ( ) ?,
11767
- ) ) ) ) ;
11778
+ sequence_options. push ( SequenceOptions :: MaxValue ( Some ( self . parse_number ( ) ?) ) ) ;
11768
11779
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MAXVALUE ] ) {
11769
11780
sequence_options. push ( SequenceOptions :: MaxValue ( None ) ) ;
11770
11781
}
11771
11782
11772
11783
//[ START [ WITH ] start ]
11773
11784
if self . parse_keywords ( & [ Keyword :: START ] ) {
11774
11785
if self . parse_keywords ( & [ Keyword :: WITH ] ) {
11775
- sequence_options. push ( SequenceOptions :: StartWith (
11776
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11777
- true ,
11778
- ) ) ;
11786
+ sequence_options. push ( SequenceOptions :: StartWith ( self . parse_number ( ) ?, true ) ) ;
11779
11787
} else {
11780
- sequence_options. push ( SequenceOptions :: StartWith (
11781
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11782
- false ,
11783
- ) ) ;
11788
+ sequence_options. push ( SequenceOptions :: StartWith ( self . parse_number ( ) ?, false ) ) ;
11784
11789
}
11785
11790
}
11786
11791
//[ CACHE cache ]
11787
11792
if self . parse_keywords ( & [ Keyword :: CACHE ] ) {
11788
- sequence_options. push ( SequenceOptions :: Cache ( Expr :: Value (
11789
- self . parse_number_value ( ) ?,
11790
- ) ) ) ;
11793
+ sequence_options. push ( SequenceOptions :: Cache ( self . parse_number ( ) ?) ) ;
11791
11794
}
11792
11795
// [ [ NO ] CYCLE ]
11793
11796
if self . parse_keywords ( & [ Keyword :: NO , Keyword :: CYCLE ] ) {
0 commit comments