diff --git a/.github/workflows/quickstart.yml b/.github/workflows/quickstart.yml index 450b025..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] @@ -14,7 +10,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 +34,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/.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 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" diff --git a/jsonpath-compliance-test-suite b/jsonpath-compliance-test-suite index 2e62f6f..9235770 160000 --- a/jsonpath-compliance-test-suite +++ b/jsonpath-compliance-test-suite @@ -1 +1 @@ -Subproject commit 2e62f6fb06cdb36dd982a9f39fa3810f385f1ce4 +Subproject commit 923577060d75a8111fb3a91bdc0ab8eb2d748f1b 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) => { diff --git a/src/grammar.pest b/src/grammar.pest index 51f7638..40caaf2 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 } @@ -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 diff --git a/src/parser.rs b/src/parser.rs index 57d3302..8032499 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) + .next() .unwrap(); selector_rule + .into_inner() + .nth(1) // skip over Rule::rootSelector + .unwrap() .into_inner() .fold(Ok(Path::Root), |prev, r| match r.as_rule() { Rule::matcher => Ok(Path::Sel(