MacroExpander class final
Reads tokens from a Lexer and expands macros.
The parser reads through peek/pop, which return the next token that
is not a macro. Raw access (peekRaw/popRaw) is for arguments that must
not be expanded, such as a \def body.
Constructors
- MacroExpander(Lexer _lexer, MacroTable macros, {required int maxExpand, required void report(Diagnostic diagnostic), required bool isDefined(String name), required int maxTokens, bool overBudget()?})
-
Creates an expander over
lexer.
Properties
- expansionCount → int
-
Number of expansions performed so far.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hitEndOfInput ↔ bool
-
Set when an argument or definition was cut off by the end of input.
getter/setter pair
- isDefined → bool Function(String name)
-
Whether a control sequence has any meaning (macro, function, symbol).
final
- macros → MacroTable
-
The macro definitions in effect.
final
- maxExpand → int
-
Maximum number of expansions.
final
- maxTokens → int
-
Maximum number of tokens all expansions together may produce.
final
- mode ↔ Mode
-
Current mode, kept in sync by the parser.
getter/setter pair
- overBudget → bool Function()?
-
Returns true when the parse has run out of time. Checked as work is
done (expansions and the tokens they produce), never more than a few
thousand tokens apart, so no single expansion can outrun it.
final
- report → void Function(Diagnostic diagnostic)
-
Receives diagnostics raised while expanding.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tokenCount → int
-
Number of tokens expansions have produced so far.
no setter
Methods
-
expandOnce(
) → bool - Expands the next token once if it is a macro. Returns false otherwise.
-
expandTokens(
List< Token> tokens) → List<Token> -
Fully expands
tokens(for\edef,\xdef). -
isAtEnd(
Token t) → bool -
Whether
tis the last thing in the source (nothing, not even a space, follows it). -
isExpandable(
Token t) → bool -
Whether
tis a macro that would be expanded. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
peek(
) → Token - The next unexpandable token, expanding macros as needed.
-
peekRaw(
) → Token - The next token without expanding it.
-
pop(
) → Token - Removes and returns the next unexpandable token.
-
popRaw(
) → Token - Removes and returns the next token without expanding it.
-
push(
Token token) → void -
Pushes
tokenback so it is read next. -
pushAll(
List< Token> tokens) → void -
Pushes
tokensso thattokens.firstis read next. -
readArgument(
) → MacroArgument - Reads one undelimited argument: a braced group (without its braces) or a single token. Spaces before it are skipped.
-
readMacroName(
) → Token? -
Reads a control-sequence name, either bare (
\foo) or braced ({\foo}). Returns null (and leaves input) when neither is present. -
readOptionalArgument(
) → MacroArgument? -
Reads
[…]if present (after optional spaces), balanced on braces. -
skipRawSpaces(
) → void - Skips space tokens without expanding.
-
skipSpaces(
) → void - Skips expanded space tokens.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
substitute(
List< Token> body, List<List< args, SourceSpan span, {int? cutOffArg}) → List<Token> >Token> -
Replaces
#ninbodywithargsand##with#. Body tokens getspan; argument tokens keep their own.