class

KrikriJinja::Lexer

Inherits Reference < Object

Constructors

new(source : String, options : LexerOptions = LexerOptions.new)
Source

Class methods

find_next_tag(src : String, pos : Int32, opts : LexerOptions) : Tuple(Int32, String) | Nil

Single forward byte scan for the earliest of the three tag openers. Returns the char index of the opener and which opener matched, or nil when none remains. Replaces three separate String#index scans plus an array allocation per tag.

Source
id_cont?(ch : Char) : Bool
Source
id_start?(ch : Char) : Bool
Source
scan_tag_end(src : String, start : Int32, delim_end : String, comment : Bool = false) : Tuple(Int32 | Nil, Bool, Bool)

Finds the tag closer starting at start, skipping quoted strings and balancing braces when the closer itself starts with "}". Returns the tag's content end, whether it closed with a - strip marker, and whether it closed with a + KEEP marker (Jinja2's whitespace-control form that suppresses trim_blocks for that tag).

comment marks a COMMENT body, which Jinja2 never scans for string literals or balanced braces: its comment rule is \{#.*?(?:#\}|\Z) with DOTALL, so the first #} closes it however the text between reads. Running the quote-skipping loop below on a comment made an apostrophe ("Jinja currently doesn't have...") open a string that ran past the #}, and the whole comment then failed as unclosed "{#" tag (ableton.sccache's templates/config.j2).

Source

Instance methods

tokens
Source