Skip to content

Commit

Permalink
Merge pull request #22 from YaroShkvorets/feature/allow_dot
Browse files Browse the repository at this point in the history
Enable all specific characters within a keys
  • Loading branch information
ArnaudBger authored May 17, 2024
2 parents 267d793 + 4fbd46e commit f49c1a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
35 changes: 19 additions & 16 deletions substreams/src/expr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,30 @@ fn expression_to_string(parsing: Pair<Rule>) -> String {
mod tests {
use rstest::rstest;
use super::*;
static TEST_KEYS: &[&str] = &["test", "test1", "test2", "test3", "test4", "test5", "test 6"];
static TEST_KEYS: &[&str] = &["test", "test1", "test2", "test3", "test4", "test5", "test 6", "test.7", "test:8", "test_9", "test*19z_|"];

#[rstest]
#[case(TEST_KEYS, "test", true)]
#[case(TEST_KEYS, "'test'", true)]
#[case(TEST_KEYS, "'test 6' || test7", true)]
#[case(TEST_KEYS, "'test_6' && test3", false)]
#[case(TEST_KEYS, "\"test 6\" || test7", true)]
#[case(TEST_KEYS, "\"test 6\"|| test7", true)]
#[case(TEST_KEYS, "\"test 6\" && test3", true)]

#[case(TEST_KEYS, "test.7", true)]
#[case(TEST_KEYS, "test.8", false)]
#[case(TEST_KEYS, "test:8", true)]
#[case(TEST_KEYS, "test*19z_|", true)]
#[case(TEST_KEYS, "test:9", false)]
#[case(TEST_KEYS, "test_9", true)]
#[case(TEST_KEYS, "test_10", false)]
#[case(TEST_KEYS, "test10 ||test.7", true)]
#[case(TEST_KEYS, "test10 && test:8", false)]
#[case(TEST_KEYS, "(test10 && test_9) || (test.7 && test:8)", true)]
#[case(TEST_KEYS, "(test10 && test_9) || (test.7 && test*19z_|)", true)]
#[case(TEST_KEYS, "(test10 && test_9) || test*19z || (test.7 && test*19z_|)", true)]
#[case(TEST_KEYS, "(test10 && test_9) || test*19z && (test.7 && test*19z_|)", false)]

#[case(TEST_KEYS, "test1 || test", true)]
#[case(TEST_KEYS, "test1 || test6", true)]
#[case(TEST_KEYS, "test6 || test7", false)]
Expand All @@ -141,8 +155,8 @@ mod tests {
#[case(TEST_KEYS, "test6 && test7", false)]

#[case(TEST_KEYS, "test1 && test && test2", true)]
#[case(TEST_KEYS, "test1 && test2 && test7", false)]
#[case(TEST_KEYS, "test6 && test7 && test8", false)]
#[case(TEST_KEYS, "test1&& test2 &&test7", false)]
#[case(TEST_KEYS, "test6 &&test7 && test8", false)]

#[case(TEST_KEYS, "test1 test", true)]
#[case(TEST_KEYS, "test1 test6", false)]
Expand All @@ -167,16 +181,5 @@ mod tests {
let result = matches_keys_in_parsed_expr(keys, input).expect("matching keys in parsed expression");

assert_eq!(result, expected, "This expression ast is {expr_as_string}");
}

#[rstest]
#[case(TEST_KEYS, "test1 *213 ", "parsing expression")]
#[case(TEST_KEYS, "|213 test", "parsing expression")]
#[case(TEST_KEYS, "", "parsing expression")]

fn test_matches_keys_in_parsed_expr_error(#[case] keys: &[&str], #[case] input: &str, #[case] expected_error: &str) {
let result = matches_keys_in_parsed_expr(keys, input).expect_err("parsing is not failing");
assert_eq!(result.to_string(), expected_error);
}

}
}
6 changes: 2 additions & 4 deletions substreams/src/expr_parser_rule.pest
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ expression = { or ~ space? ~ EOI }
or = { (and ~ (space? ~ ("||") ~ space? ~ and )* ) }
and = { (value ~ ((space ~ value) | (space? ~ ("&&") ~ space? ~ value ~ space?))* ) }
value = { (space? ~ singleQuoteKeyTerm ~ space?) | (space? ~ doubleQuoteKeyTerm ~ space?) | keyterm | (space? ~ "(" ~ space? ~ or ~ space? ~ ")" ~ space?) }
keyterm = { (letters | digits | symbols)+ }
keyterm = { (ctr_accepted)+ }
singleQuoteKeyTerm = { ("'") ~ (!"'" ~ ANY)+ ~ ("'")}
doubleQuoteKeyTerm = { ("\"") ~ (!"\"" ~ ANY)+ ~ ("\"")}

digits = _{ '0' .. '9' }
letters = _{ 'a' .. 'z' | 'A' .. 'Z' }
symbols = _{ "_" | ":" }
ctr_accepted = _{(!(space | "'" | "\"" | "(" | ")" | "-" | ("||") | ("&&")) ~ ANY)}
space = _{ (" " | "\t" | "\n" )+ }

0 comments on commit f49c1a2

Please sign in to comment.