Repository navigation
feat(std): add the std::regex parser - #438
Merged
Merged
Conversation
First slice of std::regex: parseRegex turns a pattern into an arena AST (literals, any scalar but newline, classes with sorted merged ranges, ASCII \d \w \s and negations, anchors and ASCII word boundaries, capturing, non-capturing and named groups, alternation, greedy and lazy repetition with counts up to 1000, and ASCII (?i) folded at parse time). Errors carry a 1-based column: unclosed group, nothing to repeat, invalid range, unclosed class, unknown escape, invalid repetition, and unsupported backreferences and lookaround. Matching arrives in the next slices. The module is registered in std/manifest.toml and in the formatter corpus.
This was referenced Oct 28, 2026
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.
First of four slices of
std::regex, a linear-time engine in pure Ignis. The design is RE2-style: pattern → AST → program → Pike VM. There is no backtracking, so there is no ReDoS. This slice adds only the parser. Matching, captures and replacement come in the next three.What changes
parseRegex(pattern: str): Result<RegexAst, RegexError>. The AST is an arena (nodes: Vector<RegexNode>,root,groupCount) whose children are indices, which avoids recursive owned types. The node kinds are literal scalar, any scalar but\n, class (sorted, merged ranges plus negation), concatenation, alternation, repetition (min,maxor unbounded, greedy or lazy), group (capturing index, optional name, non-capturing) and assertion (^ $ \b \B).\d \w \sand their negations, ASCII only;(?: ),(?<name> )(duplicate names rejected);* + ? {n} {n,} {n,m}and their lazy forms, with counts up to 1000;(?i)and(?i: ), ASCII-only and applied at parse time (a letter becomes a class with both cases).RegexErrorcarries a 1-based column counted in scalars. For example:unclosed group at column 7,nothing to repeat,invalid range z-a,unclosed class,empty class,unknown escape \q,invalid repetition,repetition count above 1000,unsupported: backreference,unsupported: lookaround.std/manifest.tomland in the formatter corpus (knownStdSubdirs,corpusStdRegex).The decisions are documented in the module doc:
\{.a**isnothing to repeat.-at the edge of a class is a literal.Evidence
ignis test-std regex: 18 tests and about 120 assertions, covering the AST shape of every construct and every error message with its exact column.test-std: 614/614.check-stdandfmt --checkare clean. G6 and doc baselines are added.