@@ -6717,6 +6717,7 @@ impl<'a> Parser<'a> {
6717
6717
}
6718
6718
}
6719
6719
6720
+ /// Parse an unsigned numeric literal
6720
6721
pub fn parse_number_value ( & mut self ) -> Result < Value , ParserError > {
6721
6722
match self . parse_value ( ) ? {
6722
6723
v @ Value :: Number ( _, _) => Ok ( v) ,
@@ -6728,6 +6729,26 @@ impl<'a> Parser<'a> {
6728
6729
}
6729
6730
}
6730
6731
6732
+ /// Parse a numeric literal as an expression. Returns a [`Expr::UnaryOp`] if the number is signed,
6733
+ /// otherwise returns a [`Expr::Value`]
6734
+ pub fn parse_number ( & mut self ) -> Result < Expr , ParserError > {
6735
+ let next_token = self . next_token ( ) ;
6736
+ match next_token. token {
6737
+ Token :: Plus => Ok ( Expr :: UnaryOp {
6738
+ op : UnaryOperator :: Plus ,
6739
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
6740
+ } ) ,
6741
+ Token :: Minus => Ok ( Expr :: UnaryOp {
6742
+ op : UnaryOperator :: Minus ,
6743
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
6744
+ } ) ,
6745
+ _ => {
6746
+ self . prev_token ( ) ;
6747
+ Ok ( Expr :: Value ( self . parse_number_value ( ) ?) )
6748
+ }
6749
+ }
6750
+ }
6751
+
6731
6752
fn parse_introduced_string_value ( & mut self ) -> Result < Value , ParserError > {
6732
6753
let next_token = self . next_token ( ) ;
6733
6754
let location = next_token. location ;
@@ -10660,53 +10681,35 @@ impl<'a> Parser<'a> {
10660
10681
//[ INCREMENT [ BY ] increment ]
10661
10682
if self . parse_keywords ( & [ Keyword :: INCREMENT ] ) {
10662
10683
if self . parse_keywords ( & [ Keyword :: BY ] ) {
10663
- sequence_options. push ( SequenceOptions :: IncrementBy (
10664
- Expr :: Value ( self . parse_number_value ( ) ?) ,
10665
- true ,
10666
- ) ) ;
10684
+ sequence_options. push ( SequenceOptions :: IncrementBy ( self . parse_number ( ) ?, true ) ) ;
10667
10685
} else {
10668
- sequence_options. push ( SequenceOptions :: IncrementBy (
10669
- Expr :: Value ( self . parse_number_value ( ) ?) ,
10670
- false ,
10671
- ) ) ;
10686
+ sequence_options. push ( SequenceOptions :: IncrementBy ( self . parse_number ( ) ?, false ) ) ;
10672
10687
}
10673
10688
}
10674
10689
//[ MINVALUE minvalue | NO MINVALUE ]
10675
10690
if self . parse_keyword ( Keyword :: MINVALUE ) {
10676
- sequence_options. push ( SequenceOptions :: MinValue ( Some ( Expr :: Value (
10677
- self . parse_number_value ( ) ?,
10678
- ) ) ) ) ;
10691
+ sequence_options. push ( SequenceOptions :: MinValue ( Some ( self . parse_number ( ) ?) ) ) ;
10679
10692
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MINVALUE ] ) {
10680
10693
sequence_options. push ( SequenceOptions :: MinValue ( None ) ) ;
10681
10694
}
10682
10695
//[ MAXVALUE maxvalue | NO MAXVALUE ]
10683
10696
if self . parse_keywords ( & [ Keyword :: MAXVALUE ] ) {
10684
- sequence_options. push ( SequenceOptions :: MaxValue ( Some ( Expr :: Value (
10685
- self . parse_number_value ( ) ?,
10686
- ) ) ) ) ;
10697
+ sequence_options. push ( SequenceOptions :: MaxValue ( Some ( self . parse_number ( ) ?) ) ) ;
10687
10698
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MAXVALUE ] ) {
10688
10699
sequence_options. push ( SequenceOptions :: MaxValue ( None ) ) ;
10689
10700
}
10690
10701
10691
10702
//[ START [ WITH ] start ]
10692
10703
if self . parse_keywords ( & [ Keyword :: START ] ) {
10693
10704
if self . parse_keywords ( & [ Keyword :: WITH ] ) {
10694
- sequence_options. push ( SequenceOptions :: StartWith (
10695
- Expr :: Value ( self . parse_number_value ( ) ?) ,
10696
- true ,
10697
- ) ) ;
10705
+ sequence_options. push ( SequenceOptions :: StartWith ( self . parse_number ( ) ?, true ) ) ;
10698
10706
} else {
10699
- sequence_options. push ( SequenceOptions :: StartWith (
10700
- Expr :: Value ( self . parse_number_value ( ) ?) ,
10701
- false ,
10702
- ) ) ;
10707
+ sequence_options. push ( SequenceOptions :: StartWith ( self . parse_number ( ) ?, false ) ) ;
10703
10708
}
10704
10709
}
10705
10710
//[ CACHE cache ]
10706
10711
if self . parse_keywords ( & [ Keyword :: CACHE ] ) {
10707
- sequence_options. push ( SequenceOptions :: Cache ( Expr :: Value (
10708
- self . parse_number_value ( ) ?,
10709
- ) ) ) ;
10712
+ sequence_options. push ( SequenceOptions :: Cache ( self . parse_number ( ) ?) ) ;
10710
10713
}
10711
10714
// [ [ NO ] CYCLE ]
10712
10715
if self . parse_keywords ( & [ Keyword :: NO , Keyword :: CYCLE ] ) {
0 commit comments