feat(regexp): regular expressions library (Go RE2)#126
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds regular expressions to jig/lisp — there was none. A
regexpnamespace, loaded by default in thelispbinary, with Clojure-style semantics on Go's RE2 engine.re-patterncompiles a first-class, reusable regex (prints«regex …»). Every function also accepts a raw pattern string (compiled on use), sore-patternis 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 isnil, faithful to Clojure viaFindStringSubmatchIndex).Design notes
#"…"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-matchesanchors with\A(?:…)\zso "whole string" holds regardless of a(?m)flag.re-replace/re-split/re-seqare 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-patternidempotent), and errors (bad pattern, wrong arg types).main.goanddocgen/libraries.go(sync test passes);LANGUAGE.mdregenerated. Full suite green with and without-tags debugger.🤖 Generated with Claude Code