Subject: [Jsonpath] Is [^] legal?

From: Tim Bray <[email-masked]>
Date: Wed, 26 Jan 2022 06:38:08 -0800

[Am AFK and wanted to capture this before it vanished into the tweetstream.
I assume it just matches literal "^"? -Tim]

The Daniel Martin who follows all the other ones (@dtm609) tweeted at 3:23
a.m. on Wed., Jan. 26, 2022:
The grammar seems to allow this I-Regexp:

[^]

(Since a single caret is a legal CCE1)

I wonder what the intended semantic of that expression is. In PCRE or RE2,
that's a syntax error but Ecmascript accepts it as a synonym for ".".

I'm not familiar enough with XSD regex to say.
(
https://twitter.com/dtm609/status/1486298655497854979?t=WEw50TO63UIVdN9aWIt4nA&s=03
)

---

From: Michael Kay <[email-masked]>
Date: Wed, 26 Jan 2022 15:49:19 +0000

XSD 1.1 part 2 says in §G.4.1:

Note: For example, the string '[^X]' is ambiguous according the grammar rules, denoting either a character class consisting of a negative character group with 'X' as a member, or a positive character class with 'X' and '^' as members.  The normative prose rule just given requires that the first interpretation be taken.
The string '[^]' is unambiguous: the grammar recognizes it as a character class expression containing a positive character group containing just the character '^'.  But the grammatical derivation of the string violates the rule just given, so the string '[^]' must not be accepted as a regular expression.

Michael Kay
Saxonica

> On 26 Jan 2022, at 14:38, Tim Bray <[email-masked]> wrote:
> 
> [Am AFK and wanted to capture this before it vanished into the tweetstream. I assume it just matches literal "^"? -Tim]
> 
> The Daniel Martin who follows all the other ones (@dtm609) tweeted at 3:23 a.m. on Wed., Jan. 26, 2022:
> I wonder what the intended semantic of that expression is. In PCRE or RE2, that's a syntax error but Ecmascript accepts it as a synonym for ".".
> 
> (https://twitter.com/dtm609/status/1486298655497854979?t=WEw50TO63UIVdN9aWIt4nA&s=03 <https://twitter.com/dtm609/status/1486298655497854979?t=WEw50TO63UIVdN9aWIt4nA&s=03>) 
> -- 
> JSONpath mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/jsonpath

---

From: Carsten Bormann <[email-masked]>
Date: Wed, 26 Jan 2022 17:47:34 +0100

> The string '[^]' is unambiguous: the grammar recognizes it as a character class expression containing a positive character group containing just the character '^'.  But the grammatical derivation o…

Indeed.  I tried to reflect the errata in the grammar that is in the document.

However, I fell into the trap that my tools are using a “prioritized choice” interpretation of ABNF (PEG), so they won’t accept [^], because the caret already matches the optional [“^”] part of the rule.

So the choice to fix this is adding prose like XSD 1.1 did, or actually opening up the ABNF to disallow this one case.  (Negative lookahead is a feature of PEG for a reason; to bad we don’t have that in ABNF.)

(The alternative interpretation of [^] as “not nothing” is different from “.”, by the way, as the latter doesn’t match LF/CR/LS/PS.)

Grüße, Carsten