Skip to content

feat(regexp): regular expressions library (Go RE2)#126

Merged
jig merged 1 commit into
developfrom
feat/regexp
Jul 22, 2026
Merged

feat(regexp): regular expressions library (Go RE2)#126
jig merged 1 commit into
developfrom
feat/regexp

Conversation

@jig

@jig jig commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds regular expressions to jig/lisp — there was none. A regexp namespace, loaded by default in the lisp binary, with Clojure-style semantics on Go's RE2 engine.

(re-matches? ¬\d+¬ "123")                 ; => true   (anchored — whole string)
(re-find?    ¬\d+¬ "abc123")              ; => true   (substring)
(re-find ¬(\d+)-(\d+"call 555-1234")   ; => ["555-1234" "555" "1234"]
(get (re-find ¬v(\d+"v42") 1)          ; => "42"
  • re-pattern compiles a first-class, reusable regex (prints «regex …»). Every function also accepts a raw pattern string (compiled on use), so re-pattern is optional.
  • re-matches? / re-find? → booleans (anchored whole-string / unanchored substring) — the primary need.
  • re-matches / re-find → Clojure-style match data: nil, the match string when there are no groups, or a vector [whole g1 g2 …] (an unmatched optional group is nil, faithful to Clojure via FindStringSubmatchIndex).

Design notes

  • RE2, not PCRE: no backreferences or lookaround; linear-time in exchange. Documented.
  • No #"…" reader literal: jig/lisp's raw ¬…¬ string already avoids escaping (¬\d+¬; a normal "\d+" is a read error), so it's the natural pattern syntax — no scanner changes.
  • re-matches anchors with \A(?:…)\z so "whole string" holds regardless of a (?m) flag.
  • re-replace / re-split / re-seq are deferred to a later iteration (agreed scope).

Test plan

  • lib/regexp/regexp_test.go: predicates (anchored vs substring, compiled vs raw), match data (no-groups → string, groups → vector, unmatched group → nil, no match → nil), the pattern value («regex …» print, re-pattern idempotent), and errors (bad pattern, wrong arg types).
  • Registered in main.go and docgen/libraries.go (sync test passes); LANGUAGE.md regenerated. Full suite green with and without -tags debugger.

🤖 Generated with Claude Code

Adds a regexp namespace, loaded by default, with first-class compiled
patterns and Clojure-style semantics:

- re-pattern compiles a reusable «regex …» value; the other functions
  accept a compiled regex or a raw pattern string (compiled on use).
- re-matches? / re-find? return booleans (anchored whole-string /
  unanchored substring).
- re-matches / re-find return Clojure-style match data: nil, the match
  string when there are no groups, or a vector [whole g1 g2 …] with an
  unmatched optional group as nil.

Patterns are Go RE2 (linear-time; no backreferences or lookaround) and
are written as raw ¬…¬ strings — jig/lisp's equivalent of Clojure's
#"…" literal, since a normal "…" string rejects \d. re-matches
anchors with \A(?:…)\z so it means the whole string regardless of
(?m). re-replace/re-split/re-seq are left for a later iteration.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jig
jig merged commit d71e25c into develop Jul 22, 2026
14 checks passed
@jig
jig deleted the feat/regexp branch July 22, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant