Fix decimal parsing (#4838)
This commit is contained in:
parent
99db7f2a82
commit
491b549f1d
3 changed files with 20 additions and 1 deletions
|
@ -82,9 +82,16 @@ pub fn numeric(lexer: &mut Lexer, start: Token) -> Result<Numeric, SyntaxError>
|
||||||
match start.kind {
|
match start.kind {
|
||||||
t!("-") | t!("+") => number(lexer, start).map(Numeric::Number),
|
t!("-") | t!("+") => number(lexer, start).map(Numeric::Number),
|
||||||
TokenKind::Digits => match lexer.reader.peek() {
|
TokenKind::Digits => match lexer.reader.peek() {
|
||||||
Some(b'n' | b'm' | b's' | b'h' | b'y' | b'd' | b'w') => {
|
Some(b'n' | b'm' | b's' | b'h' | b'y' | b'w') => {
|
||||||
duration(lexer, start).map(Numeric::Duration)
|
duration(lexer, start).map(Numeric::Duration)
|
||||||
}
|
}
|
||||||
|
Some(b'd') => {
|
||||||
|
if lexer.reader.peek1() == Some(b'e') {
|
||||||
|
number(lexer, start).map(Numeric::Number)
|
||||||
|
} else {
|
||||||
|
duration(lexer, start).map(Numeric::Duration)
|
||||||
|
}
|
||||||
|
}
|
||||||
Some(x) if !x.is_ascii() => duration(lexer, start).map(Numeric::Duration),
|
Some(x) if !x.is_ascii() => duration(lexer, start).map(Numeric::Duration),
|
||||||
_ => number(lexer, start).map(Numeric::Number),
|
_ => number(lexer, start).map(Numeric::Number),
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,6 +9,11 @@ mod stmt;
|
||||||
mod streaming;
|
mod streaming;
|
||||||
mod value;
|
mod value;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_large_test_file() {
|
||||||
|
test_parse!(parse_query, include_str!("../../../../test.surql")).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn multiple_semicolons() {
|
fn multiple_semicolons() {
|
||||||
let res = test_parse!(parse_query, r#";;"#).unwrap();
|
let res = test_parse!(parse_query, r#";;"#).unwrap();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use reblessive::Stack;
|
use reblessive::Stack;
|
||||||
|
use rust_decimal::Decimal;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
sql::{
|
sql::{
|
||||||
|
@ -156,6 +157,12 @@ fn parse_i64() {
|
||||||
assert_eq!(res, Value::Number(Number::Int(i64::MAX)));
|
assert_eq!(res, Value::Number(Number::Int(i64::MAX)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_decimal() {
|
||||||
|
let res = test_parse!(parse_value_field, r#" 0dec "#).unwrap();
|
||||||
|
assert_eq!(res, Value::Number(Number::Decimal(Decimal::ZERO)));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn constant_lowercase() {
|
fn constant_lowercase() {
|
||||||
let out = test_parse!(parse_value_field, r#" math::pi "#).unwrap();
|
let out = test_parse!(parse_value_field, r#" math::pi "#).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue