Skip to content

feat(std): add the std::regex parser - #438

Merged
0xErwin1 merged 1 commit into
mainfrom
feat/regex-1-parser
Oct 28, 2026
Merged

0xErwin1 merged 1 commit into
mainfrom
feat/regex-1-parser

Conversation

@0xErwin1

Copy link
Copy Markdown
Collaborator

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, max or unbounded, greedy or lazy), group (capturing index, optional name, non-capturing) and assertion (^ $ \b \B).
  • Syntax v1:
    • escapes and classes: \d \w \s and their negations, ASCII only;
    • groups: (?: ), (?<name> ) (duplicate names rejected);
    • quantifiers: * + ? {n} {n,} {n,m} and their lazy forms, with counts up to 1000;
    • flags: (?i) and (?i: ), ASCII-only and applied at parse time (a letter becomes a class with both cases).
  • RegexError carries 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.
  • Registration: the module is in std/manifest.toml and in the formatter corpus (knownStdSubdirs, corpusStdRegex).

The decisions are documented in the module doc:

  • A literal brace is written \{.
  • a** is nothing to repeat.
  • A - at the edge of a class is a literal.
  • Backreferences and lookaround are rejected because they break the linear-time guarantee.

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.
  • Full test-std: 614/614.
  • check-std and fmt --check are clean. G6 and doc baselines are added.

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.
@0xErwin1
0xErwin1 merged commit 0c1e0fc into main Oct 28, 2026
9 checks passed
@0xErwin1
0xErwin1 deleted the feat/regex-1-parser branch October 28, 2026 19:14
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