import { TokenType } from './tokenizer'; import type { Token } from './tokenizer'; export declare class ParserBase { protected tokens: Token[]; protected source: string; protected p: number; constructor(tokens: Token[], source: string); consume(type: TokenType): Token; accept(type: TokenType): Token | null; check(type: TokenType, ahead?: number): boolean; peek(): Token; advance(): Token; isAtEnd(): boolean; getSource(): string; /** * Whether this document parse is tolerant. The strict/default parser returns * false; `TolerantDocumentParser` overrides it to true. Markup-construction * sites consult this to enable the markup parser's tolerant recovery axis * (`enableTolerant()`), leaving strict (and theme-check) parses untouched. * Disjoint from the render-tree lax axis. */ isTolerant(): boolean; tokenAt(index: number): Token; tokenCount(): number; getPosition(): number; setPosition(index: number): void; /** * Move the cursor to the first token whose `start` is at or after * `sourceOffset`. Unlike a cached token index, a source offset is stable * across `resliceTokensFrom` (which renumbers token slots but preserves * offsets), and it is robust against a body parse that over-advances the * cursor past `sourceOffset` (e.g. a `{% if %}` block inside an HTML raw body * that consumes the element's close tag as text while seeking `{% endif %}`). * Callers that know a token boundary by offset should re-seek here rather than * trusting wherever a nested parse left the cursor. */ seekToSourceOffset(sourceOffset: number): void; /** * Re-tokenize the source from `sourceOffset` onward and splice the fresh * tokens in, positioning the parser at the first of them. * * This is needed after a raw-tag body is scanned at the source level * (see `liquid-raw.ts`): a stray `{{`/`{%` inside the raw body can open a * tokenizer mode that greedily runs *past* the real end tag, producing a * token that straddles the end-tag boundary and absorbs legitimate * post-end-tag content. Re-tokenizing the remainder from exactly the end * tag's end offset restores a clean token stream so content following the * raw block (e.g. a trailing `{{ 1 }}`) is parsed normally. * * Tokens that lie entirely before `sourceOffset` are retained as a prefix * (the parser only moves forward, so they are never revisited); every token * that starts at or straddles the boundary is replaced. * * The re-tokenize is gated on an actual straddle: only when a token starts * before `sourceOffset` and ends after it has the original stream been * corrupted by the body's stray `{{`/`{%`. When the boundary already falls * cleanly between tokens (e.g. `{% raw %}x{% endraw %}` with no stray opener), * the existing tokens past it are correct and carry context a fresh suffix * tokenize cannot reconstruct — an enclosing HTML attribute's closing quote * (`...{% endraw %}">`) or a mid-document `---` that is NOT frontmatter — so * we leave the stream untouched. Frontmatter is also suppressed in the * re-tokenize since the suffix never begins a document. */ /** * If the given prefix tokens end inside an open HTML quoted attribute value, * return the quote character (`"` or `'`) that opened it; otherwise `undefined`. * * An attribute value is "open" at the prefix boundary when the last * `HtmlQuoteOpen` is not yet balanced by an `HtmlQuoteClose`. The quote char * is read from the source at the open token's position so single- and * double-quoted attributes are handled identically. */ private openQuoteCharBefore; /** * Whether the prefix tokens end inside an open HTML tag — an `HtmlTagOpen` * (``) or `HtmlSelfClose` (`/>`). Used * to resume a suffix re-tokenize in `HtmlTag` mode when a `{% raw %}` straddle * lands in an *unquoted* attribute-list position (no enclosing quote). */ private insideOpenHtmlTag; resliceTokensFrom(sourceOffset: number): void; }