dartora

PatternItem

PatternItem is used by the QueryEngine to define how specific characters in a raw query string should be interpreted. Each PatternItem binds a character code (charCode) to a set of flags that instruct the parser to start/stop a collector, split tokens, define required/forbidden words, define tags, or act as an escape sequence.

Constructor

const PatternItem({
  required String name,
  required int charCode,
  String? charReplacement,
  String? regExpChar,
  bool isCollector = false,
  bool ignoreNextPattern = false,
  bool ignoreNextChar = false,
  bool isSplitter = false,
  bool definesTag = false,
  bool definesRequired = false,
  bool definesNotAllowed = false,
})

The constructor contains asserts to ensure that a pattern does not claim conflicting roles (e.g. a collector cannot also be a splitter). It also derives two additional read‑only fields:

Call operator

String call({void Function(PatternItem)? action, required bool Function(PatternItem) check}) evaluates a custom predicate (check) against the pattern and optionally executes an action. If the predicate returns true, the method returns charReplacement if available, otherwise the literal character. This is used by the query builder to append characters while evaluating pattern roles.

Equality

Two PatternItems are considered equal if they share the same charCode and name. This allows patterns to be looked up in the engine by code unit.

Default patterns

The default QueryEngine defines patterns for " (collector), \ (escape), space (splitter), - (forbidden), # (tag) and * (wildcard). See the engine documentation for details on how these combine to parse a query.