Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Unicode escape case #31

Merged
merged 8 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 2 additions & 6 deletions .github/workflows/quickstart.yml
Original file line number Diff line number Diff line change
@@ -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]

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "jsonpath_reference_implementation"
version = "0.0.1"
authors = ["Glyn Normington <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
itertools = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion jsonpath-compliance-test-suite
4 changes: 2 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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) => {
Expand Down
10 changes: 5 additions & 5 deletions src/grammar.pest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
selector = _{ SOI ~ rootSelector ~ matchers ~ EOI }
selector = ${ SOI ~ rootSelector ~ matchers ~ EOI }

matchers = ${ matcher* }
rootSelector = { "$" }
rootSelector = @{ "$" }

matcher = !{ dotChild | union }

Expand Down Expand Up @@ -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 = _{ " " }
5 changes: 4 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ struct PathParser;
pub fn parse(selector: &str) -> Result<Path, String> {
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(
Expand Down