Skip to content

Compile time path #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
26060b5
Add initial implementation for JSONPath procedural macro
thehiddenwaffle May 13, 2025
0d1fdf9
Swap syn crates, refactor CompOp, continue writing
thehiddenwaffle May 14, 2025
241b28f
It compiles
thehiddenwaffle May 14, 2025
ce8b36b
Overly verbose version of ToTokens on AST, will replace with macro AS…
thehiddenwaffle May 16, 2025
77765ff
Merge remote-tracking branch 'refs/remotes/origin/main' into compile_…
thehiddenwaffle May 19, 2025
0859bb0
Created first basic test suite with a script and now debugging
thehiddenwaffle May 19, 2025
354fb8c
Eliminate whitespace validation via compound-atomic($) and not-atomic…
thehiddenwaffle May 19, 2025
8d4ff93
almost all tests cleansed
thehiddenwaffle May 19, 2025
a1d5406
Add nonempty parsing to `PestIgnoredPunctuated`
thehiddenwaffle May 20, 2025
b64c284
Add new compile error tests for invalid JSONPath queries
thehiddenwaffle May 20, 2025
0610c7f
Merge branch '100_whitespace' into compile_time_path
thehiddenwaffle May 20, 2025
352becf
Refactor imports and remove unused public re-exports
thehiddenwaffle May 20, 2025
e409ba2
Rustfmt all, add trim() calls on raw strings for identifiers, and lit…
thehiddenwaffle May 26, 2025
ebc8e6c
**Consolidate and refactor compile test organization**
thehiddenwaffle May 26, 2025
8b78962
fmt
thehiddenwaffle May 26, 2025
c0e608e
Refactor function parsing and add support for new keywords. All tests…
thehiddenwaffle May 29, 2025
3c28b2b
Add preliminary documentation for the `compiled-path` feature
thehiddenwaffle May 29, 2025
696c40e
Merge branch 'main' into compile_time_path
thehiddenwaffle May 29, 2025
163aa4c
fmt
thehiddenwaffle May 29, 2025
1a7b04a
Merge remote-tracking branch 'fork/compile_time_path' into compile_ti…
thehiddenwaffle May 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ regex = "1"
pest = "2.7.15"
pest_derive = "2.7.15"
thiserror = "2.0.9"
jsonpath-rust-impl = {path = "jsonpath-rust-impl", optional = true}
jsonpath-ast = {path = "jsonpath-ast"}

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
criterion = "0.5.1"

[features]
compiled-path = ["jsonpath-ast/compiled-path", "dep:jsonpath-rust-impl"]

[[bench]]
name = "regex"
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,27 @@ The path is supported with the limited elements namely only the elements with th
}
```

### Compiled Paths
🚧Under Construction: Unstable/Unimplemented🚧

By enabling the `compiled-path` feature, the following syntax becomes available:
```rust
fn macros() {
// Existing
let vec = js_path("$.values[?match(@, $.regex)]", &json)?;
// New
let q_ast: JpQuery = ::jsonpath_rust::json_query!($.values[?match(@, $.regex)]);
}
```

This allows for query strings to be created infallibly at compile time for applications where query strings will be static strings in source code.

#### Limitations Of Compiled Path Queries
- Single quote strings are not allowed, however to replace this, rust's [raw string literals](https://doc.rust-lang.org/rust-by-example/std/str.html) such as `r"# ... #"` can be used.
- The macro does not check whitespace, this means that with respect to whitespace, the domain of strings accepted by the macro is a superset of those accepted by the original RFC.
- Due to [constraints on rust identifiers](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838), emoji in member name shorthands such as `json_query!( $.☺ )` are not allowed
- Unicode characters still work in both string literals and bracket field access, ie: `json_query!( $["☺"] )`

### Python bindings

Python bindings ([jsonpath-rust-bindings](https://github.com/night-crawler/jsonpath-rust-bindings)) are available on
Expand Down
18 changes: 18 additions & 0 deletions jsonpath-ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "jsonpath-ast"
version = "0.1.0"
edition = "2024"

[dependencies]
proc-macro2 = { version = "1.0.95", features = ["span-locations"] }
pest = "2.7.15"
pest_derive = "2.7.15"
syn = { version = "2.0.101", features = ["default", "extra-traits"] }
pest-ast = "0.3.5"
from-pest = "0.3.3"
syn_derive = { version = "0.2.0", optional = true }
quote = "1.0.40"
derive-new = "0.7.0"

[features]
compiled-path = ["dep:syn_derive"]
Loading
Loading