Implement parsing of method calls on integers (#4762)
This commit is contained in:
parent
211a02d1ef
commit
d94d74a715
3 changed files with 21 additions and 4 deletions
|
@ -107,8 +107,8 @@ pub fn number_kind(lexer: &mut Lexer, start: Token) -> Result<NumberKind, Syntax
|
|||
let mut kind = NumberKind::Integer;
|
||||
|
||||
let before_mantissa = lexer.reader.offset();
|
||||
// need to test for digit.. which is a range not a floating point number.
|
||||
if lexer.reader.peek1() != Some(b'.') && lexer.eat(b'.') {
|
||||
// need to test for digit.. or digit.foo
|
||||
if lexer.reader.peek1().map(|x| x.is_ascii_digit()).unwrap_or(false) && lexer.eat(b'.') {
|
||||
eat_digits1(lexer, before_mantissa)?;
|
||||
kind = NumberKind::Float;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ use reblessive::Stack;
|
|||
|
||||
use crate::{
|
||||
sql::{
|
||||
Array, Constant, Id, Number, Object, Query, Statement, Statements, Strand, Thing, Value,
|
||||
Array, Constant, Id, Idiom, Number, Object, Part, Query, Statement, Statements, Strand,
|
||||
Thing, Value,
|
||||
},
|
||||
syn::parser::{mac::test_parse, Parser},
|
||||
};
|
||||
|
@ -183,6 +184,23 @@ fn scientific_number() {
|
|||
assert_eq!(res.to_string(), "0.000097f")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn number_method() {
|
||||
let res = test_parse!(parse_value_table, r#" 9.7e-5.sin()"#).unwrap();
|
||||
let expected = Value::Idiom(Idiom(vec![
|
||||
Part::Start(Value::Number(Number::Float(9.7e-5))),
|
||||
Part::Method("sin".to_string(), vec![]),
|
||||
]));
|
||||
assert_eq!(res, expected);
|
||||
|
||||
let res = test_parse!(parse_value_table, r#" 1.sin()"#).unwrap();
|
||||
let expected = Value::Idiom(Idiom(vec![
|
||||
Part::Start(Value::Number(Number::Int(1))),
|
||||
Part::Method("sin".to_string(), vec![]),
|
||||
]));
|
||||
assert_eq!(res, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn datetime_error() {
|
||||
test_parse!(parse_value_table, r#" d"2001-01-01T01:01:01.9999999999" "#).unwrap_err();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#![cfg(feature = "scripting")]
|
||||
|
||||
mod parse;
|
||||
use geo::Extremes;
|
||||
use parse::Parse;
|
||||
mod helpers;
|
||||
use helpers::new_ds;
|
||||
|
|
Loading…
Reference in a new issue