Skip to content

Type Editor


Type Editor / @type-editor/model / content-parser/ContentMatcher / ContentMatcher

Class: ContentMatcher

Defined in: packages/model/src/content-parser/ContentMatcher.ts:20

Compiles content expressions into a deterministic finite automaton (DFA).

The compilation process follows these steps:

  1. Build a Non-deterministic Finite Automaton (NFA) from the expression AST
  2. Convert the NFA to a DFA using subset construction
  3. Validate the DFA for dead-end states (non-generatable required content)

For background on NFA/DFA construction, see: https://swtch.com/~rsc/regexp/regexp1.html

Constructors

Constructor

ts
new ContentMatcher(expression): ContentMatcher;

Defined in: packages/model/src/content-parser/ContentMatcher.ts:35

Creates a new content matcher and compiles the expression into a DFA.

Parameters

ParameterTypeDescription
expressionContentPatternThe parsed expression AST to compile

Returns

ContentMatcher

Accessors

match

Get Signature

ts
get match(): ContentMatch;

Defined in: packages/model/src/content-parser/ContentMatcher.ts:46

Gets the compiled content match automaton.

Returns

ContentMatch

The compiled ContentMatch DFA

Methods

getCheckedMatch()

ts
getCheckedMatch(stream): ContentMatch;

Defined in: packages/model/src/content-parser/ContentMatcher.ts:57

Gets the compiled content match after validating it for dead ends.

Parameters

ParameterTypeDescription
streamTokenStreamThe token stream (used for error reporting)

Returns

ContentMatch

The compiled and validated ContentMatch DFA

Throws

If the expression contains unreachable or non-generatable content