diff --git a/Cargo.lock b/Cargo.lock index af8bf70..f3de585 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,15 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" -dependencies = [ - "const-random", -] - [[package]] name = "ahash" version = "0.8.8" @@ -33,6 +24,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42cd52102d3df161c77a887b608d7a4897d7cc112886a9537b738a887a03aaff" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -176,6 +168,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "bincode" version = "1.3.3" @@ -230,7 +228,7 @@ version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "355face540df58778b96814c48abb3c2ed67c4878a8087ab1819c1fedeec505f" dependencies = [ - "ahash 0.8.8", + "ahash", "cached_proc_macro", "cached_proc_macro_types", "hashbrown 0.14.3", @@ -345,11 +343,11 @@ dependencies = [ [[package]] name = "chumsky" -version = "0.8.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d02796e4586c6c41aeb68eae9bfb4558a522c35f1430c14b40136c3706e09e4" +checksum = "8eebd66744a15ded14960ab4ccdbfb51ad3b81f51f3f04a80adac98c985396c9" dependencies = [ - "ahash 0.3.8", + "hashbrown 0.14.3", ] [[package]] @@ -426,26 +424,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "const-random" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom", - "once_cell", - "tiny-keccak", -] - [[package]] name = "convert_case" version = "0.4.0" @@ -533,6 +511,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -1038,7 +1025,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cf7d155dd7cef20195016d01005033a5521aad307033f0f8e8bf0a02f5f7554" dependencies = [ "codemap", - "indexmap 2.2.3", + "indexmap", "lasso", "once_cell", "phf", @@ -1127,19 +1114,13 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.8", + "ahash", ] [[package]] @@ -1148,7 +1129,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.8", + "ahash", "allocator-api2", ] @@ -1164,6 +1145,12 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" +[[package]] +name = "hifijson" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ef6b41c333e6dd2a4aaa59125a19b633cd17e7aaf372b2260809777bcdef4a" + [[package]] name = "humantime" version = "2.1.0" @@ -1199,16 +1186,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.2.3" @@ -1298,38 +1275,64 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "jaq-core" -version = "0.9.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1452b4acc3a7f49bd8dd516e90ed0c4f688bada805857275f85957aca2c0e7eb" +checksum = "03d6a5713b8f33675abfac79d1db0022a3f28764b2a6b96a185c199ad8dab86d" dependencies = [ - "ahash 0.3.8", - "dyn-clone", - "indexmap 1.9.3", - "itertools 0.10.5", - "jaq-parse", + "aho-corasick", + "base64", + "hifijson", + "jaq-interpret", + "libm", "log", + "regex", + "time", + "urlencoding", +] + +[[package]] +name = "jaq-interpret" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f569e38e5fc677db8dfda89ee0b4c25b3f53e811b16434fd14bdc5b43fc362ac" +dependencies = [ + "ahash", + "dyn-clone", + "hifijson", + "indexmap", + "jaq-syn", "once_cell", "serde_json", ] [[package]] name = "jaq-parse" -version = "0.9.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2130a59d64a5476f6feeb6b7e48cbe52ef05d8bc1b9174f50baa93e49052fd" +checksum = "ef6f8beb9f9922546419e774e24199e8a968f54c63a5a2323c8f3ef3321ace14" dependencies = [ "chumsky", - "serde", + "jaq-syn", ] [[package]] name = "jaq-std" -version = "0.9.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ab73d2079279e784a52dbbf5f3a5e0d792c89b41fd2c857de87cf698a4e24a" +checksum = "5d7871c59297cbfdd18f6f1bbbafaad24e97fd555ee1e2a1be7a40a5a20f551a" dependencies = [ "bincode", "jaq-parse", + "jaq-syn", +] + +[[package]] +name = "jaq-syn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4d60101fb791b20c982731d848ed6e7d25363656497647c2093b68bd88398d6" +dependencies = [ + "serde", ] [[package]] @@ -1413,6 +1416,12 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libredox" version = "0.0.1" @@ -1555,6 +1564,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-traits" version = "0.2.18" @@ -1654,7 +1669,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.2.3", + "indexmap", ] [[package]] @@ -1736,6 +1751,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -2048,7 +2069,10 @@ dependencies = [ "insta", "itertools 0.12.1", "jaq-core", + "jaq-interpret", + "jaq-parse", "jaq-std", + "jaq-syn", "lalrpop", "lalrpop-util", "once_cell", @@ -2252,6 +2276,37 @@ dependencies = [ "syn 2.0.49", ] +[[package]] +name = "time" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -2331,7 +2386,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.2.3", + "indexmap", "toml_datetime", "winnow 0.5.40", ] @@ -2342,7 +2397,7 @@ version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6" dependencies = [ - "indexmap 2.2.3", + "indexmap", "serde", "serde_spanned", "toml_datetime", @@ -2373,6 +2428,12 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index f8dabf2..dd571cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,11 @@ futures = "0.3.28" grass = {version = "0.13.1", default-features = false} insta = "1.7" itertools = "0.12.1" -jaq-core = "0.9.0" -jaq-std = {version = "0.9.0", features = ["bincode"]} +jaq-core = "1.2.1" +jaq-parse = "1.0.2" +jaq-std = {version = "1.2.1", features = ["bincode"]} +jaq-interpret = "1.2.1" +jaq-syn = "1.1.0" lalrpop = "0.19.5" lalrpop-util = "0.19.5" libc = "0.2" diff --git a/crates/simplexpr/Cargo.toml b/crates/simplexpr/Cargo.toml index a30061c..420c04d 100644 --- a/crates/simplexpr/Cargo.toml +++ b/crates/simplexpr/Cargo.toml @@ -19,7 +19,10 @@ chrono-tz.workspace = true chrono.workspace = true itertools.workspace = true jaq-core.workspace = true +jaq-parse.workspace = true jaq-std = {workspace = true, features = ["bincode"]} +jaq-interpret.workspace = true +jaq-syn.workspace = true lalrpop-util.workspace = true once_cell.workspace = true regex.workspace = true diff --git a/crates/simplexpr/src/eval.rs b/crates/simplexpr/src/eval.rs index ef7383b..2f4fa86 100644 --- a/crates/simplexpr/src/eval.rs +++ b/crates/simplexpr/src/eval.rs @@ -1,6 +1,7 @@ use cached::proc_macro::cached; use chrono::{Local, LocalResult, TimeZone}; use itertools::Itertools; +use jaq_interpret::FilterT; use crate::{ ast::{AccessType, BinOp, SimplExpr, UnaryOp}, @@ -15,7 +16,7 @@ use std::{ }; #[derive(Debug, thiserror::Error)] -pub struct JaqParseError(pub Option); +pub struct JaqParseError(pub Option); impl std::fmt::Display for JaqParseError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self.0 { @@ -459,18 +460,16 @@ fn call_expr_function(name: &str, args: Vec) -> Result Result, EvalError> { - let (filter, mut errors) = jaq_core::parse::parse(&code, jaq_core::parse::main()); +fn prepare_jaq_filter(code: String) -> Result, EvalError> { + let (filter, mut errors) = jaq_parse::parse(&code, jaq_parse::main()); let filter = match filter { Some(x) => x, None => return Err(EvalError::JaqParseError(Box::new(JaqParseError(errors.pop())))), }; - let mut defs = jaq_core::Definitions::core(); - for def in jaq_std::std() { - defs.insert(def, &mut errors); - } + let mut defs = jaq_interpret::ParseCtx::new(Vec::new()); + defs.insert_defs(jaq_std::std()); - let filter = defs.finish(filter, Vec::new(), &mut errors); + let filter = defs.compile(filter); if let Some(error) = errors.pop() { return Err(EvalError::JaqParseError(Box::new(JaqParseError(Some(error))))); @@ -479,10 +478,10 @@ fn prepare_jaq_filter(code: String) -> Result, EvalError> } fn run_jaq_function(json: serde_json::Value, code: String) -> Result { - let filter = prepare_jaq_filter(code)?; - let inputs = jaq_core::RcIter::new(std::iter::empty()); + let filter: Arc = prepare_jaq_filter(code)?; + let inputs = jaq_interpret::RcIter::new(std::iter::empty()); let out = filter - .run(jaq_core::Ctx::new([], &inputs), jaq_core::Val::from(json)) + .run((jaq_interpret::Ctx::new([], &inputs), jaq_interpret::Val::from(json))) .map(|x| x.map(Into::::into)) .map(|x| x.map(|x| DynVal::from_string(serde_json::to_string(&x).unwrap()))) .collect::>()