hydra-kernel-0.17.2: src/main/haskell/Hydra/Regex.hs
-- Note: this is an automatically generated file. Do not edit.
-- | A model for Hydra's translingual regular-expression syntax: the abstract syntax tree (AST) into which hydra.parse.regex parses a pattern and from which hydra.print.regex (and the per-dialect hydra.print.<dialect>.regex renderers) emit target syntax. Covers the minimal core defined in docs/specification/regex.md (literals, character classes, ., quantifiers, alternation, anchors, grouping). See issue #567.
module Hydra.Regex where
import qualified Hydra.Core as Core
import Prelude hiding (Enum, Ordering, decodeFloat, encodeFloat, fail, map, pure, sum)
import qualified Data.Scientific as Sci
-- | A non-empty list of alternative sequences, joined by the | operator. Matches if any alternative matches.
type Alternation = [RegexSequence]
_Alternation = Core.Name "hydra.regex.Alternation"
-- | A single, unquantified regex element: the smallest unit to which a quantifier may apply.
data Atom =
-- | A literal character, matched exactly. The character is a Unicode scalar value in the range [U+0000, U+10FFFF] (surrogates excluded), held as an int32 code point (the range fits in signed 32-bit, and int32 matches Hydra's string/parser code-point representation). In concrete syntax, a metacharacter is written escaped (e.g. \.); escaping is purely a concrete-syntax concern, so the AST holds the bare code point.
AtomLiteral Int |
-- | The . metacharacter; matches any single character, INCLUDING newline (unlike most host engines, whose native . excludes newline). To exclude newline, write [^\n] explicitly.
AtomAny |
-- | The ^ anchor; matches the empty string at the start of input.
AtomAnchorStart |
-- | The $ anchor; matches the empty string at the end of input.
AtomAnchorEnd |
-- | A parenthesized sub-expression, ( ... ); groups an alternation for quantification.
AtomGroup Alternation |
-- | A character class, [ ... ]; matches any single character in (or, if negated, not in) the set.
AtomClass CharacterClass
deriving (Eq, Ord, Read, Show)
_Atom = Core.Name "hydra.regex.Atom"
_Atom_literal = Core.Name "literal"
_Atom_any = Core.Name "any"
_Atom_anchorStart = Core.Name "anchorStart"
_Atom_anchorEnd = Core.Name "anchorEnd"
_Atom_group = Core.Name "group"
_Atom_class = Core.Name "class"
-- | A bracketed character class, [ ... ] or [^ ... ].
data CharacterClass =
CharacterClass {
-- | True for a negated class ([^ ... ]), which matches any character NOT listed.
characterClassNegated :: Bool,
-- | The class members: individual characters and/or character ranges. Must be non-empty; the empty class [] and negated-empty class [^] are excluded from the core (they are not in the POSIX/PCRE/ECMA intersection). hydra.parse.regex rejects an empty class.
characterClassItems :: [ClassItem]}
deriving (Eq, Ord, Read, Show)
_CharacterClass = Core.Name "hydra.regex.CharacterClass"
_CharacterClass_negated = Core.Name "negated"
_CharacterClass_items = Core.Name "items"
-- | An inclusive range of characters within a character class, e.g. a-z.
data CharacterRange =
CharacterRange {
-- | The first character of the range (inclusive), as an int32 Unicode scalar value.
characterRangeFrom :: Int,
-- | The last character of the range (inclusive), as an int32 Unicode scalar value.
characterRangeTo :: Int}
deriving (Eq, Ord, Read, Show)
_CharacterRange = Core.Name "hydra.regex.CharacterRange"
_CharacterRange_from = Core.Name "from"
_CharacterRange_to = Core.Name "to"
-- | A member of a character class: either a single character or an inclusive character range.
data ClassItem =
-- | A single character (int32 Unicode scalar value) in the class.
ClassItemCharacter Int |
-- | An inclusive range of characters, e.g. a-z.
ClassItemRange CharacterRange
deriving (Eq, Ord, Read, Show)
_ClassItem = Core.Name "hydra.regex.ClassItem"
_ClassItem_character = Core.Name "character"
_ClassItem_range = Core.Name "range"
-- | An atom together with an optional quantifier applied to it.
data Quantified =
Quantified {
-- | The atom being quantified.
quantifiedAtom :: Atom,
-- | The quantifier; use 'one' for an unquantified atom.
quantifiedQuantifier :: Quantifier}
deriving (Eq, Ord, Read, Show)
_Quantified = Core.Name "hydra.regex.Quantified"
_Quantified_atom = Core.Name "atom"
_Quantified_quantifier = Core.Name "quantifier"
-- | A regular-expression quantifier. Mirrors hydra.query.RegexQuantifier, which models the same set of quantifiers for graph-path queries; a future refactor may hoist a shared type (see #567 findings).
data Quantifier =
-- | No quantifier; matches exactly one occurrence.
QuantifierOne |
-- | The ? quantifier; matches zero or one occurrence.
QuantifierZeroOrOne |
-- | The * quantifier; matches zero or more occurrences.
QuantifierZeroOrMore |
-- | The + quantifier; matches one or more occurrences.
QuantifierOneOrMore |
-- | The {n} quantifier; matches exactly n occurrences.
QuantifierExactly Int |
-- | The {n,} quantifier; matches at least n occurrences.
QuantifierAtLeast Int |
-- | The {n,m} quantifier; matches between n and m (inclusive) occurrences.
QuantifierRange_ QuantifierRange
deriving (Eq, Ord, Read, Show)
_Quantifier = Core.Name "hydra.regex.Quantifier"
_Quantifier_one = Core.Name "one"
_Quantifier_zeroOrOne = Core.Name "zeroOrOne"
_Quantifier_zeroOrMore = Core.Name "zeroOrMore"
_Quantifier_oneOrMore = Core.Name "oneOrMore"
_Quantifier_exactly = Core.Name "exactly"
_Quantifier_atLeast = Core.Name "atLeast"
_Quantifier_range = Core.Name "range"
-- | The bounds of a {n,m} quantifier: between min and max (inclusive) occurrences.
data QuantifierRange =
QuantifierRange {
-- | The minimum number of occurrences (inclusive).
quantifierRangeMin :: Int,
-- | The maximum number of occurrences (inclusive).
quantifierRangeMax :: Int}
deriving (Eq, Ord, Read, Show)
_QuantifierRange = Core.Name "hydra.regex.QuantifierRange"
_QuantifierRange_min = Core.Name "min"
_QuantifierRange_max = Core.Name "max"
-- | A complete Hydra regular expression: the root of the AST. A regex is an alternation of sequences.
type Regex = Alternation
_Regex = Core.Name "hydra.regex.Regex"
-- | A (possibly empty) sequence of quantified atoms, matched in order. An empty sequence matches the empty string. (Named RegexSequence rather than Sequence to avoid the generated coder binding colliding with the host's built-in sequence.)
type RegexSequence = [Quantified]
_RegexSequence = Core.Name "hydra.regex.RegexSequence"