ParseRule
Base class for text parsing rules that identify modifier application ranges.
Remarks
Derived Types(22)
Types that inherit from ParseRule.
The literal-escape capability: a rule that consumes an escape prefix to protect the following character from markup interpretation returns that prefix; '\0' (default) = the rule provides no escaping. Consumers (literal-paste serialization, escaping injection) check this contract instead of naming a concrete rule type, so a custom escaping rule participates by overriding it.
Whether this rule provides literal escaping — see EscapePrefix.
The source-markup token this rule's syntax is externally known by — whatever form the syntax takes (color for a tag rule, a marker for a marker rule) — or null for a markerless rule. Interop consumers (clipboard bindings) pair rules with format schemas by this token instead of testing syntax families.
Stable identity shared by rule instances that match the same syntax, compared case-insensitively — pairs separately configured instances (style merging, ByRule chrome selectors). The default (full type name) is correct for configuration-free rules. A rule whose instances can be configured to match different syntaxes MUST qualify it (TagRule → "tag:" + name, marker rule → "marker:" + marker) or return null (identity by reference only) — otherwise differently configured instances are falsely treated as the same rule. Called on hot paths — cache the string, don't rebuild it per access.
Characters of which at least one must start any match of this rule that alters the visible text — strips markup (tags, markers), replaces it, or inserts content. Empty = the rule never consumes text (style-only matches like raw-URL detection); null (default) = unknown, callers must assume any text can be consumed. Literal-paste escaping protects exactly these characters, so under-reporting silently mutates pasted text.
Characters whose insertion or removal can make this rule begin or complete a consuming markup match. The editable document parses typed syntax only when an edit contains one of these characters or touches its immediate boundary; empty means this rule has no source syntax, while null conservatively parses every direct typing edit. Include closing delimiters and required separators, not only match starts.
Characters of which at least one must be at the match position for TryMatch to succeed at all (consuming or style-only). Defaults to MarkupTriggers — override when the rule matches at characters beyond its consuming set (raw-URL scheme letters). The parser bakes the union into a jump table and skips runs of non-trigger text, so an accurate set here is a large parse speedup; null disables the fast scan for the whole component.
Whether EscapePrefix can protect c — the escapable set of this rule's grammar. Meaningful only when ProvidesLiteralEscape.
public static string MarkupTriggerUnion(IReadOnlyList<ParseRule> rules)Deduplicated union of the rules' MarkupTriggers, or null when any rule reports unknown — shared by the parser and CompositeParseRule to advertise the combined trigger set. Null rules are skipped.
public static string ScanTriggerUnion(IReadOnlyList<ParseRule> rules)Deduplicated union of the rules' ScanTriggers; null when any rule reports unknown.
public static string TypingTriggerUnion(IReadOnlyList<ParseRule> rules)Deduplicated union of the rules' TypingTriggers; null when every direct typing edit must be considered.
protected static string CachedIdentity(string prefix, string name, ref string cacheKey, ref string cacheValue)Identity builder for configurable rules: returns prefix + name cached against the name's string instance, so hot-path Identity reads allocate only when the configured name actually changes. Null/empty name → null identity.
public abstract int TryMatch(ReadOnlySpan<char> text, int index, PooledList<ParsedRange> results)Attempts to match a pattern starting at the specified index.
public virtual void Finalize(ReadOnlySpan<char> text, PooledList<ParsedRange> results)Called after parsing completes to finalize any pending ranges (e.g., unclosed tags).
public virtual void PostParse(ReadOnlySpan<char> cleanText, PooledList<ParsedRange> results)Called after tag stripping to add ranges in clean-text space.
public virtual bool IsCompleteMatch(in ParsedRange range)Whether a matched occurrence is complete: complete markup becomes persistent document markup and, in an editable text that hides completed markup, strips and styles; incomplete markup, such as a tag still being typed, stays literal there.
public virtual string Apply(ReadOnlySpan<char> content, string parameter)Emits this rule's source syntax wrapping content — the inverse of parsing, used by the editing layer to apply a style and to reconstruct copied markup. Returns null when the rule has no content-wrapping form (void, block, or composite rules), meaning it cannot be applied as an inline style.
