Skip to content

Commit

Permalink
single quote strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhibas committed Feb 11, 2024
1 parent 3ea6d0a commit e2160be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- [ ] Atom parsing for Date & DateTime
- [ ] Scopes and negated scopes
- [ ] either lower() or upper() function calls or case insensitive string comparison operators
- [ ] support for single quote strings
- [+] support for single quote strings
- [ ] not quoted strings as values treated as variables now, needs a fix
- [ ] evaluation with provided context
40 changes: 26 additions & 14 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ fn parse_boolean(i: &str) -> IResult<&str, Atom> {
}

fn parse_string(i: &str) -> IResult<&str, Atom> {
let parser = delimited(tag("\""), take_until("\""), tag("\""));
let parser_a = delimited(tag("\""), take_until("\""), tag("\""));
let parser_b = delimited(tag("\'"), take_until("\'"), tag("\'"));
let parser = alt((parser_a, parser_b));
map(parser, |s: &str| Atom::String(s.to_string()))(i)
}

Expand Down Expand Up @@ -273,18 +275,28 @@ mod tests {
}

#[test]
fn test_extreme_test() {
/// TODO:
/// scopes with negates (!(a=b) and c=d)
/// date/date time Atom
/// function calls to lower / upper
/// values > variables should be strings
let expression = r###"a = b and c=d and something not in (1,2,3) or lower(z) == "demo car" or
z == "demo car" or
g in (4,5,6) and z == "demo car" or
model in (ms,mx,m3,my) and created >= 2024-01-01
and demo == false"###;
let (i, v) = parse(expression).unwrap();
assert_eq!(i, "");
fn test_single_quote_string() {
let a = "a='demo demo'";
let res = parse_compare_expr(a);
assert_eq!(res.is_ok(), true);
if let Ok((i, v)) = res {
assert_eq!(i, "");
}
}

// #[test]
// fn test_extreme_test() {
// /// TODO:
// /// scopes with negates (!(a=b) and c=d)
// /// date/date time Atom
// /// function calls to lower / upper
// /// values > variables should be strings
// let expression = r###"a = b and c=d and something not in (1,2,3) or lower(z) == "demo car" or
// z == "demo car" or
// g in (4,5,6) and z == "demo car" or
// model in (ms,mx,m3,my) and created >= 2024-01-01
// and demo == false"###;
// let (i, v) = parse(expression).unwrap();
// assert_eq!(i, "");
// }
}

0 comments on commit e2160be

Please sign in to comment.