Expand description
The engine-facing inline driver: a second engine instance whose lexer
IS the inline scanner. Port of ts/src/engine-inline.ts and
go/engineinline.go.
Each custom matcher is a thin adapter over one InlineParser scanner
method, the same methods the engine-free path runs, so the anti-drift
rule holds: recognition, node building, the delimiter stack and the
bracket stack all live once, in inline.rs.
Two engine features carry the design:
-
Context-sensitive matchers. Every adapter reaches the per-parse state through
ctx.u["inl"]. That is what makes the]matcher the cursor owner:parse_close_bracketconsumes a successful link tail directly from the subject, and because that happens at lex time, the engine’s point advances past the tail and everything after it is lexed fresh. The corpus-blind straddle cases (a backtick inside a successful destination or title, followed by a code span; see test/spec/mixed.tsv) are correct by construction: no token is ever cut across a tail boundary, so no re-lex or resynchronization machinery exists at all. -
Matcher order as precedence. At
<, the autolink adapter runs before the raw-HTML adapter, exactly as the hand scanner’s dispatch tries them; the text-run adapter and the single-character literal fallback come last. The registered order is §6.3’s precedence table, visible in the instance’s configuration instead of buried in amatch.
The one-token effects are applied at lex time on purpose. The engine’s
rule loop reads lookahead tokens before earlier alts’ actions run, so
any state a matcher consults (the tree for break trimming, the bracket
stack for ]) must be current when the lexer reaches it, not when
the parser does. The inline rule therefore carries no per-token
actions: the tokens are the observable record of the scan (subscribe
with Tabnas::subscribe_tokens and watch), and the rule’s close action
finalizes the block exactly as the engine-free parse tail does.
§One instance per install
TypeScript builds one inline instance per plugin install; Go builds one
per parse because its engine’s concurrency guarantee covers
construction only. The Rust engine parses through &self and the
instance is Send + Sync, so this port follows TypeScript: one
instance, built when the plugin installs, shared by every parse. The
per-parse state it needs (the scanner, the tree, the block) travels
through a thread-local slab exactly as the block phase’s does, keyed by
a slot index in the parse meta.
Constants§
- INLINE_
PREPARE - The
parse.preparehook’s name. - INLINE_
STATE_ KEY - The key under
ctx.u(and undermeta.md) that carries the inline state’s slot index. - INLINE_
TOKENS - The inline token alphabet, in the order the rule’s alt lists them.
Functions§
- make_
inline_ tn - Build the inline engine instance for one option set. All built-in matchers are disabled; the registered matcher set is the complete lexical description of the inline phase, in precedence order.
- parse_
inlines_ engine - The engine-path inline phase: the same block walk as
parse_inlines, with each block’s scan driven by the engine instance’s lexer. An empty subject never reaches the engine (its empty-source path returns before the rules run), and finishes the block directly: a no-op resolve, exactly as the hand scanner’sparsedoes.