Implement parsing of method calls on integers (#4762)

This commit is contained in:
Mees Delzenne 2024-09-13 16:52:56 +02:00 committed by GitHub
parent 211a02d1ef
commit d94d74a715
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 4 deletions

View file

@ -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;
}

View file

@ -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();

View file

@ -1,7 +1,6 @@
#![cfg(feature = "scripting")]
mod parse;
use geo::Extremes;
use parse::Parse;
mod helpers;
use helpers::new_ds;