pandaman64/lean-regex

Correctly fail invalid range operators

Offen

#152 geöffnet am 30.12.2025

 (0 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Lean (14 Forks)auto 404
bughelp wanted

Repository-Metriken

Stars
 (109 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 12h 48m) (2 gemergte PRs in 30 T)

Beschreibung

We have extended the bracketed character class parsers with new capabilities like #150 while breaking error handling of range operators. Namely,

  • [z-a] should be an error (as the range is valid only if 'z' ≦ 'a'), but is treated as a union of z, -, and a.
  • Also, [\d-a] should be an error, but accepted as a union

We want to restore the original behavior that returns .error .invalidRange in such cases.

I'd expect that we need a rework of the bracketed class parsers to conform to a grammar like this:

escapedChar   ::= '\' c
singleChar    ::= c (except for '[', ']', '\', ...)
atom          ::= escapedChar | singleChar
rangeExpr     ::= atom ('-' atom)?
setOp         ::= '&&' | '||' | '--' | '~~'
setExpr       ::= bracketed (setOp bracketed)*
singleExpr    ::= rangeExpr | setExpr
bracketed     ::= '[' ('^')? singleExpr* ']'

The idea is to make a range expression a proper level in the hierarchy and insert .commit at appropriate levels.

Contributor Guide