struct

Obelisk::ParsingContext

Inherits Struct < Value < Object

Represents the parsing context with look-ahead and look-behind capabilities

Constructors

new(state : LexerState, text : String, position : Int32, history : Array(Obelisk::Token) = [] of Token, look_ahead_cache : Hash(Int32, Nil | String) = {} of Int32 => String | ::Nil)
Source

Instance methods

advance(new_position : Int32, new_token : Token | Nil = nil) : ParsingContext

Clone context with updated position

Source
any_recent_token?(max_lookback : Int32, &block : Token -> Bool) : Bool

Check if any recent token matches a condition

Source
at_line_end?

Check if we're at the end of a line

Source
at_line_start?

Check if we're at the beginning of a line

Source
column_number

Get current column number (1-based)

Source
history
Source
last_token_of_type(type : TokenType) : Token | Nil

Get the most recent token of a specific type from history

Source
line_number

Get current line number (1-based)

Source
look_ahead(count : Int32) : String

Get text after current position (look-ahead)

Source
look_ahead_cache
Source
look_around(before : Int32, after : Int32) : String

Get text around current position

Source
look_behind(count : Int32) : String

Get text before current position (look-behind)

Source
nesting_level(open_types : Array(TokenType), close_types : Array(TokenType)) : Int32

Get nesting level of specific token types (like brackets)

Source
position
Source
recent_tokens(count : Int32, &block : Token -> Bool) : Array(Token)

Get recent tokens matching a condition

Source
state
Source
text
Source