lambdaclass / lambdaclass/lambda_compiler_kit

api: CompiledRegex should carry its MatchMode to prevent silent misuse

Offen
#20 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Lean
Sterne
2
Forks
1
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Problem

CompiledRegex stores only nfa : GlushkovNfa with no record of the MatchMode used during compilation. Both matchCompiled and searchCompiled call the identical Glushkov.matchString underneath — the mode distinction is only enforced inside desugar (which wraps unanchored patterns with .* in search mode).

This means a caller who compiles with .search and then calls matchCompiled instead of searchCompiled silently gets wrong semantics — no error, no warning.

-- Silent misuse: compiled for search, used as fullMatch
let compiled ← compile pattern .search
let result := matchCompiled compiled input  -- wrong! should be searchCompiled

Proposed fix

Add a mode : MatchMode field to CompiledRegex and assert (or dispatch) on it in matchCompiled/searchCompiled:

structure CompiledRegex where
  nfa  : Glushkov.GlushkovNfa
  mode : MatchMode
deriving Repr

Option A: panic/error if wrong function called for mode.
Option B: merge into a single runCompiled that dispatches based on stored mode.
Option C: remove matchCompiled/searchCompiled and expose only runCompiled.

Option C (single entry point) is cleanest — callers can't pick the wrong function.

Impact

Breaking API change for matchCompiled/searchCompiled. The CLI (LckGrep.lean) and tests need updating.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, CompiledRegex, compile, matchCompiled, searchCompiled und desugar zu finden, und untersuche anschließend den CLI-Einstiegspunkt in LckGrep.lean sowie die betroffenen Tests. Entscheide, welche der vorgeschlagenen API-Formen beabsichtigt ist, aktualisiere die Aufrufer und Tests und überprüfe, dass nicht übereinstimmende Match-Modi nicht mehr stillschweigend verwendet werden können.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Bereich
cli, compilers
Issue-Typ
Refactoring
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.