From fc876b2d4a57c2a176f4e50e7caffd37310cb55e Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Thu, 16 May 2024 23:31:28 -0400 Subject: [PATCH 1/4] allow . in the expression --- substreams/src/expr_parser_rule.pest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substreams/src/expr_parser_rule.pest b/substreams/src/expr_parser_rule.pest index f8c965a..6aff6f4 100644 --- a/substreams/src/expr_parser_rule.pest +++ b/substreams/src/expr_parser_rule.pest @@ -8,5 +8,5 @@ doubleQuoteKeyTerm = { ("\"") ~ (!"\"" ~ ANY)+ ~ ("\"")} digits = _{ '0' .. '9' } letters = _{ 'a' .. 'z' | 'A' .. 'Z' } -symbols = _{ "_" | ":" } +symbols = _{ "_" | ":" | "." } space = _{ (" " | "\t" | "\n" )+ } \ No newline at end of file From a078d3b86023d7fe3b5cecc38543dd3476488bad Mon Sep 17 00:00:00 2001 From: arnaudberger Date: Fri, 17 May 2024 11:14:58 -0400 Subject: [PATCH 2/4] Allow all specific characters based on go parser and some tests --- substreams/src/expr_parser.rs | 34 +++++++++++++++------------- substreams/src/expr_parser_rule.pest | 6 ++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/substreams/src/expr_parser.rs b/substreams/src/expr_parser.rs index 374d229..dc2d24f 100644 --- a/substreams/src/expr_parser.rs +++ b/substreams/src/expr_parser.rs @@ -10,6 +10,7 @@ fn parsing(input: &str) -> Result, Error> { let pairs = EParser::parse(Rule::expression, input) .context("parsing input based on the expression rule")?; + println!("{:?}", pairs.clone().collect::>()); match pairs.into_iter().next() { Some(pair) => Ok(pair), None => Err(anyhow::Error::msg("no pairs found in input")) @@ -118,16 +119,28 @@ fn expression_to_string(parsing: Pair) -> 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, "test1 || test", true)] #[case(TEST_KEYS, "test1 || test6", true)] #[case(TEST_KEYS, "test6 || test7", false)] @@ -141,8 +154,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)] @@ -167,16 +180,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); - } - + } } \ No newline at end of file diff --git a/substreams/src/expr_parser_rule.pest b/substreams/src/expr_parser_rule.pest index 6aff6f4..d63a70a 100644 --- a/substreams/src/expr_parser_rule.pest +++ b/substreams/src/expr_parser_rule.pest @@ -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" )+ } \ No newline at end of file From af284a2f8d6f079914441fc85671712f77b3022a Mon Sep 17 00:00:00 2001 From: arnaudberger Date: Fri, 17 May 2024 11:18:10 -0400 Subject: [PATCH 3/4] Remove print --- substreams/src/expr_parser.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substreams/src/expr_parser.rs b/substreams/src/expr_parser.rs index dc2d24f..7973156 100644 --- a/substreams/src/expr_parser.rs +++ b/substreams/src/expr_parser.rs @@ -10,7 +10,6 @@ fn parsing(input: &str) -> Result, Error> { let pairs = EParser::parse(Rule::expression, input) .context("parsing input based on the expression rule")?; - println!("{:?}", pairs.clone().collect::>()); match pairs.into_iter().next() { Some(pair) => Ok(pair), None => Err(anyhow::Error::msg("no pairs found in input")) From 4fbd46e31483cd089f346853436fb4b40365fc5e Mon Sep 17 00:00:00 2001 From: arnaudberger Date: Fri, 17 May 2024 11:19:47 -0400 Subject: [PATCH 4/4] Add more tests --- substreams/src/expr_parser.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substreams/src/expr_parser.rs b/substreams/src/expr_parser.rs index 7973156..9a1c158 100644 --- a/substreams/src/expr_parser.rs +++ b/substreams/src/expr_parser.rs @@ -139,6 +139,8 @@ mod tests { #[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)]