From 778aea12cef10896f1fc0434a3a25942cbb72026 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Mon, 28 Feb 2022 16:16:17 +0000 Subject: [PATCH 1/8] Bump Rust edition Drop support for Rust 1.43.0. This was required when the JSONPath comparison project pinned Rust to that version, but now that project uses the latest stable Rust. --- .github/workflows/quickstart.yml | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/quickstart.yml b/.github/workflows/quickstart.yml index 450b025..abc335c 100644 --- a/.github/workflows/quickstart.yml +++ b/.github/workflows/quickstart.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - toolchain: [ stable, "1.43.0" ] + toolchain: [ stable ] steps: - name: Checkout sources uses: actions/checkout@v2 @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - toolchain: [ stable, "1.43.0" ] + toolchain: [ stable ] steps: - name: Checkout sources uses: actions/checkout@v2 diff --git a/Cargo.toml b/Cargo.toml index 1dc052b..9c4be77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "jsonpath_reference_implementation" version = "0.0.1" authors = ["Glyn Normington "] -edition = "2018" +edition = "2021" [dependencies] itertools = "0.9.0" From 63f3db29ae8aef535115127bc1ef67aa6604b0de Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Tue, 1 Mar 2022 20:29:45 +0000 Subject: [PATCH 2/8] Delete extraneous comment This should have been deleted previously as it pertains to an example application rather than ours. --- .github/workflows/quickstart.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/quickstart.yml b/.github/workflows/quickstart.yml index abc335c..3e5945e 100644 --- a/.github/workflows/quickstart.yml +++ b/.github/workflows/quickstart.yml @@ -1,8 +1,4 @@ # Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md -# -# While our "example" application has the platform-specific code, -# for simplicity we are compiling and testing everything on the Ubuntu environment only. -# For multi-OS testing see the `cross.yml` workflow. on: [push, pull_request] From b16a17c2c7a4452cc18380c1711ddbf2c9044af9 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Sat, 16 Apr 2022 18:30:02 +0100 Subject: [PATCH 3/8] Handle leading and trailing whitespace correctly These should cause a parsing error. --- jsonpath-compliance-test-suite | 2 +- src/grammar.pest | 4 ++-- src/parser.rs | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/jsonpath-compliance-test-suite b/jsonpath-compliance-test-suite index 2e62f6f..fc5a04d 160000 --- a/jsonpath-compliance-test-suite +++ b/jsonpath-compliance-test-suite @@ -1 +1 @@ -Subproject commit 2e62f6fb06cdb36dd982a9f39fa3810f385f1ce4 +Subproject commit fc5a04d52b5c4607206f30a2faf2ba3295cabbab diff --git a/src/grammar.pest b/src/grammar.pest index 51f7638..c4b87a8 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -1,7 +1,7 @@ -selector = _{ SOI ~ rootSelector ~ matchers ~ EOI } +selector = ${ SOI ~ rootSelector ~ matchers ~ EOI } matchers = ${ matcher* } -rootSelector = { "$" } +rootSelector = @{ "$" } matcher = !{ dotChild | union } diff --git a/src/parser.rs b/src/parser.rs index 57d3302..c3d45a7 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -16,10 +16,13 @@ struct PathParser; pub fn parse(selector: &str) -> Result { let selector_rule = PathParser::parse(Rule::selector, selector) .map_err(|e| format!("{}", e))? - .nth(1) + .nth(0) .unwrap(); selector_rule + .into_inner() + .nth(1) // skip over Rule::selector + .unwrap() .into_inner() .fold(Ok(Path::Root), |prev, r| match r.as_rule() { Rule::matcher => Ok(Path::Sel( From 78157e2b3b3b403e33a288218ccf28c39fb24bda Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Sat, 16 Apr 2022 18:45:42 +0100 Subject: [PATCH 4/8] Use personal repo for CTS --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 4972b45..88f08b5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "jsonpath-compliance-test-suite"] path = jsonpath-compliance-test-suite - url = https://github.com/jsonpath-standard/jsonpath-compliance-test-suite.git + url = git@github.com:glyn/jsonpath-compliance-test-suite.git From 8cc97c15745b962f9716375ba4461441d5968fa8 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Sun, 17 Apr 2022 13:41:14 +0100 Subject: [PATCH 5/8] fix lint --- src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index c3d45a7..097fe5e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -16,7 +16,7 @@ struct PathParser; pub fn parse(selector: &str) -> Result { let selector_rule = PathParser::parse(Rule::selector, selector) .map_err(|e| format!("{}", e))? - .nth(0) + .next() .unwrap(); selector_rule From ff9d79fc15dded214fa1a4ac4c64232ef8395d3b Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Wed, 20 Apr 2022 13:10:51 +0100 Subject: [PATCH 6/8] Correct comment --- src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 097fe5e..8032499 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -21,7 +21,7 @@ pub fn parse(selector: &str) -> Result { selector_rule .into_inner() - .nth(1) // skip over Rule::selector + .nth(1) // skip over Rule::rootSelector .unwrap() .into_inner() .fold(Ok(Path::Root), |prev, r| match r.as_rule() { From 26133492336e966711abfd5f74f78883cec75ac5 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Wed, 20 Apr 2022 13:19:43 +0100 Subject: [PATCH 7/8] Name find method consistently --- src/ast.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index c2fd948..6624884 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -77,7 +77,7 @@ impl Path { impl Selector { pub fn find<'a>(&'a self, input: &'a Value) -> Iter<'a> { match self { - Selector::Union(indices) => Box::new(indices.iter().flat_map(move |i| i.get(input))), + Selector::Union(indices) => Box::new(indices.iter().flat_map(move |i| i.find(input))), Selector::DotName(name) => Box::new(input.get(name).into_iter()), Selector::DotWildcard => match input { Value::Object(m) => Box::new(m.values()), @@ -89,7 +89,7 @@ impl Selector { } impl UnionElement { - pub fn get<'a>(&self, v: &'a Value) -> Iter<'a> { + pub fn find<'a>(&self, v: &'a Value) -> Iter<'a> { match self { UnionElement::Name(name) => Box::new(v.get(name).into_iter()), UnionElement::Slice(slice) => { From f2d7305ad03bb2e56433c6ac1709c62d1c7a3d4b Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Mon, 30 May 2022 11:00:07 +0100 Subject: [PATCH 8/8] Allow lower case hex in unicode escapes --- jsonpath-compliance-test-suite | 2 +- src/grammar.pest | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jsonpath-compliance-test-suite b/jsonpath-compliance-test-suite index fc5a04d..9235770 160000 --- a/jsonpath-compliance-test-suite +++ b/jsonpath-compliance-test-suite @@ -1 +1 @@ -Subproject commit fc5a04d52b5c4607206f30a2faf2ba3295cabbab +Subproject commit 923577060d75a8111fb3a91bdc0ab8eb2d748f1b diff --git a/src/grammar.pest b/src/grammar.pest index c4b87a8..40caaf2 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -32,16 +32,16 @@ doubleInner = @{ doubleChar* } doubleChar = { !("\"" | "\\" | '\u{00}'..'\u{1F}') ~ ANY | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") - | "\\" ~ ("u" ~ upperHexDigit{4}) + | "\\" ~ ("u" ~ hexDigit{4}) } -upperHexDigit = _{ ASCII_DIGIT | "A" | "B" | "C" | "D" | "E" | "F" } +hexDigit = _{ ASCII_DIGIT | "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b" | "c" | "d" | "e" | "f" } singleQuotedString = _{ "'" ~ singleInner ~ "'" } singleInner = @{ singleChar* } singleChar = { !("'" | "\\" | '\u{00}'..'\u{1F}') ~ ANY | "\\" ~ ("'" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") - | "\\" ~ ("u" ~ upperHexDigit{4}) + | "\\" ~ ("u" ~ hexDigit{4}) } WHITESPACE = _{ " " } \ No newline at end of file