From 7e4425413489c39eca0b4f92283a062a4271ea78 Mon Sep 17 00:00:00 2001 From: Ignacio Perez Date: Wed, 28 Oct 2026 15:47:48 -0300 Subject: [PATCH] feat(std): add the std::regex parser 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. --- ignis/format/corpus_tests.ign | 6 + std/manifest.toml | 1 + std/regex/ast.ign | 289 ++++++ std/regex/mod.ign | 88 ++ std/regex/parser.ign | 832 ++++++++++++++++++ std/regex/tests.ign | 219 +++++ .../__parse_verdicts__/std_regex_ast.txt | 2 + .../__parse_verdicts__/std_regex_mod.txt | 2 + .../__parse_verdicts__/std_regex_parser.txt | 2 + .../__parse_verdicts__/std_regex_tests.txt | 2 + .../__doc_baselines__/output__std_io_mod.json | 699 +++++++++++++++ 11 files changed, 2142 insertions(+) create mode 100644 std/regex/ast.ign create mode 100644 std/regex/mod.ign create mode 100644 std/regex/parser.ign create mode 100644 std/regex/tests.ign create mode 100644 test_cases/__parse_verdicts__/std_regex_ast.txt create mode 100644 test_cases/__parse_verdicts__/std_regex_mod.txt create mode 100644 test_cases/__parse_verdicts__/std_regex_parser.txt create mode 100644 test_cases/__parse_verdicts__/std_regex_tests.txt diff --git a/ignis/format/corpus_tests.ign b/ignis/format/corpus_tests.ign index f596428fe..13506cb4e 100644 --- a/ignis/format/corpus_tests.ign +++ b/ignis/format/corpus_tests.ign @@ -860,6 +860,11 @@ function corpusStdRc(): void { runFixedPointDir("std-rc", "std/rc"); } +@test +function corpusStdRegex(): void { + runFixedPointDir("std-regex", "std/regex"); +} + @test function corpusStdResult(): void { runFixedPointDir("std-result", "std/result"); @@ -1075,6 +1080,7 @@ function knownStdSubdirs(): Vector { names.push(String::create("process")); names.push(String::create("ptr")); names.push(String::create("rc")); + names.push(String::create("regex")); names.push(String::create("result")); names.push(String::create("runtime")); names.push(String::create("serializer")); diff --git a/std/manifest.toml b/std/manifest.toml index 7bf0014d9..b8c0f9b1c 100644 --- a/std/manifest.toml +++ b/std/manifest.toml @@ -43,6 +43,7 @@ sync = "sync/mod.ign" thread = "thread/mod.ign" net = "net/mod.ign" http = "http/mod.ign" +regex = "regex/mod.ign" web = "web/mod.ign" sqlite3 = "sqlite3/mod.ign" orm = "orm/mod.ign" diff --git a/std/regex/ast.ign b/std/regex/ast.ign new file mode 100644 index 000000000..3871ab00f --- /dev/null +++ b/std/regex/ast.ign @@ -0,0 +1,289 @@ +//! The parsed form of a pattern: an arena of `RegexNode` addressed by index, +//! which the compiler walks from `RegexAst.root`. + +/// A pattern that could not be parsed: what is wrong and where. +export record RegexError { + errorColumn: u64; + errorMessage: String; + + /// An error at the 1-based `column` with `message`. + public static create(column: u64, message: String): RegexError { + return RegexError { errorColumn: column, errorMessage: message }; + } + + /// The 1-based column of the offending part, counted in Unicode scalars. + public column(&self): u64 { + return self.errorColumn; + } + + /// What is wrong, without the column. + public message(&self): str { + return self.errorMessage.toStr(); + } + + /// ` at column `. + public toString(&self): String { + let mut text: String = self.errorMessage.clone(); + text.pushStr(" at column "); + let column: String = self.errorColumn.toString(); + text.push(&column); + return text; + } +} + +/// An inclusive range of Unicode scalar values. +export record RegexRange { + public start: u32; + public end: u32; +} + +/// A set of scalars: sorted, non-overlapping, non-adjacent ranges. A negated +/// class matches every scalar outside them. +export record RegexClass { + public ranges: Vector; + public negated: boolean; +} + +/// A zero-width condition on the position between two scalars. +export enum RegexAssertion { + /// `^`: the start of the text. + START, + + /// `$`: the end of the text. + END, + + /// `\b`: one side is an ASCII word scalar and the other is not. + WORD_BOUNDARY, + + /// `\B`: both sides are ASCII word scalars, or neither is. + NOT_WORD_BOUNDARY, +} + +/// A repetition of `child` between `min` and `max` times. +export record RegexRepeat { + public child: u64; + public min: u32; + + /// Ignored when `bounded` is false. + public max: u32; + public bounded: boolean; + + /// Greedy prefers more repetitions, lazy fewer. + public greedy: boolean; +} + +/// A parenthesized subpattern. +export record RegexGroup { + public child: u64; + public capturing: boolean; + + /// 1-based capture index in order of the opening parenthesis; 0 when not + /// capturing. + public index: u64; + + /// The `(?...)` name, empty when there is none. + public name: String; +} + +/// One node of a parsed pattern. Children are indices into `RegexAst.nodes`. +/// +/// Case-insensitive matching is resolved here: under `(?i)` an ASCII letter +/// becomes a class holding both cases, and classes gain the other case of +/// their ASCII letters. +export enum RegexNode { + /// Matches the empty string. + EMPTY, + + /// One scalar. + LITERAL(u32), + + /// `.`: any scalar except `\n`. + ANY_EXCEPT_NEWLINE, + CLASS(RegexClass), + + /// Children one after another. + CONCAT(Vector), + + /// The first child that matches, leftmost-first. + ALTERNATE(Vector), + REPEAT(RegexRepeat), + GROUP(RegexGroup), + ASSERT(RegexAssertion), +} + +/// A parsed pattern. +export record RegexAst { + public nodes: Vector; + public root: u64; + + /// The number of capturing groups, the whole match not included. + public groupCount: u64; +} + +function regexHexDigit(value: u32): u8 { + if (value < 10) { + return '0' as u8 + value as u8; + } + + return 'A' as u8 + (value - 10) as u8; +} + +function regexDebugScalar(text: &mut String, scalar: u32): void { + if (scalar > 0x20 && scalar < 0x7F && scalar != '(' as u32 && scalar != ')' as u32 && scalar != ',' as u32 && scalar != '-' as u32) { + text.pushByte(scalar as u8); + return; + } + + text.pushStr("U+"); + let mut shift: u32 = 20; + let mut started: boolean = false; + + while (true) { + let digit: u32 = (scalar >> shift) & 0xF; + + if (digit != 0 || started || shift <= 12) { + text.pushByte(regexHexDigit(digit)); + started = true; + } + + if (shift == 0) { + break; + } + + shift -= 4; + } +} + +function regexDebugChildren(ast: &RegexAst, children: &Vector, text: &mut String): void { + let mut index: u64 = 0; + + while (index < children.length()) { + if (index > 0) { + text.pushStr(","); + } + + regexDebugNode(ast, *children.get(index).unwrap(), text); + index += 1; + } +} + +function regexDebugNode(ast: &RegexAst, id: u64, text: &mut String): void { + match (ast.nodes.get(id).unwrap()) { + RegexNode::EMPTY -> { + text.pushStr("empty"); + }, + RegexNode::LITERAL(scalar) -> { + text.pushStr("lit("); + regexDebugScalar(text, scalar); + text.pushStr(")"); + }, + RegexNode::ANY_EXCEPT_NEWLINE -> { + text.pushStr("any"); + }, + RegexNode::CLASS(class) -> { + if (class.negated) { + text.pushStr("nclass("); + } else { + text.pushStr("class("); + } + + let mut index: u64 = 0; + + while (index < class.ranges.length()) { + let range: &RegexRange = class.ranges.get(index).unwrap(); + + if (index > 0) { + text.pushStr(","); + } + + regexDebugScalar(text, range.start); + + if (range.end != range.start) { + text.pushStr("-"); + regexDebugScalar(text, range.end); + } + + index += 1; + } + + text.pushStr(")"); + }, + RegexNode::CONCAT(children) -> { + text.pushStr("cat("); + regexDebugChildren(ast, &children, text); + text.pushStr(")"); + }, + RegexNode::ALTERNATE(children) -> { + text.pushStr("alt("); + regexDebugChildren(ast, &children, text); + text.pushStr(")"); + }, + RegexNode::REPEAT(repeat) -> { + text.pushStr("rep{"); + let min: String = repeat.min.toString(); + text.push(&min); + text.pushStr(","); + + if (repeat.bounded) { + let max: String = repeat.max.toString(); + text.push(&max); + } else { + text.pushStr("inf"); + } + + text.pushStr("}"); + + if (!repeat.greedy) { + text.pushStr("?"); + } + + text.pushStr("("); + regexDebugNode(ast, repeat.child, text); + text.pushStr(")"); + }, + RegexNode::GROUP(group) -> { + if (group.capturing) { + text.pushStr("group("); + let index: String = group.index.toString(); + text.push(&index); + + if (group.name.length() > 0) { + text.pushStr(":"); + text.push(&group.name); + } + + text.pushStr(","); + } else { + text.pushStr("ncgroup("); + } + + regexDebugNode(ast, group.child, text); + text.pushStr(")"); + }, + RegexNode::ASSERT(assertion) -> { + match (assertion) { + RegexAssertion::START -> { + text.pushStr("start"); + }, + RegexAssertion::END -> { + text.pushStr("end"); + }, + RegexAssertion::WORD_BOUNDARY -> { + text.pushStr("wordb"); + }, + RegexAssertion::NOT_WORD_BOUNDARY -> { + text.pushStr("nwordb"); + }, + }; + }, + }; +} + +/// A compact text form of `ast` for tests: `cat(lit(a),rep{0,inf}(lit(b)))`. +/// Scalars that are not printable ASCII, or that the form itself uses, print +/// as `U+XXXX`. +export function regexAstDebug(ast: &RegexAst): String { + let mut text: String = String::new(); + regexDebugNode(ast, ast.root, &mut text); + return text; +} diff --git a/std/regex/mod.ign b/std/regex/mod.ign new file mode 100644 index 000000000..85d098ae4 --- /dev/null +++ b/std/regex/mod.ign @@ -0,0 +1,88 @@ +//! +//! # Regex +//! +//! Regular expressions with linear-time matching, in the style of RE2: a +//! pattern is parsed into an AST, compiled to a program and run by a Pike VM +//! that simulates the NFA, so matching takes O(text x program) time and never +//! backtracks. +//! +//! This slice holds the parser only. Compiling and matching (`Regex::new`, +//! `isMatch`, `find`, `findAll`, captures, `replaceAll`, `split`) arrive in +//! the next slices. +//! +//! ## Exports +//! +//! | Export | Description | +//! |------------------------|----------------------------------------------------------------| +//! | `parseRegex` | `parseRegex(pattern)`: `Result` | +//! | `RegexError` | `column()` (1-based, in Unicode scalars), `message()`, `toString()` | +//! | `RegexAst` | `nodes`, `root`, `groupCount` | +//! | `RegexNode` | `EMPTY`, `LITERAL`, `ANY_EXCEPT_NEWLINE`, `CLASS`, `CONCAT`, `ALTERNATE`, `REPEAT`, `GROUP`, `ASSERT` | +//! | `RegexClass` | Sorted, merged `ranges` and `negated` | +//! | `RegexRange` | Inclusive `start` and `end` scalar values | +//! | `RegexRepeat` | `child`, `min`, `max`, `bounded`, `greedy` | +//! | `RegexGroup` | `child`, `capturing`, `index`, `name` | +//! | `RegexAssertion` | `START`, `END`, `WORD_BOUNDARY`, `NOT_WORD_BOUNDARY` | +//! | `REGEX_MAX_REPETITION` | The largest count `{n,m}` accepts: 1000 | +//! +//! ## Syntax +//! +//! | Syntax | Meaning | +//! |-----------------------------------|----------------------------------------------------------| +//! | `x` | The scalar `x`, any UTF-8 scalar | +//! | `.` | Any scalar except `\n` | +//! | `\n` `\t` `\r` `\f` `\v` | Control scalars | +//! | `\.` `\*` `\\` ... | Any escaped ASCII punctuation is itself | +//! | `[abc]` `[a-z]` `[^...]` | Classes, ranges, negation; escapes work inside | +//! | `\d` `\w` `\s` and `\D` `\W` `\S` | `[0-9]`, `[0-9A-Za-z_]`, `[ \t\n\r\f\v]` and negations (ASCII) | +//! | `^` `$` | Start and end of the whole text, not of a line | +//! | `\b` `\B` | ASCII word boundary and its negation | +//! | `(x)` `(?:x)` `(?x)` | Capturing, non-capturing and named groups | +//! | `x\|y` | Alternation, leftmost-first | +//! | `x*` `x+` `x?` | Zero or more, one or more, zero or one | +//! | `x{n}` `x{n,}` `x{n,m}` | Counted repetition, counts at most 1000 | +//! | `x*?` `x+?` `x??` `x{n,m}?` | Lazy forms: prefer fewer repetitions | +//! | `(?i)` `(?i:x)` | ASCII case-insensitive for the rest of the enclosing group, or inside `x` | +//! +//! Group names are `[A-Za-z_][A-Za-z0-9_]*` and must be unique. Capturing +//! groups are numbered from 1 in the order of their `(`. +//! +//! The parser is strict where a pattern would otherwise be ambiguous: +//! +//! - `{` always starts a counted repetition; a literal brace is `\{`. A +//! `{` that is not `{n}`, `{n,}` or `{n,m}` is `invalid repetition`. A +//! lone `}` or `]` is a literal. +//! - A quantifier after a quantifier (`a**`, `a+*`, `a{2}{3}`) and a +//! quantifier after `^`, `$`, `\b` or `\B` are `nothing to repeat`; the +//! `?` of a lazy form is part of its quantifier. +//! - `[]` and `[^]` are `empty class`; a `]` inside a class is `\]`. A `-` +//! first or last in a class is a literal. +//! +//! ## Errors +//! +//! Every error carries the 1-based column, counted in Unicode scalars, of +//! the part that is wrong: `unclosed group` (at its `(`), `unmatched )`, +//! `nothing to repeat`, `invalid range z-a` (at its `-`), `unclosed class` +//! (at its `[`), `empty class`, `trailing backslash`, `unknown escape \q`, +//! `invalid repetition`, `invalid repetition range`, `repetition count above +//! 1000`, `invalid group name`, `duplicate group name x`, `unknown group +//! flag`, `unsupported: backreference` and `unsupported: lookaround`. +//! +//! Backreferences (`\1`) and lookaround (`(?=`, `(?!`, `(?<=`, `(? `RegexAst`, or the first `RegexError`. + +import + RegexAssertion, + RegexAst, + RegexClass, + RegexError, + RegexGroup, + RegexNode, + RegexRange, + RegexRepeat, +from "./ast"; + +/// The largest count a `{n}`, `{n,}` or `{n,m}` may use, so that a pattern +/// cannot compile to an unbounded program. +export const REGEX_MAX_REPETITION: u32 = 1000; + +/// The highest Unicode scalar value. +const REGEX_MAX_SCALAR: u32 = 0x10FFFF; + +/// What `regexParseAtom` returns for `(?i)`, which sets a flag and adds no +/// node. +const REGEX_NO_NODE: u64 = 0xFFFFFFFFFFFFFFFF; + +record RegexParser { + scalars: Vector; + position: u64; + nodes: Vector; + groupCount: u64; + names: Vector; + caseInsensitive: boolean; + failed: boolean; + errorColumn: u64; + errorMessage: String; +} + +/// A class item read inside `[...]` or after `\` outside it: one scalar or +/// a shorthand set such as `\d`. +record RegexClassItem { + scalar: u32; + isSet: boolean; + set: Vector; +} + +function regexAtEnd(parser: &mut RegexParser): boolean { + return parser.position >= parser.scalars.length(); +} + +function regexCurrent(parser: &mut RegexParser): u32 { + return *parser.scalars.get(parser.position).unwrap(); +} + +/// Whether the scalar `offset` past the current one exists and is `scalar`. +function regexPeekIs(parser: &mut RegexParser, offset: u64, scalar: u32): boolean { + let index: u64 = parser.position + offset; + + if (index >= parser.scalars.length()) { + return false; + } + + return *parser.scalars.get(index).unwrap() == scalar; +} + +/// The 1-based column of the current scalar. +function regexColumn(parser: &mut RegexParser): u64 { + return parser.position + 1; +} + +/// Records the first error; later ones are ignored. +function regexFail(parser: &mut RegexParser, column: u64, message: String): void { + if (parser.failed) { + return; + } + + parser.failed = true; + parser.errorColumn = column; + parser.errorMessage = message; +} + +function regexFailStr(parser: &mut RegexParser, column: u64, message: str): void { + regexFail(parser, column, String::create(message)); +} + +function regexAddNode(parser: &mut RegexParser, node: RegexNode): u64 { + parser.nodes.push(node); + return parser.nodes.length() - 1; +} + +function regexIsDigit(scalar: u32): boolean { + return scalar >= '0' as u32 && scalar <= '9' as u32; +} + +function regexIsNameStart(scalar: u32): boolean { + return (scalar >= 'a' as u32 && scalar <= 'z' as u32) || (scalar >= 'A' as u32 && scalar <= 'Z' as u32) || scalar == '_' as u32; +} + +function regexIsQuantifier(scalar: u32): boolean { + return scalar == '*' as u32 || scalar == '+' as u32 || scalar == '?' as u32 || scalar == '{' as u32; +} + +function regexPushRange(ranges: &mut Vector, start: u32, end: u32): void { + ranges.push(RegexRange { start: start, end: end }); +} + +/// Sorts `ranges` and merges overlapping or adjacent ones. +function regexNormalize(ranges: &mut Vector): Vector { + ranges.sort((left: &RegexRange, right: &RegexRange): i32 -> { + if (left.start < right.start) { + return -1; + } + + if (left.start > right.start) { + return 1; + } + + return 0; + }); + + let mut merged: Vector = Vector::new(); + let mut index: u64 = 0; + + while (index < ranges.length()) { + let range: &RegexRange = ranges.get(index).unwrap(); + let count: u64 = merged.length(); + + if (count > 0) { + let last: &mut RegexRange = merged.getMut(count - 1).unwrap(); + + if (range.start <= last.end + 1) { + if (range.end > last.end) { + last.end = range.end; + } + + index += 1; + continue; + } + } + + regexPushRange(&mut merged, range.start, range.end); + index += 1; + } + + return merged; +} + +/// The scalars outside `ranges`, which must be normalized. +function regexComplement(ranges: &Vector): Vector { + let mut result: Vector = Vector::new(); + let mut next: u32 = 0; + let mut index: u64 = 0; + + while (index < ranges.length()) { + let range: &RegexRange = ranges.get(index).unwrap(); + + if (range.start > next) { + regexPushRange(&mut result, next, range.start - 1); + } + + next = range.end + 1; + index += 1; + } + + if (next <= REGEX_MAX_SCALAR) { + regexPushRange(&mut result, next, REGEX_MAX_SCALAR); + } + + return result; +} + +/// Adds the other ASCII case of every ASCII letter in `ranges`. +function regexAddCaseCounterparts(ranges: &mut Vector): void { + let count: u64 = ranges.length(); + let mut index: u64 = 0; + + while (index < count) { + let start: u32 = ranges.get(index).unwrap().start; + let end: u32 = ranges.get(index).unwrap().end; + let lowerStart: u32 = start > 'a' as u32 ? start : 'a' as u32; + let lowerEnd: u32 = end < 'z' as u32 ? end : 'z' as u32; + + if (lowerStart <= lowerEnd) { + regexPushRange(ranges, lowerStart - 32, lowerEnd - 32); + } + + let upperStart: u32 = start > 'A' as u32 ? start : 'A' as u32; + let upperEnd: u32 = end < 'Z' as u32 ? end : 'Z' as u32; + + if (upperStart <= upperEnd) { + regexPushRange(ranges, upperStart + 32, upperEnd + 32); + } + + index += 1; + } +} + +/// The ranges of `\d`, `\w`, `\s` or their negations, or `false` when +/// `letter` is none of them. +function regexShorthand(letter: u32, ranges: &mut Vector): boolean { + let mut base: Vector = Vector::new(); + let lower: u32 = letter >= 'A' as u32 && letter <= 'Z' as u32 ? letter + 32 : letter; + + if (lower == 'd' as u32) { + regexPushRange(&mut base, '0' as u32, '9' as u32); + } else if (lower == 'w' as u32) { + regexPushRange(&mut base, '0' as u32, '9' as u32); + regexPushRange(&mut base, 'A' as u32, 'Z' as u32); + regexPushRange(&mut base, '_' as u32, '_' as u32); + regexPushRange(&mut base, 'a' as u32, 'z' as u32); + } else if (lower == 's' as u32) { + regexPushRange(&mut base, 0x09, 0x0D); + regexPushRange(&mut base, 0x20, 0x20); + } else { + return false; + } + + let mut set: Vector = base; + + if (letter != lower) { + set = regexComplement(&set); + } + let mut index: u64 = 0; + + while (index < set.length()) { + let range: &RegexRange = set.get(index).unwrap(); + regexPushRange(ranges, range.start, range.end); + index += 1; + } + + return true; +} + +/// The scalar an escape `\letter` stands for, for the escapes that stand +/// for one scalar: control escapes and escaped ASCII punctuation. +function regexEscapedScalar(letter: u32): Option { + if (letter == 'n' as u32) { + return Option::SOME(0x0A); + } + + if (letter == 't' as u32) { + return Option::SOME(0x09); + } + + if (letter == 'r' as u32) { + return Option::SOME(0x0D); + } + + if (letter == 'f' as u32) { + return Option::SOME(0x0C); + } + + if (letter == 'v' as u32) { + return Option::SOME(0x0B); + } + + let isPunctuation: boolean = (letter >= 0x21 && letter <= 0x2F) || (letter >= 0x3A && letter <= 0x40) || (letter >= 0x5B && letter <= 0x60) || (letter >= 0x7B && letter <= 0x7E); + + if (isPunctuation) { + return Option::SOME(letter); + } + + return Option::NONE; +} + +/// Reads the escape at the current `\`. `\b` and `\B` are not handled +/// here: outside a class the caller reads them first, and inside a class +/// they are unknown escapes. `NONE` after recording an error. +function regexParseEscapeItem(parser: &mut RegexParser): Option { + let column: u64 = regexColumn(parser); + parser.position += 1; + + if (regexAtEnd(parser)) { + regexFailStr(parser, column, "trailing backslash"); + return Option::NONE; + } + + let letter: u32 = regexCurrent(parser); + parser.position += 1; + + if (letter >= '1' as u32 && letter <= '9' as u32) { + regexFailStr(parser, column, "unsupported: backreference"); + return Option::NONE; + } + + let mut set: Vector = Vector::new(); + + if (regexShorthand(letter, &mut set)) { + return Option::SOME(RegexClassItem { scalar: 0, isSet: true, set: set }); + } + + if (let Option::SOME(scalar) = regexEscapedScalar(letter)) { + return Option::SOME(RegexClassItem { scalar: scalar, isSet: false, set: set }); + } + + let mut message: String = String::create("unknown escape \\"); + message.pushChar(letter as char); + regexFail(parser, column, message); + return Option::NONE; +} + +/// A class node for `ranges`, case-folded under `(?i)`. +function regexClassNode( + parser: &mut RegexParser, + ranges: &mut Vector, + negated: boolean +): u64 { + if (parser.caseInsensitive) { + regexAddCaseCounterparts(ranges); + } + + let normalized: Vector = regexNormalize(ranges); + return regexAddNode(parser, RegexNode::CLASS(RegexClass { ranges: normalized, negated: negated })); +} + +/// A literal node, or under `(?i)` a class of both cases of an ASCII letter. +function regexLiteralNode(parser: &mut RegexParser, scalar: u32): u64 { + let isLetter: boolean = (scalar >= 'a' as u32 && scalar <= 'z' as u32) || (scalar >= 'A' as u32 && scalar <= 'Z' as u32); + + if (parser.caseInsensitive && isLetter) { + let mut ranges: Vector = Vector::new(); + regexPushRange(&mut ranges, scalar, scalar); + return regexClassNode(parser, &mut ranges, false); + } + + return regexAddNode(parser, RegexNode::LITERAL(scalar)); +} + +/// Reads one class item at the current position inside `[...]`. +function regexParseClassItem(parser: &mut RegexParser): Option { + if (regexCurrent(parser) == '\\' as u32) { + return regexParseEscapeItem(parser); + } + + let scalar: u32 = regexCurrent(parser); + parser.position += 1; + return Option::SOME(RegexClassItem { scalar: scalar, isSet: false, set: Vector::new() }); +} + +/// Parses `[...]` starting at the current `[`. +function regexParseClass(parser: &mut RegexParser): Option { + let openColumn: u64 = regexColumn(parser); + parser.position += 1; + let mut negated: boolean = false; + + if (!regexAtEnd(parser) && regexCurrent(parser) == '^' as u32) { + negated = true; + parser.position += 1; + } + + let mut ranges: Vector = Vector::new(); + let mut itemCount: u64 = 0; + + while (true) { + if (regexAtEnd(parser)) { + regexFailStr(parser, openColumn, "unclosed class"); + return Option::NONE; + } + + if (regexCurrent(parser) == ']' as u32) { + if (itemCount == 0) { + regexFailStr(parser, openColumn, "empty class"); + return Option::NONE; + } + + parser.position += 1; + break; + } + + let Option::SOME(first) = regexParseClassItem(parser) else { + return Option::NONE; + }; + + itemCount += 1; + + let isRange: boolean = !regexAtEnd(parser) && regexCurrent(parser) == '-' as u32 && parser.position + 1 < parser.scalars.length() && !regexPeekIs(parser, 1, ']' as u32); + + if (!isRange) { + if (first.isSet) { + let mut index: u64 = 0; + + while (index < first.set.length()) { + let range: &RegexRange = first.set.get(index).unwrap(); + regexPushRange(&mut ranges, range.start, range.end); + index += 1; + } + } else { + regexPushRange(&mut ranges, first.scalar, first.scalar); + } + + continue; + } + + let dashColumn: u64 = regexColumn(parser); + parser.position += 1; + + let Option::SOME(last) = regexParseClassItem(parser) else { + return Option::NONE; + }; + + if (first.isSet || last.isSet) { + regexFailStr(parser, dashColumn, "invalid range"); + return Option::NONE; + } + + if (last.scalar < first.scalar) { + let mut message: String = String::create("invalid range "); + message.pushChar(first.scalar as char); + message.pushStr("-"); + message.pushChar(last.scalar as char); + regexFail(parser, dashColumn, message); + return Option::NONE; + } + + regexPushRange(&mut ranges, first.scalar, last.scalar); + } + + return Option::SOME(regexClassNode(parser, &mut ranges, negated)); +} + +/// Reads a decimal count at the current position for `{...}`; `NONE` +/// without consuming anything when no digit is there. A count above the +/// limit is recorded as an error against `braceColumn`. +function regexParseCount(parser: &mut RegexParser, braceColumn: u64): Option { + if (regexAtEnd(parser) || !regexIsDigit(regexCurrent(parser))) { + return Option::NONE; + } + + let mut value: u32 = 0; + let mut tooLarge: boolean = false; + + while (!regexAtEnd(parser) && regexIsDigit(regexCurrent(parser))) { + if (!tooLarge) { + value = value * 10 + (regexCurrent(parser) - '0' as u32); + + if (value > REGEX_MAX_REPETITION) { + tooLarge = true; + } + } + + parser.position += 1; + } + + if (tooLarge) { + let mut message: String = String::create("repetition count above "); + let limit: String = REGEX_MAX_REPETITION.toString(); + message.push(&limit); + regexFail(parser, braceColumn, message); + } + + return Option::SOME(value); +} + +/// Parses the quantifier at the current position and wraps `child` in it. +function regexParseQuantifier(parser: &mut RegexParser, child: u64): Option { + let column: u64 = regexColumn(parser); + let symbol: u32 = regexCurrent(parser); + parser.position += 1; + let mut min: u32 = 0; + let mut max: u32 = 0; + let mut bounded: boolean = false; + + if (symbol == '+' as u32) { + min = 1; + } else if (symbol == '?' as u32) { + max = 1; + bounded = true; + } else if (symbol == '{' as u32) { + let Option::SOME(low) = regexParseCount(parser, column) else { + regexFailStr(parser, column, "invalid repetition"); + return Option::NONE; + }; + + if (parser.failed) { + return Option::NONE; + } + + min = low; + max = low; + bounded = true; + + if (!regexAtEnd(parser) && regexCurrent(parser) == ',' as u32) { + parser.position += 1; + + if (let Option::SOME(high) = regexParseCount(parser, column)) { + if (parser.failed) { + return Option::NONE; + } + + max = high; + } else { + bounded = false; + } + } + + if (regexAtEnd(parser) || regexCurrent(parser) != '}' as u32) { + regexFailStr(parser, column, "invalid repetition"); + return Option::NONE; + } + + parser.position += 1; + + if (bounded && max < min) { + regexFailStr(parser, column, "invalid repetition range"); + return Option::NONE; + } + } + + let mut greedy: boolean = true; + + if (!regexAtEnd(parser) && regexCurrent(parser) == '?' as u32) { + greedy = false; + parser.position += 1; + } + + return Option::SOME(regexAddNode(parser, RegexNode::REPEAT(RegexRepeat { child: child, min: min, max: max, bounded: bounded, greedy: greedy }))); +} + +/// Reads `name>` after `(?<`; `NONE` after recording an error. +function regexParseGroupName(parser: &mut RegexParser, openColumn: u64): Option { + let nameColumn: u64 = regexColumn(parser); + let mut name: String = String::new(); + + while (!regexAtEnd(parser) && regexCurrent(parser) != '>' as u32) { + let scalar: u32 = regexCurrent(parser); + + if (!regexIsNameStart(scalar) && !(name.length() > 0 && regexIsDigit(scalar))) { + regexFailStr(parser, regexColumn(parser), "invalid group name"); + return Option::NONE; + } + + name.pushByte(scalar as u8); + parser.position += 1; + } + + if (regexAtEnd(parser)) { + regexFailStr(parser, openColumn, "unclosed group"); + return Option::NONE; + } + + if (name.length() == 0) { + regexFailStr(parser, nameColumn, "invalid group name"); + return Option::NONE; + } + + let mut index: u64 = 0; + + while (index < parser.names.length()) { + if (parser.names.get(index).unwrap().equals(&name)) { + let mut message: String = String::create("duplicate group name "); + message.push(&name); + regexFail(parser, nameColumn, message); + return Option::NONE; + } + + index += 1; + } + + parser.names.push(name.clone()); + parser.position += 1; + return Option::SOME(name); +} + +/// Parses a group starting at the current `(`. `(?i)` returns +/// `REGEX_NO_NODE` after setting the flag for the rest of the enclosing +/// group. +function regexParseGroup(parser: &mut RegexParser): Option { + let openColumn: u64 = regexColumn(parser); + let savedCaseInsensitive: boolean = parser.caseInsensitive; + let mut capturing: boolean = true; + let mut name: String = String::new(); + parser.position += 1; + + if (!regexAtEnd(parser) && regexCurrent(parser) == '?' as u32) { + parser.position += 1; + + if (regexAtEnd(parser)) { + regexFailStr(parser, openColumn, "unclosed group"); + return Option::NONE; + } + + let flag: u32 = regexCurrent(parser); + let isLookbehind: boolean = flag == '<' as u32 && (regexPeekIs(parser, 1, '=' as u32) || regexPeekIs(parser, 1, '!' as u32)); + + if (flag == '=' as u32 || flag == '!' as u32 || isLookbehind) { + regexFailStr(parser, openColumn, "unsupported: lookaround"); + return Option::NONE; + } + + if (flag == ':' as u32) { + capturing = false; + parser.position += 1; + } else if (flag == '<' as u32) { + parser.position += 1; + + let Option::SOME(groupName) = regexParseGroupName(parser, openColumn) else { + return Option::NONE; + }; + + name = groupName; + } else if (flag == 'i' as u32) { + parser.position += 1; + + if (regexAtEnd(parser)) { + regexFailStr(parser, openColumn, "unclosed group"); + return Option::NONE; + } + + if (regexCurrent(parser) == ')' as u32) { + parser.position += 1; + parser.caseInsensitive = true; + return Option::SOME(REGEX_NO_NODE); + } + + if (regexCurrent(parser) != ':' as u32) { + regexFailStr(parser, regexColumn(parser), "unknown group flag"); + return Option::NONE; + } + + parser.position += 1; + parser.caseInsensitive = true; + capturing = false; + } else { + regexFailStr(parser, regexColumn(parser), "unknown group flag"); + return Option::NONE; + } + } + + let mut index: u64 = 0; + + if (capturing) { + parser.groupCount += 1; + index = parser.groupCount; + } + + let Option::SOME(child) = regexParseAlternation(parser) else { + return Option::NONE; + }; + + if (regexAtEnd(parser)) { + regexFailStr(parser, openColumn, "unclosed group"); + return Option::NONE; + } + + parser.position += 1; + parser.caseInsensitive = savedCaseInsensitive; + return Option::SOME(regexAddNode(parser, RegexNode::GROUP(RegexGroup { child: child, capturing: capturing, index: index, name: name }))); +} + +/// Parses one atom at the current position, which is not `|`, `)` or a +/// quantifier. +function regexParseAtom(parser: &mut RegexParser): Option { + let scalar: u32 = regexCurrent(parser); + + if (scalar == '(' as u32) { + return regexParseGroup(parser); + } + + if (scalar == '[' as u32) { + return regexParseClass(parser); + } + + if (scalar == '.' as u32) { + parser.position += 1; + return Option::SOME(regexAddNode(parser, RegexNode::ANY_EXCEPT_NEWLINE)); + } + + if (scalar == '^' as u32) { + parser.position += 1; + return Option::SOME(regexAddNode(parser, RegexNode::ASSERT(RegexAssertion::START))); + } + + if (scalar == '$' as u32) { + parser.position += 1; + return Option::SOME(regexAddNode(parser, RegexNode::ASSERT(RegexAssertion::END))); + } + + if (scalar != '\\' as u32) { + parser.position += 1; + return Option::SOME(regexLiteralNode(parser, scalar)); + } + + if (regexPeekIs(parser, 1, 'b' as u32)) { + parser.position += 2; + return Option::SOME(regexAddNode(parser, RegexNode::ASSERT(RegexAssertion::WORD_BOUNDARY))); + } + + if (regexPeekIs(parser, 1, 'B' as u32)) { + parser.position += 2; + return Option::SOME(regexAddNode(parser, RegexNode::ASSERT(RegexAssertion::NOT_WORD_BOUNDARY))); + } + + let Option::SOME(item) = regexParseEscapeItem(parser) else { + return Option::NONE; + }; + + if (!item.isSet) { + return Option::SOME(regexLiteralNode(parser, item.scalar)); + } + + let mut ranges: Vector = item.set; + return Option::SOME(regexClassNode(parser, &mut ranges, false)); +} + +function regexIsAssertion(parser: &mut RegexParser, id: u64): boolean { + return match (parser.nodes.get(id).unwrap()) { + RegexNode::ASSERT(_) -> true, + _ -> false, + }; +} + +/// Parses atoms and their quantifiers up to `|`, `)` or the end. +function regexParseConcat(parser: &mut RegexParser): Option { + let mut items: Vector = Vector::new(); + + while (!regexAtEnd(parser)) { + let scalar: u32 = regexCurrent(parser); + + if (scalar == '|' as u32 || scalar == ')' as u32) { + break; + } + + if (regexIsQuantifier(scalar)) { + regexFailStr(parser, regexColumn(parser), "nothing to repeat"); + return Option::NONE; + } + + let Option::SOME(parsedAtom) = regexParseAtom(parser) else { + return Option::NONE; + }; + + if (parsedAtom == REGEX_NO_NODE) { + continue; + } + + let mut node: u64 = parsedAtom; + + if (!regexAtEnd(parser) && regexIsQuantifier(regexCurrent(parser))) { + if (regexIsAssertion(parser, parsedAtom)) { + regexFailStr(parser, regexColumn(parser), "nothing to repeat"); + return Option::NONE; + } + + let Option::SOME(repeated) = regexParseQuantifier(parser, parsedAtom) else { + return Option::NONE; + }; + + node = repeated; + + if (!regexAtEnd(parser) && regexIsQuantifier(regexCurrent(parser))) { + regexFailStr(parser, regexColumn(parser), "nothing to repeat"); + return Option::NONE; + } + } + + items.push(node); + } + + if (items.length() == 0) { + return Option::SOME(regexAddNode(parser, RegexNode::EMPTY)); + } + + if (items.length() == 1) { + return Option::SOME(*items.get(0).unwrap()); + } + + return Option::SOME(regexAddNode(parser, RegexNode::CONCAT(items))); +} + +/// Parses `|`-separated branches up to `)` or the end. +function regexParseAlternation(parser: &mut RegexParser): Option { + let mut branches: Vector = Vector::new(); + + while (true) { + let Option::SOME(branch) = regexParseConcat(parser) else { + return Option::NONE; + }; + + branches.push(branch); + + if (regexAtEnd(parser) || regexCurrent(parser) != '|' as u32) { + break; + } + + parser.position += 1; + } + + if (branches.length() == 1) { + return Option::SOME(*branches.get(0).unwrap()); + } + + return Option::SOME(regexAddNode(parser, RegexNode::ALTERNATE(branches))); +} + +/// Parses `pattern` into a `RegexAst`, or the first error with its 1-based +/// column counted in Unicode scalars. +export function parseRegex(pattern: str): Result { + let source: String = String::create(pattern); + let mut scalars: Vector = Vector::new(); + let mut offset: u64 = 0; + + while (offset < source.length()) { + let mut end: u64 = offset; + + // `charAt` covers an invalid sequence with U+FFFD and still advances. + let scalar: char = source.charAt(offset, &mut end).unwrap(); + scalars.push(scalar as u32); + offset = end; + } + + let mut parser: RegexParser = RegexParser { + scalars: scalars, + position: 0, + nodes: Vector::new(), + groupCount: 0, + names: Vector::new(), + caseInsensitive: false, + failed: false, + errorColumn: 0, + errorMessage: String::new(), + }; + + let parsed: Option = regexParseAlternation(&mut parser); + + if (!parser.failed && !regexAtEnd(&mut parser)) { + regexFailStr(&mut parser, regexColumn(&mut parser), "unmatched )"); + } + + if (parser.failed) { + return Result::ERROR(RegexError::create(parser.errorColumn, parser.errorMessage)); + } + + return Result::OK(RegexAst { nodes: parser.nodes, root: parsed.unwrap(), groupCount: parser.groupCount }); +} diff --git a/std/regex/tests.ign b/std/regex/tests.ign new file mode 100644 index 000000000..24f0b851d --- /dev/null +++ b/std/regex/tests.ign @@ -0,0 +1,219 @@ +import Test from "std::test"; +import parseRegex from "std::regex"; +import regexAstDebug from "./ast"; + +function regexTestShape(pattern: str, expected: str): void { + match (parseRegex(pattern)) { + Result::OK(ast) -> { + let shape: String = regexAstDebug(&ast); + Test::assertEq(shape.toStr(), expected); + }, + Result::ERROR(error) -> { + let text: String = error.toString(); + Test::assertEq(text.toStr(), "no error"); + }, + }; +} + +function regexTestError(pattern: str, message: str, column: u64): void { + match (parseRegex(pattern)) { + Result::OK(_) -> { + Test::assertEq("parsed", message); + }, + Result::ERROR(error) -> { + Test::assertEq(error.message(), message); + Test::assertEq(error.column(), column); + }, + }; +} + +function regexTestGroupCount(pattern: str): u64 { + let Result::OK(ast) = parseRegex(pattern) else { + return 0xFFFF; + }; + + return ast.groupCount; +} + +@test +function parsesLiteralsAndConcatenation(): void { + regexTestShape("", "empty"); + regexTestShape("a", "lit(a)"); + regexTestShape("abc", "cat(lit(a),lit(b),lit(c))"); + regexTestShape("é+", "rep{1,inf}(lit(U+00E9))"); + regexTestShape("a]}", "cat(lit(a),lit(]),lit(}))"); +} + +@test +function parsesEscapes(): void { + regexTestShape("\\.\\*\\\\\\n", "cat(lit(.),lit(*),lit(\\),lit(U+000A))"); + regexTestShape("\\t\\r\\f\\v", "cat(lit(U+0009),lit(U+000D),lit(U+000C),lit(U+000B))"); + regexTestShape("\\{\\}\\[\\]\\(\\)\\|\\^\\$\\?\\+", "cat(lit({),lit(}),lit([),lit(]),lit(U+0028),lit(U+0029),lit(|),lit(^),lit($),lit(?),lit(+))"); +} + +@test +function parsesShorthandClasses(): void { + regexTestShape("\\d", "class(0-9)"); + regexTestShape("\\w", "class(0-9,A-Z,_,a-z)"); + regexTestShape("\\s", "class(U+0009-U+000D,U+0020)"); + regexTestShape("\\D", "class(U+0000-/,:-U+10FFFF)"); + regexTestShape("\\S", "class(U+0000-U+0008,U+000E-U+001F,!-U+10FFFF)"); + regexTestShape("\\W", "class(U+0000-/,:-@,[-^,`,{-U+10FFFF)"); +} + +@test +function parsesClasses(): void { + regexTestShape("[a-cx]", "class(a-c,x)"); + regexTestShape("[^a-z0-9_]", "nclass(0-9,_,a-z)"); + regexTestShape("[c-ea-d]", "class(a-e)"); + regexTestShape("[a-]", "class(U+002D,a)"); + regexTestShape("[-a]", "class(U+002D,a)"); + regexTestShape("[\\d.]", "class(.,0-9)"); + regexTestShape("[\\]\\-]", "class(U+002D,])"); + regexTestShape("[\\n-\\r]", "class(U+000A-U+000D)"); + regexTestShape("[.*(]", "class(U+0028,*,.)"); +} + +@test +function parsesAnyAndAssertions(): void { + regexTestShape("^a.$", "cat(start,lit(a),any,end)"); + regexTestShape("\\bx\\B", "cat(wordb,lit(x),nwordb)"); +} + +@test +function parsesAlternation(): void { + regexTestShape("a|bc", "alt(lit(a),cat(lit(b),lit(c)))"); + regexTestShape("a|b|", "alt(lit(a),lit(b),empty)"); + regexTestShape("|a", "alt(empty,lit(a))"); +} + +@test +function parsesGreedyQuantifiers(): void { + regexTestShape("ab*", "cat(lit(a),rep{0,inf}(lit(b)))"); + regexTestShape("a+", "rep{1,inf}(lit(a))"); + regexTestShape("a?", "rep{0,1}(lit(a))"); + regexTestShape("a{3}", "rep{3,3}(lit(a))"); + regexTestShape("a{2,}", "rep{2,inf}(lit(a))"); + regexTestShape("a{2,5}", "rep{2,5}(lit(a))"); + regexTestShape("a{0,1000}", "rep{0,1000}(lit(a))"); + regexTestShape("(ab)*", "rep{0,inf}(group(1,cat(lit(a),lit(b))))"); + regexTestShape("[ab]+", "rep{1,inf}(class(a-b))"); +} + +@test +function parsesLazyQuantifiers(): void { + regexTestShape("a*?", "rep{0,inf}?(lit(a))"); + regexTestShape("a+?b??", "cat(rep{1,inf}?(lit(a)),rep{0,1}?(lit(b)))"); + regexTestShape("a{2,5}?", "rep{2,5}?(lit(a))"); + regexTestShape("a{2,}?", "rep{2,inf}?(lit(a))"); +} + +@test +function parsesGroups(): void { + regexTestShape("(a)(?:b)(?c)", "cat(group(1,lit(a)),ncgroup(lit(b)),group(2:word,lit(c)))"); + regexTestShape("((a)b)", "group(1,cat(group(2,lit(a)),lit(b)))"); + regexTestShape("()", "group(1,empty)"); + regexTestShape("(?<_x9>a)", "group(1:_x9,lit(a))"); + Test::assertEq(regexTestGroupCount("(a)(?:b)(?c)((d))"), 4); + Test::assertEq(regexTestGroupCount("abc"), 0); +} + +@test +function caseInsensitiveFlagFoldsAsciiLetters(): void { + regexTestShape("(?i)ab", "cat(class(A,a),class(B,b))"); + regexTestShape("(?i)1", "lit(1)"); + regexTestShape("a(?i)b|c", "alt(cat(lit(a),class(B,b)),class(C,c))"); + regexTestShape("(?i:a)b", "cat(ncgroup(class(A,a)),lit(b))"); + regexTestShape("((?i)a)b", "cat(group(1,class(A,a)),lit(b))"); + regexTestShape("(?i)[a-cX]", "class(A-C,X,a-c,x)"); + regexTestShape("(?i)[^k]", "nclass(K,k)"); + regexTestShape("(?i)[Y-b]", "class(A-B,Y-b,y-z)"); +} + +@test +function errorFormatsMessageAndColumn(): void { + let Result::ERROR(error) = parseRegex("abcdef(") else { + Test::fail(); + return; + }; + + let text: String = error.toString(); + Test::assertEq(text.toStr(), "unclosed group at column 7"); +} + +@test +function rejectsUnbalancedGroups(): void { + regexTestError("(ab", "unclosed group", 1); + regexTestError("abcdef(", "unclosed group", 7); + regexTestError("a(b(c)", "unclosed group", 2); + regexTestError("é(", "unclosed group", 2); + regexTestError("a)", "unmatched )", 2); + regexTestError("(a))", "unmatched )", 4); +} + +@test +function rejectsNothingToRepeat(): void { + regexTestError("*a", "nothing to repeat", 1); + regexTestError("a|*", "nothing to repeat", 3); + regexTestError("(+)", "nothing to repeat", 2); + regexTestError("a**", "nothing to repeat", 3); + regexTestError("a*??", "nothing to repeat", 4); + regexTestError("a{2}{3}", "nothing to repeat", 5); + regexTestError("^*", "nothing to repeat", 2); + regexTestError("\\b+", "nothing to repeat", 3); + regexTestError("(?i)*", "nothing to repeat", 5); + regexTestError("{2}", "nothing to repeat", 1); +} + +@test +function rejectsBadClasses(): void { + regexTestError("[z-a]", "invalid range z-a", 3); + regexTestError("[\\d-z]", "invalid range", 4); + regexTestError("[a", "unclosed class", 1); + regexTestError("x[a-", "unclosed class", 2); + regexTestError("[]", "empty class", 1); + regexTestError("[^]", "empty class", 1); + regexTestError("[\\b]", "unknown escape \\b", 2); +} + +@test +function rejectsBadEscapes(): void { + regexTestError("a\\", "trailing backslash", 2); + regexTestError("\\q", "unknown escape \\q", 1); + regexTestError("\\0", "unknown escape \\0", 1); + regexTestError("(a)b\\1", "unsupported: backreference", 5); + regexTestError("[\\2]", "unsupported: backreference", 2); +} + +@test +function rejectsBadRepetitions(): void { + regexTestError("a{", "invalid repetition", 2); + regexTestError("a{}", "invalid repetition", 2); + regexTestError("a{,3}", "invalid repetition", 2); + regexTestError("a{2", "invalid repetition", 2); + regexTestError("a{2,x}", "invalid repetition", 2); + regexTestError("a{3,2}", "invalid repetition range", 2); + regexTestError("a{1001}", "repetition count above 1000", 2); + regexTestError("a{1,1001}", "repetition count above 1000", 2); + regexTestError("a{99999999999}", "repetition count above 1000", 2); +} + +@test +function rejectsLookaround(): void { + regexTestError("(?=a)", "unsupported: lookaround", 1); + regexTestError("x(?!a)", "unsupported: lookaround", 2); + regexTestError("(?<=a)", "unsupported: lookaround", 1); + regexTestError("(?x)", "invalid group name", 4); + regexTestError("(?x)", "invalid group name", 5); + regexTestError("(?<>x)", "invalid group name", 4); + regexTestError("(?x)(?y)", "duplicate group name a", 11); +} diff --git a/test_cases/__parse_verdicts__/std_regex_ast.txt b/test_cases/__parse_verdicts__/std_regex_ast.txt new file mode 100644 index 000000000..3d8e43b24 --- /dev/null +++ b/test_cases/__parse_verdicts__/std_regex_ast.txt @@ -0,0 +1,2 @@ +parse-verdict v1 +accepted diff --git a/test_cases/__parse_verdicts__/std_regex_mod.txt b/test_cases/__parse_verdicts__/std_regex_mod.txt new file mode 100644 index 000000000..3d8e43b24 --- /dev/null +++ b/test_cases/__parse_verdicts__/std_regex_mod.txt @@ -0,0 +1,2 @@ +parse-verdict v1 +accepted diff --git a/test_cases/__parse_verdicts__/std_regex_parser.txt b/test_cases/__parse_verdicts__/std_regex_parser.txt new file mode 100644 index 000000000..3d8e43b24 --- /dev/null +++ b/test_cases/__parse_verdicts__/std_regex_parser.txt @@ -0,0 +1,2 @@ +parse-verdict v1 +accepted diff --git a/test_cases/__parse_verdicts__/std_regex_tests.txt b/test_cases/__parse_verdicts__/std_regex_tests.txt new file mode 100644 index 000000000..3d8e43b24 --- /dev/null +++ b/test_cases/__parse_verdicts__/std_regex_tests.txt @@ -0,0 +1,2 @@ +parse-verdict v1 +accepted diff --git a/test_cases/doc/__doc_baselines__/output__std_io_mod.json b/test_cases/doc/__doc_baselines__/output__std_io_mod.json index 8303db6c1..1fe99de6b 100644 --- a/test_cases/doc/__doc_baselines__/output__std_io_mod.json +++ b/test_cases/doc/__doc_baselines__/output__std_io_mod.json @@ -284,6 +284,18 @@ "name": "std::rc", "doc": " \n# Rc Module \n \nReference-counted shared ownership for heap-allocated values. \n \n`Rc` provides shared ownership of a value of type `T` allocated on the \nheap. Cloning an `Rc` increments the reference count; dropping one \ndecrements it. When the last strong reference is released, the payload's \ndestructor runs. The allocation is freed when both strong and weak counts \nreach zero. \n \n`Weak` is a non-owning observer. It keeps the allocation header alive \nso `upgrade()` can check whether the value still exists, but does not \nprevent the payload from being destroyed. \n \nBoth types are **move-by-default**. Use `.clone()` to share. \n \n## Where the payload destructor comes from \n \nThe control block stores counts and nothing else. `Rc` and `Weak` are \ngeneric, so every operation already knows `T`, and the payload is destroyed \nwith `@dropInPlace` at the point the strong count reaches zero. Storing a \ndestructor pointer in the block would need a raw C function pointer, which \nIgnis has no way to call. \n \n## Example \n \n```ignis \nimport Rc, Weak from \"std::rc\"; \n \nfunction main(): i32 { \n let a: Rc = Rc::new(42); \n let b: Rc = a.clone(); \n let w: Weak = a.downgrade(); \n let upgraded: Option> = w.upgrade(); // SOME while a or b is alive \n return 0; \n} \n```" }, + { + "name": "std::regex", + "doc": " \n# Regex \n \nRegular expressions with linear-time matching, in the style of RE2: a \npattern is parsed into an AST, compiled to a program and run by a Pike VM \nthat simulates the NFA, so matching takes O(text x program) time and never \nbacktracks. \n \nThis slice holds the parser only. Compiling and matching (`Regex::new`, \n`isMatch`, `find`, `findAll`, captures, `replaceAll`, `split`) arrive in \nthe next slices. \n \n## Exports \n \n| Export | Description | \n|------------------------|----------------------------------------------------------------| \n| `parseRegex` | `parseRegex(pattern)`: `Result` | \n| `RegexError` | `column()` (1-based, in Unicode scalars), `message()`, `toString()` | \n| `RegexAst` | `nodes`, `root`, `groupCount` | \n| `RegexNode` | `EMPTY`, `LITERAL`, `ANY_EXCEPT_NEWLINE`, `CLASS`, `CONCAT`, `ALTERNATE`, `REPEAT`, `GROUP`, `ASSERT` | \n| `RegexClass` | Sorted, merged `ranges` and `negated` | \n| `RegexRange` | Inclusive `start` and `end` scalar values | \n| `RegexRepeat` | `child`, `min`, `max`, `bounded`, `greedy` | \n| `RegexGroup` | `child`, `capturing`, `index`, `name` | \n| `RegexAssertion` | `START`, `END`, `WORD_BOUNDARY`, `NOT_WORD_BOUNDARY` | \n| `REGEX_MAX_REPETITION` | The largest count `{n,m}` accepts: 1000 | \n \n## Syntax \n \n| Syntax | Meaning | \n|-----------------------------------|----------------------------------------------------------| \n| `x` | The scalar `x`, any UTF-8 scalar | \n| `.` | Any scalar except `\\n` | \n| `\\n` `\\t` `\\r` `\\f` `\\v` | Control scalars | \n| `\\.` `\\*` `\\\\` ... | Any escaped ASCII punctuation is itself | \n| `[abc]` `[a-z]` `[^...]` | Classes, ranges, negation; escapes work inside | \n| `\\d` `\\w` `\\s` and `\\D` `\\W` `\\S` | `[0-9]`, `[0-9A-Za-z_]`, `[ \\t\\n\\r\\f\\v]` and negations (ASCII) | \n| `^` `$` | Start and end of the whole text, not of a line | \n| `\\b` `\\B` | ASCII word boundary and its negation | \n| `(x)` `(?:x)` `(?x)` | Capturing, non-capturing and named groups | \n| `x\\|y` | Alternation, leftmost-first | \n| `x*` `x+` `x?` | Zero or more, one or more, zero or one | \n| `x{n}` `x{n,}` `x{n,m}` | Counted repetition, counts at most 1000 | \n| `x*?` `x+?` `x??` `x{n,m}?` | Lazy forms: prefer fewer repetitions | \n| `(?i)` `(?i:x)` | ASCII case-insensitive for the rest of the enclosing group, or inside `x` | \n \nGroup names are `[A-Za-z_][A-Za-z0-9_]*` and must be unique. Capturing \ngroups are numbered from 1 in the order of their `(`. \n \nThe parser is strict where a pattern would otherwise be ambiguous: \n \n- `{` always starts a counted repetition; a literal brace is `\\{`. A \n `{` that is not `{n}`, `{n,}` or `{n,m}` is `invalid repetition`. A \n lone `}` or `]` is a literal. \n- A quantifier after a quantifier (`a**`, `a+*`, `a{2}{3}`) and a \n quantifier after `^`, `$`, `\\b` or `\\B` are `nothing to repeat`; the \n `?` of a lazy form is part of its quantifier. \n- `[]` and `[^]` are `empty class`; a `]` inside a class is `\\]`. A `-` \n first or last in a class is a literal. \n \n## Errors \n \nEvery error carries the 1-based column, counted in Unicode scalars, of \nthe part that is wrong: `unclosed group` (at its `(`), `unmatched )`, \n`nothing to repeat`, `invalid range z-a` (at its `-`), `unclosed class` \n(at its `[`), `empty class`, `trailing backslash`, `unknown escape \\q`, \n`invalid repetition`, `invalid repetition range`, `repetition count above \n1000`, `invalid group name`, `duplicate group name x`, `unknown group \nflag`, `unsupported: backreference` and `unsupported: lookaround`. \n \nBackreferences (`\\1`) and lookaround (`(?=`, `(?!`, `(?<=`, `(? `RegexAst`, or the first `RegexError`." + }, { "name": "std::result", "doc": " \n# Result Module \n \nSuccess/error sum type for fallible operations. \n \n## Overview \n \n`Result` models operations that can either produce a value (`T`) \nor an error (`E`). It is an enum with two variants: \n \n- `Result::OK(value)` — the operation succeeded \n- `Result::ERROR(err)` — the operation failed \n \nUse `Result` when a function can fail in a recoverable way, forcing \nthe caller to explicitly handle the error path. \n \n## Variants \n \n```text \n Result \n ┌──────────────────────────────────────────┐ \n │ │ \n │ OK(T) ── success value of type T │ \n │ │ \n │ ERROR(E) ── error value of type E │ \n │ │ \n └──────────────────────────────────────────┘ \n``` \n \n## Ownership \n \nEvery method that can hand a payload out takes `self` by value and \nconsumes the result: `unwrap`, `unwrapErr`, `unwrapOr`, `unwrapOrElse`, \n`inspect`, `inspectErr`, `map`, `mapErr`, `andThen`, and `orElse`. The \nreceiver cannot be used again afterwards, so an owning payload is moved \nexactly once. \n \nOnly `isOk` and `isError` observe through `&self` and leave the result \nusable. \n \nA borrowed `Result` therefore cannot be fed to a consuming \ncombinator directly. Match on the borrow instead, or clone the result when \nthe value is genuinely needed twice. \n \n## Higher-Order Methods \n \nResult provides callback-based methods for transforming, inspecting, \nand chaining fallible operations: \n \n| Method | Signature | Description | \n|------------------|----------------------------------------|--------------------------------------| \n| `unwrapOrElse` | `(E) -> T` → `T` | Recover from error with callback | \n| `inspect` | `(&T) -> void` → `Result` | Side-effect on OK value | \n| `inspectErr` | `(&E) -> void` → `Result` | Side-effect on ERROR value | \n| `map` | `(T) -> U` → `Result` | Transform OK value | \n| `mapErr` | `(E) -> F` → `Result` | Transform ERROR value | \n| `andThen` | `(T) -> Result` → `Result` | Chain fallible OK operations | \n| `orElse` | `(E) -> Result` → `Result` | Chain fallible ERROR recovery | \n \n`inspect` and `inspectErr` observe the payload through a reference because \nthey hand the original result back. The other callbacks receive the payload \nby value because it is given away. \n \nAll callbacks are `@noescape`: the closure must not outlive the method call. \n \n## Example \n \n```ignis \nimport Io from \"std::io\"; \n \nfunction parseInt(s: str): Result { \n // ... parsing logic ... \n return Result::OK(42); \n} \n \nfunction main(): i32 { \n let result: Result = parseInt(\"42\"); \n \n // Chain: parse, double, inspect \n let doubled: Result = result \n .inspect((val: &i32): void -> { Io::printI32(*val); }) \n .map((val: i32): i32 -> { return val * 2; }); \n \n // Recover from error \n let value: i32 = doubled.unwrapOrElse((err: str): i32 -> { return 0; }); \n \n return 0; \n} \n```" @@ -16129,6 +16141,693 @@ } ] }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexAssertion", + "name": "RegexAssertion", + "kind": "enum", + "visibility": "public", + "signature": "enum RegexAssertion", + "doc": "A zero-width condition on the position between two scalars.", + "members": [ + { + "name": "START", + "kind": "variant", + "signature": "START" + }, + { + "name": "END", + "kind": "variant", + "signature": "END" + }, + { + "name": "WORD_BOUNDARY", + "kind": "variant", + "signature": "WORD_BOUNDARY" + }, + { + "name": "NOT_WORD_BOUNDARY", + "kind": "variant", + "signature": "NOT_WORD_BOUNDARY" + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexAst", + "name": "RegexAst", + "kind": "record", + "visibility": "public", + "signature": "record RegexAst", + "doc": "A parsed pattern.", + "members": [ + { + "name": "nodes", + "kind": "field", + "signature": "nodes: Vector" + }, + { + "name": "root", + "kind": "field", + "signature": "root: u64" + }, + { + "name": "groupCount", + "kind": "field", + "signature": "groupCount: u64", + "doc": "The number of capturing groups, the whole match not included." + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexClass", + "name": "RegexClass", + "kind": "record", + "visibility": "public", + "signature": "record RegexClass", + "doc": "A set of scalars: sorted, non-overlapping, non-adjacent ranges. A negated \nclass matches every scalar outside them.", + "members": [ + { + "name": "ranges", + "kind": "field", + "signature": "ranges: Vector" + }, + { + "name": "negated", + "kind": "field", + "signature": "negated: boolean" + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexError", + "name": "RegexError", + "kind": "record", + "visibility": "public", + "signature": "record RegexError", + "doc": "A pattern that could not be parsed: what is wrong and where.", + "members": [ + { + "name": "errorColumn", + "kind": "field", + "signature": "errorColumn: u64" + }, + { + "name": "errorMessage", + "kind": "field", + "signature": "errorMessage: String" + }, + { + "name": "create", + "kind": "method", + "signature": "static create(column: u64, message: String): RegexError", + "doc": "An error at the 1-based `column` with `message`." + }, + { + "name": "column", + "kind": "method", + "signature": "column(&self): u64", + "doc": "The 1-based column of the offending part, counted in Unicode scalars." + }, + { + "name": "message", + "kind": "method", + "signature": "message(&self): str", + "doc": "What is wrong, without the column." + }, + { + "name": "toString", + "kind": "method", + "signature": "toString(&self): String", + "doc": "` at column `." + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexGroup", + "name": "RegexGroup", + "kind": "record", + "visibility": "public", + "signature": "record RegexGroup", + "doc": "A parenthesized subpattern.", + "members": [ + { + "name": "child", + "kind": "field", + "signature": "child: u64" + }, + { + "name": "capturing", + "kind": "field", + "signature": "capturing: boolean" + }, + { + "name": "index", + "kind": "field", + "signature": "index: u64", + "doc": "1-based capture index in order of the opening parenthesis; 0 when not \ncapturing." + }, + { + "name": "name", + "kind": "field", + "signature": "name: String", + "doc": "The `(?...)` name, empty when there is none." + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexNode", + "name": "RegexNode", + "kind": "enum", + "visibility": "public", + "signature": "enum RegexNode", + "doc": "One node of a parsed pattern. Children are indices into `RegexAst.nodes`. \n \nCase-insensitive matching is resolved here: under `(?i)` an ASCII letter \nbecomes a class holding both cases, and classes gain the other case of \ntheir ASCII letters.", + "members": [ + { + "name": "EMPTY", + "kind": "variant", + "signature": "EMPTY" + }, + { + "name": "LITERAL", + "kind": "variant", + "signature": "LITERAL(u32)" + }, + { + "name": "ANY_EXCEPT_NEWLINE", + "kind": "variant", + "signature": "ANY_EXCEPT_NEWLINE" + }, + { + "name": "CLASS", + "kind": "variant", + "signature": "CLASS(RegexClass)" + }, + { + "name": "CONCAT", + "kind": "variant", + "signature": "CONCAT(Vector)" + }, + { + "name": "ALTERNATE", + "kind": "variant", + "signature": "ALTERNATE(Vector)" + }, + { + "name": "REPEAT", + "kind": "variant", + "signature": "REPEAT(RegexRepeat)" + }, + { + "name": "GROUP", + "kind": "variant", + "signature": "GROUP(RegexGroup)" + }, + { + "name": "ASSERT", + "kind": "variant", + "signature": "ASSERT(RegexAssertion)" + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexRange", + "name": "RegexRange", + "kind": "record", + "visibility": "public", + "signature": "record RegexRange", + "doc": "An inclusive range of Unicode scalar values.", + "members": [ + { + "name": "start", + "kind": "field", + "signature": "start: u32" + }, + { + "name": "end", + "kind": "field", + "signature": "end: u32" + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::RegexRepeat", + "name": "RegexRepeat", + "kind": "record", + "visibility": "public", + "signature": "record RegexRepeat", + "doc": "A repetition of `child` between `min` and `max` times.", + "members": [ + { + "name": "child", + "kind": "field", + "signature": "child: u64" + }, + { + "name": "min", + "kind": "field", + "signature": "min: u32" + }, + { + "name": "max", + "kind": "field", + "signature": "max: u32", + "doc": "Ignored when `bounded` is false." + }, + { + "name": "bounded", + "kind": "field", + "signature": "bounded: boolean" + }, + { + "name": "greedy", + "kind": "field", + "signature": "greedy: boolean", + "doc": "Greedy prefers more repetitions, lazy fewer." + } + ] + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::regexAstDebug", + "name": "regexAstDebug", + "kind": "function", + "visibility": "public", + "signature": "function regexAstDebug(ast: &RegexAst): String", + "doc": "A compact text form of `ast` for tests: `cat(lit(a),rep{0,inf}(lit(b)))`. \nScalars that are not printable ASCII, or that the form itself uses, print \nas `U+XXXX`." + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::regexDebugChildren", + "name": "regexDebugChildren", + "kind": "function", + "visibility": "private", + "signature": "function regexDebugChildren(ast: &RegexAst, children: &Vector, text: &mut String): void" + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::regexDebugNode", + "name": "regexDebugNode", + "kind": "function", + "visibility": "private", + "signature": "function regexDebugNode(ast: &RegexAst, id: u64, text: &mut String): void" + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::regexDebugScalar", + "name": "regexDebugScalar", + "kind": "function", + "visibility": "private", + "signature": "function regexDebugScalar(text: &mut String, scalar: u32): void" + }, + { + "module": "std::regex::ast", + "path": "std::regex::ast::regexHexDigit", + "name": "regexHexDigit", + "kind": "function", + "visibility": "private", + "signature": "function regexHexDigit(value: u32): u8" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::REGEX_MAX_REPETITION", + "name": "REGEX_MAX_REPETITION", + "kind": "constant", + "visibility": "public", + "signature": "const REGEX_MAX_REPETITION: u32" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::REGEX_MAX_SCALAR", + "name": "REGEX_MAX_SCALAR", + "kind": "constant", + "visibility": "private", + "signature": "const REGEX_MAX_SCALAR: u32" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::REGEX_NO_NODE", + "name": "REGEX_NO_NODE", + "kind": "constant", + "visibility": "private", + "signature": "const REGEX_NO_NODE: u64" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::RegexClassItem", + "name": "RegexClassItem", + "kind": "record", + "visibility": "private", + "signature": "record RegexClassItem", + "doc": "A class item read inside `[...]` or after `\\` outside it: one scalar or \na shorthand set such as `\\d`.", + "members": [ + { + "name": "scalar", + "kind": "field", + "signature": "scalar: u32" + }, + { + "name": "isSet", + "kind": "field", + "signature": "isSet: boolean" + }, + { + "name": "set", + "kind": "field", + "signature": "set: Vector" + } + ] + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::RegexParser", + "name": "RegexParser", + "kind": "record", + "visibility": "private", + "signature": "record RegexParser", + "members": [ + { + "name": "scalars", + "kind": "field", + "signature": "scalars: Vector" + }, + { + "name": "position", + "kind": "field", + "signature": "position: u64" + }, + { + "name": "nodes", + "kind": "field", + "signature": "nodes: Vector" + }, + { + "name": "groupCount", + "kind": "field", + "signature": "groupCount: u64" + }, + { + "name": "names", + "kind": "field", + "signature": "names: Vector" + }, + { + "name": "caseInsensitive", + "kind": "field", + "signature": "caseInsensitive: boolean" + }, + { + "name": "failed", + "kind": "field", + "signature": "failed: boolean" + }, + { + "name": "errorColumn", + "kind": "field", + "signature": "errorColumn: u64" + }, + { + "name": "errorMessage", + "kind": "field", + "signature": "errorMessage: String" + } + ] + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::__closure_thunk_0", + "name": "__closure_thunk_0", + "kind": "function", + "visibility": "private", + "signature": "function __closure_thunk_0(__closure_env_0: *mut u8, left: &RegexRange, right: &RegexRange): i32" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::parseRegex", + "name": "parseRegex", + "kind": "function", + "visibility": "public", + "signature": "function parseRegex(pattern: str): Result", + "doc": "Parses `pattern` into a `RegexAst`, or the first error with its 1-based \ncolumn counted in Unicode scalars." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexAddCaseCounterparts", + "name": "regexAddCaseCounterparts", + "kind": "function", + "visibility": "private", + "signature": "function regexAddCaseCounterparts(ranges: &mut Vector): void", + "doc": "Adds the other ASCII case of every ASCII letter in `ranges`." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexAddNode", + "name": "regexAddNode", + "kind": "function", + "visibility": "private", + "signature": "function regexAddNode(parser: &mut RegexParser, node: RegexNode): u64" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexAtEnd", + "name": "regexAtEnd", + "kind": "function", + "visibility": "private", + "signature": "function regexAtEnd(parser: &mut RegexParser): boolean" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexClassNode", + "name": "regexClassNode", + "kind": "function", + "visibility": "private", + "signature": "function regexClassNode(parser: &mut RegexParser, ranges: &mut Vector, negated: boolean): u64", + "doc": "A class node for `ranges`, case-folded under `(?i)`." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexColumn", + "name": "regexColumn", + "kind": "function", + "visibility": "private", + "signature": "function regexColumn(parser: &mut RegexParser): u64", + "doc": "The 1-based column of the current scalar." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexComplement", + "name": "regexComplement", + "kind": "function", + "visibility": "private", + "signature": "function regexComplement(ranges: &Vector): Vector", + "doc": "The scalars outside `ranges`, which must be normalized." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexCurrent", + "name": "regexCurrent", + "kind": "function", + "visibility": "private", + "signature": "function regexCurrent(parser: &mut RegexParser): u32" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexEscapedScalar", + "name": "regexEscapedScalar", + "kind": "function", + "visibility": "private", + "signature": "function regexEscapedScalar(letter: u32): Option", + "doc": "The scalar an escape `\\letter` stands for, for the escapes that stand \nfor one scalar: control escapes and escaped ASCII punctuation." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexFail", + "name": "regexFail", + "kind": "function", + "visibility": "private", + "signature": "function regexFail(parser: &mut RegexParser, column: u64, message: String): void", + "doc": "Records the first error; later ones are ignored." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexFailStr", + "name": "regexFailStr", + "kind": "function", + "visibility": "private", + "signature": "function regexFailStr(parser: &mut RegexParser, column: u64, message: str): void" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexIsAssertion", + "name": "regexIsAssertion", + "kind": "function", + "visibility": "private", + "signature": "function regexIsAssertion(parser: &mut RegexParser, id: u64): boolean" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexIsDigit", + "name": "regexIsDigit", + "kind": "function", + "visibility": "private", + "signature": "function regexIsDigit(scalar: u32): boolean" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexIsNameStart", + "name": "regexIsNameStart", + "kind": "function", + "visibility": "private", + "signature": "function regexIsNameStart(scalar: u32): boolean" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexIsQuantifier", + "name": "regexIsQuantifier", + "kind": "function", + "visibility": "private", + "signature": "function regexIsQuantifier(scalar: u32): boolean" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexLiteralNode", + "name": "regexLiteralNode", + "kind": "function", + "visibility": "private", + "signature": "function regexLiteralNode(parser: &mut RegexParser, scalar: u32): u64", + "doc": "A literal node, or under `(?i)` a class of both cases of an ASCII letter." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexNormalize", + "name": "regexNormalize", + "kind": "function", + "visibility": "private", + "signature": "function regexNormalize(ranges: &mut Vector): Vector", + "doc": "Sorts `ranges` and merges overlapping or adjacent ones." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseAlternation", + "name": "regexParseAlternation", + "kind": "function", + "visibility": "private", + "signature": "function regexParseAlternation(parser: &mut RegexParser): Option", + "doc": "Parses `|`-separated branches up to `)` or the end." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseAtom", + "name": "regexParseAtom", + "kind": "function", + "visibility": "private", + "signature": "function regexParseAtom(parser: &mut RegexParser): Option", + "doc": "Parses one atom at the current position, which is not `|`, `)` or a \nquantifier." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseClass", + "name": "regexParseClass", + "kind": "function", + "visibility": "private", + "signature": "function regexParseClass(parser: &mut RegexParser): Option", + "doc": "Parses `[...]` starting at the current `[`." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseClassItem", + "name": "regexParseClassItem", + "kind": "function", + "visibility": "private", + "signature": "function regexParseClassItem(parser: &mut RegexParser): Option", + "doc": "Reads one class item at the current position inside `[...]`." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseConcat", + "name": "regexParseConcat", + "kind": "function", + "visibility": "private", + "signature": "function regexParseConcat(parser: &mut RegexParser): Option", + "doc": "Parses atoms and their quantifiers up to `|`, `)` or the end." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseCount", + "name": "regexParseCount", + "kind": "function", + "visibility": "private", + "signature": "function regexParseCount(parser: &mut RegexParser, braceColumn: u64): Option", + "doc": "Reads a decimal count at the current position for `{...}`; `NONE` \nwithout consuming anything when no digit is there. A count above the \nlimit is recorded as an error against `braceColumn`." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseEscapeItem", + "name": "regexParseEscapeItem", + "kind": "function", + "visibility": "private", + "signature": "function regexParseEscapeItem(parser: &mut RegexParser): Option", + "doc": "Reads the escape at the current `\\`. `\\b` and `\\B` are not handled \nhere: outside a class the caller reads them first, and inside a class \nthey are unknown escapes. `NONE` after recording an error." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseGroup", + "name": "regexParseGroup", + "kind": "function", + "visibility": "private", + "signature": "function regexParseGroup(parser: &mut RegexParser): Option", + "doc": "Parses a group starting at the current `(`. `(?i)` returns \n`REGEX_NO_NODE` after setting the flag for the rest of the enclosing \ngroup." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseGroupName", + "name": "regexParseGroupName", + "kind": "function", + "visibility": "private", + "signature": "function regexParseGroupName(parser: &mut RegexParser, openColumn: u64): Option", + "doc": "Reads `name>` after `(?<`; `NONE` after recording an error." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexParseQuantifier", + "name": "regexParseQuantifier", + "kind": "function", + "visibility": "private", + "signature": "function regexParseQuantifier(parser: &mut RegexParser, child: u64): Option", + "doc": "Parses the quantifier at the current position and wraps `child` in it." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexPeekIs", + "name": "regexPeekIs", + "kind": "function", + "visibility": "private", + "signature": "function regexPeekIs(parser: &mut RegexParser, offset: u64, scalar: u32): boolean", + "doc": "Whether the scalar `offset` past the current one exists and is `scalar`." + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexPushRange", + "name": "regexPushRange", + "kind": "function", + "visibility": "private", + "signature": "function regexPushRange(ranges: &mut Vector, start: u32, end: u32): void" + }, + { + "module": "std::regex::parser", + "path": "std::regex::parser::regexShorthand", + "name": "regexShorthand", + "kind": "function", + "visibility": "private", + "signature": "function regexShorthand(letter: u32, ranges: &mut Vector): boolean", + "doc": "The ranges of `\\d`, `\\w`, `\\s` or their negations, or `false` when \n`letter` is none of them." + }, { "module": "std::result", "path": "std::result::Result",