Subject: [Jsonpath] Re: [Technical Errata Reported] RFC9535 (8343)
From: Carsten Bormann <[email-masked]>
To: Vladimir Gorej <[email-masked]>
Cc: "Andrew Newton (andy)" <[email-masked]>, RFC Errata System <[email-masked]>, [email-masked], [email-masked], Orie Steele <[email-masked]>, [email-masked], Tim Bray <[email-masked]>, [email-masked]
Date: Wed, 26 Mar 2025 15:56:44 +0100
List-Id: Discussion of JSONPath syntax <jsonpath.ietf.org>

On 2025-03-26, at 15:19, Vladimir Gorej <[email-masked]> wrote:
> 
> Would something like that work for the GLOBAL errata report?

I would probably simplify this to the below.
(And Apple Mail will then destroy the alignment, sorry about that.)

Grüße, Carsten

Original Text
-------------

;; Section 2.3.5.1
comparable          = literal /
                      singular-query / ; singular query value
                      function-expr    ; ValueType

;; Section 2.4
function-argument   = literal /
                      filter-query / ; (includes singular-query)
                      logical-expr /
                      function-expr

;; Appendix A copies these two rules into the collected ABNF.

Corrected Text
--------------

;; Section 2.3.5.1
comparable          = singular-query / ; singular query value
                      function-expr /  ; ValueType
                      literal

;; Section 2.4
function-argument   = logical-expr /
                      filter-query / ; (includes singular-query)
                      function-expr /
                      literal

;; Appendix A needs to copy these two updates in the collected ABNF.

Notes
-----

The ABNF grammars in RFC 9535 were designed to be directly usable with PEG (Parsing Expression Grammar) parsers.

However, PEG parsers will fail to parse $[?blt(1==1)] or $[?true(1)==0] with the grammar as given, as they employ prioritized choice, where the order matters.

In the order given, they will try to match the `literal` rule in `function-argument` with the input `1==1`, and find that the `1` indeed matches a `number`, completing the match for `function-argument` and preempting the other choices.  The intended rest of the `function-argument`, `==1` does not match anything, and the rule fails.
By putting the more complex `logical-expr` first, the whole `1==1` matches, and the rule succeeds as intended.

Similary, the function name `true` matches as the literal `true` instead, and preempts parsing `true(1)` as the more complex `function-expr`.  Putting the `literal` choice last prevents the preemptive match.