hydra.parse.regex module
Parser for Hydra’s translingual regular-expression syntax (docs/specification/regex.md): text -> hydra.regex AST. Built on the hydra.parsers combinators. Rejects ill-formed patterns (empty alternation branches, empty classes, out-of-range code points) via the ParseResult failure channel, so ‘well-formed’ is portable across hosts. See issue #567. A structured textual-syntax parser (precedent for the general parser in #497), not a scalar parse<T> convention function (see docs/specification/index.md, Conventions).
- hydra.parse.regex.alternation() Parser[Sequence[Sequence[Quantified]]]
Parse an alternation of sequences separated by |. When there is more than one branch, each branch must be non-empty; empty branches (a|, |b, a||b, and the nested (a|)) are rejected at every level. A single empty branch is the legal empty case (empty whole pattern / empty group).
- hydra.parse.regex.atom() Parser[Atom]
Parse a single atom: a group ( … ), a class [ … ], ., an anchor ^ or $, or a literal.
- hydra.parse.regex.character_class() Parser[Atom]
Parse a character class [ … ] or [^ … ]; the class must be non-empty.
- hydra.parse.regex.class_item() Parser[ClassItem]
Parse one member of a character class: a range like a-z, or a single character (escapes allowed).
- hydra.parse.regex.escaped_char() Parser[int]
Parse a backslash followed by any character; yields that character’s codepoint (the escape is consumed).
- hydra.parse.regex.is_metachar(c: int) bool
True if the codepoint is a top-level regex metacharacter that must be escaped to match literally.
- hydra.parse.regex.literal_atom() Parser[Atom]
Parse a literal character (an escaped metacharacter, or any ordinary non-metacharacter) into an Atom.
- hydra.parse.regex.parse_regex(input: str) object
Parse a full regex pattern string into a hydra.regex AST. Returns nothing if the pattern is ill-formed or does not consume all input; a well-formed pattern is exactly one that parses here, so ‘well-formed’ is portable across all hosts.
- hydra.parse.regex.quantified() Parser[Quantified]
Parse an atom followed by an optional quantifier.
- hydra.parse.regex.quantifier() Parser[Quantifier]
Parse an optional quantifier following an atom; yields ‘one’ when no quantifier is present.
- hydra.parse.regex.regex() Parser[Sequence[Sequence[Quantified]]]
Parse a complete regex (an alternation). The empty pattern parses to a single empty sequence.
- hydra.parse.regex.regex_sequence() Parser[Sequence[Quantified]]
Parse a sequence of quantified atoms (a single alternation branch). May be empty only as the whole pattern; as an alternation branch it is constrained to be non-empty by the alternation parser’s use of sepBy1 plus a non-empty check.