@@ -7197,6 +7197,7 @@ impl<'a> Parser<'a> {
7197
7197
}
7198
7198
}
7199
7199
7200
+ /// Parse an unsigned numeric literal
7200
7201
pub fn parse_number_value ( & mut self ) -> Result < Value , ParserError > {
7201
7202
match self . parse_value ( ) ? {
7202
7203
v @ Value :: Number ( _, _) => Ok ( v) ,
@@ -7208,6 +7209,26 @@ impl<'a> Parser<'a> {
7208
7209
}
7209
7210
}
7210
7211
7212
+ /// Parse a numeric literal as an expression. Returns a [`Expr::UnaryOp`] if the number is signed,
7213
+ /// otherwise returns a [`Expr::Value`]
7214
+ pub fn parse_number ( & mut self ) -> Result < Expr , ParserError > {
7215
+ let next_token = self . next_token ( ) ;
7216
+ match next_token. token {
7217
+ Token :: Plus => Ok ( Expr :: UnaryOp {
7218
+ op : UnaryOperator :: Plus ,
7219
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
7220
+ } ) ,
7221
+ Token :: Minus => Ok ( Expr :: UnaryOp {
7222
+ op : UnaryOperator :: Minus ,
7223
+ expr : Box :: new ( Expr :: Value ( self . parse_number_value ( ) ?) ) ,
7224
+ } ) ,
7225
+ _ => {
7226
+ self . prev_token ( ) ;
7227
+ Ok ( Expr :: Value ( self . parse_number_value ( ) ?) )
7228
+ }
7229
+ }
7230
+ }
7231
+
7211
7232
fn parse_introduced_string_value ( & mut self ) -> Result < Value , ParserError > {
7212
7233
let next_token = self . next_token ( ) ;
7213
7234
let location = next_token. location ;
@@ -11487,53 +11508,35 @@ impl<'a> Parser<'a> {
11487
11508
//[ INCREMENT [ BY ] increment ]
11488
11509
if self . parse_keywords ( & [ Keyword :: INCREMENT ] ) {
11489
11510
if self . parse_keywords ( & [ Keyword :: BY ] ) {
11490
- sequence_options. push ( SequenceOptions :: IncrementBy (
11491
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11492
- true ,
11493
- ) ) ;
11511
+ sequence_options. push ( SequenceOptions :: IncrementBy ( self . parse_number ( ) ?, true ) ) ;
11494
11512
} else {
11495
- sequence_options. push ( SequenceOptions :: IncrementBy (
11496
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11497
- false ,
11498
- ) ) ;
11513
+ sequence_options. push ( SequenceOptions :: IncrementBy ( self . parse_number ( ) ?, false ) ) ;
11499
11514
}
11500
11515
}
11501
11516
//[ MINVALUE minvalue | NO MINVALUE ]
11502
11517
if self . parse_keyword ( Keyword :: MINVALUE ) {
11503
- sequence_options. push ( SequenceOptions :: MinValue ( Some ( Expr :: Value (
11504
- self . parse_number_value ( ) ?,
11505
- ) ) ) ) ;
11518
+ sequence_options. push ( SequenceOptions :: MinValue ( Some ( self . parse_number ( ) ?) ) ) ;
11506
11519
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MINVALUE ] ) {
11507
11520
sequence_options. push ( SequenceOptions :: MinValue ( None ) ) ;
11508
11521
}
11509
11522
//[ MAXVALUE maxvalue | NO MAXVALUE ]
11510
11523
if self . parse_keywords ( & [ Keyword :: MAXVALUE ] ) {
11511
- sequence_options. push ( SequenceOptions :: MaxValue ( Some ( Expr :: Value (
11512
- self . parse_number_value ( ) ?,
11513
- ) ) ) ) ;
11524
+ sequence_options. push ( SequenceOptions :: MaxValue ( Some ( self . parse_number ( ) ?) ) ) ;
11514
11525
} else if self . parse_keywords ( & [ Keyword :: NO , Keyword :: MAXVALUE ] ) {
11515
11526
sequence_options. push ( SequenceOptions :: MaxValue ( None ) ) ;
11516
11527
}
11517
11528
11518
11529
//[ START [ WITH ] start ]
11519
11530
if self . parse_keywords ( & [ Keyword :: START ] ) {
11520
11531
if self . parse_keywords ( & [ Keyword :: WITH ] ) {
11521
- sequence_options. push ( SequenceOptions :: StartWith (
11522
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11523
- true ,
11524
- ) ) ;
11532
+ sequence_options. push ( SequenceOptions :: StartWith ( self . parse_number ( ) ?, true ) ) ;
11525
11533
} else {
11526
- sequence_options. push ( SequenceOptions :: StartWith (
11527
- Expr :: Value ( self . parse_number_value ( ) ?) ,
11528
- false ,
11529
- ) ) ;
11534
+ sequence_options. push ( SequenceOptions :: StartWith ( self . parse_number ( ) ?, false ) ) ;
11530
11535
}
11531
11536
}
11532
11537
//[ CACHE cache ]
11533
11538
if self . parse_keywords ( & [ Keyword :: CACHE ] ) {
11534
- sequence_options. push ( SequenceOptions :: Cache ( Expr :: Value (
11535
- self . parse_number_value ( ) ?,
11536
- ) ) ) ;
11539
+ sequence_options. push ( SequenceOptions :: Cache ( self . parse_number ( ) ?) ) ;
11537
11540
}
11538
11541
// [ [ NO ] CYCLE ]
11539
11542
if self . parse_keywords ( & [ Keyword :: NO , Keyword :: CYCLE ] ) {
0 commit comments