lambdaclass / lambdaclass/lambda_compiler_kit

api: CompiledRegex should carry its MatchMode to prevent silent misuse

オープン
#20 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Lean
スター
2
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず CompiledRegex、compile、matchCompiled、searchCompiled、desugar を見つけ、次に LckGrep.lean の CLI エントリポイントと影響を受けるテストを調べます。提案されている API の形のうち、どれが意図されたものかを判断し、呼び出し元とテストを更新して、互換性のないマッチモードが暗黙的に使用できなくなっていることを確認します。

索引モデルが issue の本文から書いたものです。

評価

領域
cli, compilers
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。