filosganga/jsonpath

Filter implementation

Punctuality opened this issue · 3 comments

Greetings,

Forgive me, if same issue was opened before, or if I've misunderstood some part of API or implementation details.

I was wondering, if it's a known issue/task regarding implementation of Filters. As of right now, it seems like JsonPath's filters are not supported by JsonPathParser.

Example

Let's consider example provided in README:

val expression = "$.books[?(@.year > 1950)].title"

val path = JsonPathParser.parse(expression)
This will yield an erroneous result value
Left(Error(8, NonEmptyList(WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,',()))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,*,*)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,-,-)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,0,9)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,٠,٩)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,۰,۹)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,߀,߉)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,०,९)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,০,৯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,੦,੯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,૦,૯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,୦,୯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,௦,௯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,౦,౯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,೦,೯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,൦,൯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,෦,෯)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,๐,๙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,໐,໙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,༠,༩)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,၀,၉)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,႐,႙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,០,៩)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᠐,᠙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᥆,᥏)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᧐,᧙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᪀,᪉)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᪐,᪙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᭐,᭙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᮰,᮹)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᱀,᱉)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,᱐,᱙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,꘠,꘩)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,꣐,꣙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,꤀,꤉)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,꧐,꧙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,꧰,꧹)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,꩐,꩙)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,꯰,꯹)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,InRange(8,0,9)))), WithContext(expP,WithContext(selectorP,WithContext(bracketsP,WithContext(arraySliceP,InRange(8,:,:))))))))

Investigation

Upon a little bit of investigation, I've found that inside JsonPathParser, there's a defined questionMarkP:

val questionMarkP: Parser[Unit] = Parser.char('?')

Yet, as it seems, it is not being used for any of the parsers present in this class.

Also, unlike in CirceSolver, JsonPathParser is not instantiating Filter <: Exp at any point, not only syntactically, but also logically.

Added an implementation, which fixed problem for me. Though, may require additional review for completeness

Thank you @Punctuality,

We may have lost the implementation of the filter when shuffling stuff around, to generalise the implementation. I'll look in your PR, and thank you for the contribution

Released in 1.0.1