module

Tartrazine

These are Lexer actions. When a rule matches, it will perform a list of actions. These actions can emit tokens or change the state machine.

Constants

EMPTY_TOKENS = [] of Token

Shared empty result for rule misses (allocation cut, see patch 5). Never mutated: the only consumer iterates it into a deque.

HWARO_CUSTOM_KEY_PREFIX = "hwaro-custom/"
HWARO_LEXER_ALIASES = {"cr" => "crystal", "yml" => "yaml"}
HWARO_MAX_INCLUDES = 64
HWARO_MAX_NESTING = 32
HWARO_MAX_STALLS = 1000
HWARO_STATE_REFS = {"push", "include", "combined"}

Elements whose state attribute names a state of the same lexer.

Class methods

hwaro_custom_language_for(basename : String) : String | Nil

The custom lexer for a lowercased file base name (an exact <filename> entry or a glob), or nil.

Source
hwaro_custom_lexer?(name : String) : Bool
Source
hwaro_lexer_known?(name : String, custom : Enumerable(String)) : Bool

Whether lexer_by_name resolves name (lowercased), given the custom lexer names in custom: a custom or bundled name, or a+b (a delegating lexer, split at the first +) whose halves both resolve.

Source
hwaro_parse_custom_lexer(xml : String) : Tuple(Array(String), Array(String), LexerTemplate, Array(String), Array(String))

Parse one grammar file's XML. Returns the lowercased names it registers under (<name> first, then each <alias>), its lowercased <filename> globs, its template, warnings, and the lowercased <using lexer> names that are neither bundled nor its own (the caller checks them against the other custom grammars). Warnings cover what only fails once tokenization reaches it, so the block then falls back to plain: a <push>, <include> or <combined> naming a state the grammar does not define (three bundled grammars have one, so these warn rather than reject), a cycle of <include>s, a pattern-less rule that emits a <token>, and a negative <pop depth>. A <filename> glob File.match? would refuse is dropped with a warning. Raises with a readable message on malformed XML, a missing <name> or root state, an unknown action, or a regex PCRE2 refuses to compile.

Source
hwaro_register_custom_lexers(entries : Array(Tuple(Array(String), Array(String), LexerTemplate))) : Nil

Replace every previously registered custom lexer with entries (names, filename globs, template). Earlier entries win a name both claim; the caller orders and reports those.

Source

Nested types