TemplateParserDelegate class abstract

Defines the contract used by delegate parsers to interact with the surrounding template parsing process.

A TemplateParserDelegate provides controlled access to the parser's state and utilities while parsing a template. It acts as a bridge between low-level statement parsing logic and the higher-level template parser.

Implementations (such as TemplateParser) are responsible for:

  • Managing the current position in the template.
  • Providing access to parsing context such as errors and expression grammar.
  • Coordinating traversal between TemplateBlocks.
  • Delegating expression parsing when needed.

Delegate parsers (e.g. StatementDefinition.parse) use this interface to:

  • Inspect upcoming TemplateBlocks.
  • Advance through the template.
  • Parse nested structures (e.g. if, else, endif).
  • Report errors in a consistent way.

Lifecycle

A typical interaction looks like:

  1. A statement parser receives this delegate.
  2. It consumes tokens from the current TemplateBlock.
  3. It may call advanceBlock to move forward.
  4. It may call parseUntil to recursively parse nested content.
  5. It creates AST nodes based on the parsed structure.

TemplateBlock-based parsing

Templates are split into TemplateBlocks (text vs code). This delegate provides access to the current and next block via token streams:

Expression parsing

For parsing expressions inside statements, implementations should use createExpressionParser, which ensures consistent configuration and error tracking.

Error handling

All parsing errors should be reported through errors, allowing the parser to collect and return them as part of the final result.

Implementers must ensure that all returned data (tokens, locations, parsers) remain consistent with the current parsing position.

Implementers

Constructors

TemplateParserDelegate()

Properties

currentBlock → TemplateBlock
no setter
errors → List<ParseError>
The list of accumulated parsing errors.
no setter
grammar → Grammar
The configuration used for parsing
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

advanceBlock() → void
Advances the parser to the next block.
createExpressionParser(CodeTokenStream tokenStream) → ExpressionParser
Creates an ExpressionParser for the given tokenStream.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseUntil(Set<String> terminators) → List<AstNode>
Parses template nodes until one of the given terminators is encountered.
peekBlockTokens() → CodeTokenStream?
Returns a CodeTokenStream for the current block without advancing.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited