class RLTK::Lexer::Environment
All actions passed to LexerCore.rule are evaluated inside an instance of the Environment
class or its subclass (which must have the same name). This class provides functions for manipulating lexer state and flags.
Attributes
@return [Array<Symbol>] Flags currently set in this environment.
@return [Match] Match object generated by a rule’s regular expression.
Public Class Methods
Instantiates a new Environment
object.
@param [Symbol] start_state Lexer’s start state. @param [Match] match Match object for matching text.
# File lib/rltk/lexer.rb, line 261 def initialize(start_state, match = nil) @state = [start_state] @match = match @flags = Array.new end
Public Instance Methods
Unsets all flags in the current environment.
@return [void]
# File lib/rltk/lexer.rb, line 340 def clear_flags @flags = Array.new nil end
Pops a state from the state stack.
@return [void]
# File lib/rltk/lexer.rb, line 282 def pop_state @state.pop nil end
Pushes a new state onto the state stack.
@return [void]
# File lib/rltk/lexer.rb, line 291 def push_state(state) @state << state nil end
This function will instance_exec a block for a rule after setting the match value.
@param [Match] match Match object for matching text. @param [String] txt Text of matching string. @param [Proc] block Block for matched rule.
# File lib/rltk/lexer.rb, line 273 def rule_exec(match, txt, &block) self.match = match self.instance_exec(txt, &block) end
Sets a flag in the current environment.
@param [Symbol] flag Flag to set as enabled.
@return [void]
# File lib/rltk/lexer.rb, line 318 def set_flag(flag) if not @flags.include?(flag) @flags << flag end nil end
Sets the value on the top of the state stack.
@param [Symbol] state New state for the lexing environment.
@return [void]
# File lib/rltk/lexer.rb, line 302 def set_state(state) @state[-1] = state nil end
@return [Symbol] Current state of the lexing environment.
# File lib/rltk/lexer.rb, line 309 def state @state.last end
Unsets a flag in the current environment.
@param [Symbol] flag Flag to unset.
@return [void]
# File lib/rltk/lexer.rb, line 331 def unset_flag(flag) @flags.delete(flag) nil end