diff --git a/Cargo.lock b/Cargo.lock index 1cdc842..f5c19e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.65" @@ -31,6 +40,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bytes" version = "1.2.1" @@ -43,12 +61,41 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "diff" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "either" version = "1.8.0" @@ -70,6 +117,117 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.61", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "hashbrown" version = "0.12.3" @@ -130,9 +288,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.133" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "log" @@ -143,6 +301,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + [[package]] name = "multimap" version = "0.8.3" @@ -194,6 +358,51 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "pest" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.61", +] + +[[package]] +name = "pest_meta" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "petgraph" version = "0.6.2" @@ -204,6 +413,18 @@ dependencies = [ "indexmap", ] +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pretty_assertions" version = "1.4.0" @@ -221,14 +442,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" dependencies = [ "proc-macro2", - "syn", + "syn 1.0.100", ] [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -273,7 +494,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 1.0.100", ] [[package]] @@ -288,9 +509,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -306,18 +527,38 @@ dependencies = [ [[package]] name = "regex" -version = "1.6.0" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "relative-path" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" [[package]] name = "remove_dir_all" @@ -328,6 +569,70 @@ dependencies = [ "winapi", ] +[[package]] +name = "rstest" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5316d2a1479eeef1ea21e7f9ddc67c191d497abc8fc3ba2467857abbb68330" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros", + "rustc_version", +] + +[[package]] +name = "rstest_macros" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04a9df72cc1f67020b0d63ad9bfe4a323e459ea7eb68e03bd9824db49f9a4c25" +dependencies = [ + "cfg-if", + "glob", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version", + "syn 2.0.61", + "unicode-ident", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "substreams" version = "0.5.13" @@ -340,9 +645,12 @@ dependencies = [ "num-integer", "num-traits", "pad", + "pest", + "pest_derive", "prost", "prost-build", "prost-types", + "rstest", "substreams-macro", "thiserror", ] @@ -355,7 +663,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn", + "syn 1.0.100", "thiserror", ] @@ -370,6 +678,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.3.0" @@ -386,29 +705,41 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.35" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.35" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.61", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-width" @@ -416,6 +747,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "which" version = "4.3.0" diff --git a/substreams/Cargo.toml b/substreams/Cargo.toml index a5bbecf..ecdf68a 100644 --- a/substreams/Cargo.toml +++ b/substreams/Cargo.toml @@ -24,6 +24,11 @@ prost = "0.11" prost-types = "0.11" substreams-macro = { workspace = true } thiserror = "1" +pest= "2.7.10" +pest_derive = "2.7.10" + +[dev-dependencies] +rstest = "0.19.0" [build-dependencies] prost-build = "0.11" diff --git a/substreams/src/expr_parser.rs b/substreams/src/expr_parser.rs new file mode 100644 index 0000000..374d229 --- /dev/null +++ b/substreams/src/expr_parser.rs @@ -0,0 +1,182 @@ +use anyhow::{Context, Error}; +use pest::{iterators::Pair, Parser}; +use pest_derive::Parser; + +#[derive(Parser)] +#[grammar = "expr_parser_rule.pest"] +struct EParser; + +fn parsing(input: &str) -> Result, Error> { + let pairs = EParser::parse(Rule::expression, input) + .context("parsing input based on the expression rule")?; + + match pairs.into_iter().next() { + Some(pair) => Ok(pair), + None => Err(anyhow::Error::msg("no pairs found in input")) + } +} + +pub fn matches_keys_in_parsed_expr, I: AsRef>(keys: &[K], input: I) -> Result { + let successful_parse = parsing(input.as_ref()).context("parsing expression")?; + Ok(apply_rule(successful_parse, keys)) +} + +fn apply_rule>(pair: Pair, keys: &[K]) -> bool { + match pair.as_rule() { + Rule::expression => { + let inner_pair = pair.into_inner().next().unwrap(); + return apply_rule(inner_pair, keys); + } + Rule::or => { + let mut result = false; + for inner_pair in pair.into_inner() { + result = result || apply_rule(inner_pair, keys); + } + return result; + }, + Rule::and => { + let mut result = true; + for inner_pair in pair.into_inner() { + result = result && apply_rule(inner_pair, keys); + } + return result; + }, + Rule::value => { + let inner_pair = pair.into_inner().next().unwrap(); + return apply_rule(inner_pair, keys); + } + Rule::keyterm => { + return keys.iter().any(|key| key.as_ref() == pair.as_str()); + } + Rule::singleQuoteKeyTerm => { + return keys.iter().any(|key| key.as_ref() == pair.as_str().trim_matches('\'')); + } + Rule::doubleQuoteKeyTerm => { + return keys.iter().any(|key| key.as_ref() == pair.as_str().trim_matches('"')); + } + _ => {panic!("Unexpected rule encountered")} + } +} + +#[cfg(test)] +fn expression_to_string(parsing: Pair) -> String { + let rule = parsing.as_rule(); + match rule { + Rule::expression => { + let inner_pair = parsing.into_inner().next().unwrap(); + return expression_to_string(inner_pair); + } + Rule::or => { + let mut result = String::new(); + result.push_str("["); + for inner_pair in parsing.into_inner() { + result.push_str(&expression_to_string(inner_pair)); + result.push_str("||"); + } + + if result.ends_with("||") { + result.truncate(result.len() - 2); + } + + result.push_str("]"); + return result; + }, + Rule::and => { + let mut result = String::new(); + result.push_str("<"); + for inner_pair in parsing.into_inner() { + result.push_str(&expression_to_string(inner_pair)); + result.push_str("&&"); + } + + if result.ends_with("&&") { + result.truncate(result.len() - 2); + } + + result.push_str(">"); + return result; + }, + Rule::value => { + let inner_pair = parsing.into_inner().next().unwrap(); + return expression_to_string(inner_pair); + } + Rule::keyterm => { + return parsing.as_str().to_string(); + } + Rule::singleQuoteKeyTerm => { + return parsing.as_str().trim_matches('\'').to_string(); + } + Rule::doubleQuoteKeyTerm => { + return parsing.as_str().trim_matches('\"').to_string(); + } + _ => {panic!("Unexpected rule encountered")} + } +} + + +#[cfg(test)] +mod tests { + use rstest::rstest; + use super::*; + static TEST_KEYS: &[&str] = &["test", "test1", "test2", "test3", "test4", "test5", "test 6"]; + + #[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\" && test3", true)] + + #[case(TEST_KEYS, "test1 || test", true)] + #[case(TEST_KEYS, "test1 || test6", true)] + #[case(TEST_KEYS, "test6 || test7", false)] + + #[case(TEST_KEYS, "test1 || test || test2", true)] + #[case(TEST_KEYS, "test1 || test6 || test7", true)] + #[case(TEST_KEYS, "test6 || test7 || test8", false)] + + #[case(TEST_KEYS, "test1 && test", true)] + #[case(TEST_KEYS, "test1 && test6", false)] + #[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 test", true)] + #[case(TEST_KEYS, "test1 test6", false)] + #[case(TEST_KEYS, "test6 test7", false)] + + #[case(TEST_KEYS, "(test1)", true)] + #[case(TEST_KEYS, "(test1 test6)", false)] + + #[case(TEST_KEYS, "test1 test2 ", true)] + #[case(TEST_KEYS, "test1 && test2 ", true)] + #[case(TEST_KEYS, "test1 && test6", false)] + #[case(TEST_KEYS, "(test1 || test3) && test6 ", false)] + #[case(TEST_KEYS, "(test1 || test6 || test7 ) && (test4 || test5) && test3 ", true)] + + #[case(TEST_KEYS, "(test1 || test6 || test7) && (test4 || test5) && test3 ", true)] + #[case(TEST_KEYS, "(test1 && test6 && test7) || (test4 && test5) || test3 ", true)] + + fn test_matches_keys_in_parsed_expr(#[case] keys: &[&str], #[case] input: &str, #[case] expected: bool) { + let pair = parsing(input).unwrap(); + let expr_as_string = expression_to_string(pair); + + 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 new file mode 100644 index 0000000..f8c965a --- /dev/null +++ b/substreams/src/expr_parser_rule.pest @@ -0,0 +1,12 @@ +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)+ } +singleQuoteKeyTerm = { ("'") ~ (!"'" ~ ANY)+ ~ ("'")} +doubleQuoteKeyTerm = { ("\"") ~ (!"\"" ~ ANY)+ ~ ("\"")} + +digits = _{ '0' .. '9' } +letters = _{ 'a' .. 'z' | 'A' .. 'Z' } +symbols = _{ "_" | ":" } +space = _{ (" " | "\t" | "\n" )+ } \ No newline at end of file diff --git a/substreams/src/lib.rs b/substreams/src/lib.rs index d00e54b..f3c1ff9 100644 --- a/substreams/src/lib.rs +++ b/substreams/src/lib.rs @@ -126,6 +126,9 @@ mod state; pub mod key; pub mod store; +pub mod expr_parser; +pub use expr_parser::matches_keys_in_parsed_expr; + mod operation; /// A prelude that makes all store traits available. diff --git a/substreams/src/pb/mod.rs b/substreams/src/pb/mod.rs index 5d14a91..90eeb9b 100644 --- a/substreams/src/pb/mod.rs +++ b/substreams/src/pb/mod.rs @@ -1,2 +1,14 @@ +pub mod sf { + pub mod substreams { + pub mod index { + // @@protoc_insertion_point(attribute:sf.substreams.index.v1) + pub mod v1 { + include!("sf.substreams.index.v1.rs"); + // @@protoc_insertion_point(sf.substreams.index.v1) + } + } + } +} + #[path = "./sf.substreams.v1.rs"] pub mod substreams; diff --git a/substreams/src/pb/sf.substreams.index.v1.rs b/substreams/src/pb/sf.substreams.index.v1.rs new file mode 100644 index 0000000..a954365 --- /dev/null +++ b/substreams/src/pb/sf.substreams.index.v1.rs @@ -0,0 +1,8 @@ +// @generated +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Keys { + #[prost(string, repeated, tag="1")] + pub keys: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, +} +// @@protoc_insertion_point(module)