Skip to content

Commit

Permalink
V0.11.1 dev (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarMatt authored Mar 28, 2024
1 parent 429ce02 commit 97f1b6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rscel"
version = "0.11.0"
version = "0.11.1"
edition = "2021"
description = "Cel interpreter in rust"
license = "MIT"
Expand Down
17 changes: 15 additions & 2 deletions src/compiler/string_tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ impl<'l> StringTokenizer<'l> {
}
_ => Ok(Some(Token::Not)),
},
'.' => Ok(Some(Token::Dot)),
'.' => {
if let Some(v) = self.scanner.peek() {
if v >= '0' && v <= '9' {
self.parse_number_or_token(input_char.encode_utf8(&mut tmp), Token::Dot)
} else {
Ok(Some(Token::Dot))
}
} else {
Ok(Some(Token::Dot))
}
}
',' => Ok(Some(Token::Comma)),
'[' => Ok(Some(Token::LBracket)),
']' => Ok(Some(Token::RBracket)),
Expand Down Expand Up @@ -205,7 +215,7 @@ impl<'l> StringTokenizer<'l> {
_starting_token: Token,
) -> Result<Option<Token>, SyntaxError> {
let mut working = starting.to_owned();
let mut is_float = false;
let mut is_float = starting.contains(".");
let mut is_unsigned = false;

'outer: loop {
Expand Down Expand Up @@ -316,7 +326,10 @@ mod test {
#[test_case("true", vec![Token::BoolLit(true)]; "keyword true")]
#[test_case("100", vec![Token::IntLit(100)]; "int literal")]
#[test_case("3+4", vec![Token::IntLit(3), Token::Add, Token::IntLit(4)]; "parse addition")]
#[test_case(".4", vec![Token::FloatLit(0.4)]; "parse float 2")]
#[test_case(r#""test\"123""#, vec![Token::StringLit("test\"123".to_string())]; "string literal")]
#[test_case("-0.4", vec![Token::Minus, Token::FloatLit(0.4)]; "parse neg float")]
#[test_case("-.4", vec![Token::Minus, Token::FloatLit(0.4)]; "parse neg float 2")]
fn test_tokenizer(input: &str, expected: Vec<Token>) {
let tokens = _tokenize(input).unwrap();

Expand Down
3 changes: 3 additions & 0 deletions src/tests/general_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ fn test_contains() {
#[test_case("coalesce(null, 3)", 3.into(); "coalesce explicit null")]
#[test_case("coalesce(foo, 4)", 4.into(); "coalesce unbound var")]
#[test_case("coalesce(1, 2, 3)", 1.into(); "coalesce first val ok")]
#[test_case(".1", 0.1.into(); "dot leading floating point")]
#[test_case("-.1", (-0.1).into(); "neg dot leading floating point")]
#[test_case("2+3 in [5]", true.into(); "check in binding")]
fn test_equation(prog: &str, res: CelValue) {
let mut ctx = CelContext::new();
let exec_ctx = BindContext::new();
Expand Down

0 comments on commit 97f1b6d

Please sign in to comment.