Class: RLTK::Lexer::Environment
- Inherits:
-
Object
- Object
- RLTK::Lexer::Environment
- Defined in:
- lib/rltk/lexer.rb
Overview
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.
Instance Attribute Summary collapse
-
#flags ⇒ Array<Symbol>
readonly
Flags currently set in this environment.
-
#match ⇒ Match
Match object generated by a rule’s regular expression.
Instance Method Summary collapse
-
#clear_flags ⇒ void
Unsets all flags in the current environment.
-
#initialize(start_state, match = nil) ⇒ Environment
constructor
Instantiates a new Environment object.
-
#pop_state ⇒ void
Pops a state from the state stack.
-
#push_state(state) ⇒ void
Pushes a new state onto the state stack.
-
#rule_exec(match, txt, &block) ⇒ Object
This function will instance_exec a block for a rule after setting the match value.
-
#set_flag(flag) ⇒ void
Sets a flag in the current environment.
-
#set_state(state) ⇒ void
Sets the value on the top of the state stack.
-
#state ⇒ Symbol
Current state of the lexing environment.
-
#unset_flag(flag) ⇒ void
Unsets a flag in the current environment.
Constructor Details
#initialize(start_state, match = nil) ⇒ Environment
Instantiates a new Environment object.
261 262 263 264 265 |
# File 'lib/rltk/lexer.rb', line 261 def initialize(start_state, match = nil) @state = [start_state] @match = match @flags = Array.new end |
Instance Attribute Details
#flags ⇒ Array<Symbol> (readonly)
Returns Flags currently set in this environment.
252 253 254 |
# File 'lib/rltk/lexer.rb', line 252 def flags @flags end |
#match ⇒ Match
Returns Match object generated by a rule’s regular expression.
255 256 257 |
# File 'lib/rltk/lexer.rb', line 255 def match @match end |
Instance Method Details
#clear_flags ⇒ void
This method returns an undefined value.
Unsets all flags in the current environment.
340 341 342 343 344 |
# File 'lib/rltk/lexer.rb', line 340 def clear_flags @flags = Array.new nil end |
#pop_state ⇒ void
This method returns an undefined value.
Pops a state from the state stack.
282 283 284 285 286 |
# File 'lib/rltk/lexer.rb', line 282 def pop_state @state.pop nil end |
#push_state(state) ⇒ void
This method returns an undefined value.
Pushes a new state onto the state stack.
291 292 293 294 295 |
# File 'lib/rltk/lexer.rb', line 291 def push_state(state) @state << state nil end |
#rule_exec(match, txt, &block) ⇒ Object
This function will instance_exec a block for a rule after setting the match value.
273 274 275 276 277 |
# File 'lib/rltk/lexer.rb', line 273 def rule_exec(match, txt, &block) self.match = match self.instance_exec(txt, &block) end |
#set_flag(flag) ⇒ void
This method returns an undefined value.
Sets a flag in the current environment.
318 319 320 321 322 323 324 |
# File 'lib/rltk/lexer.rb', line 318 def set_flag(flag) if not @flags.include?(flag) @flags << flag end nil end |
#set_state(state) ⇒ void
This method returns an undefined value.
Sets the value on the top of the state stack.
302 303 304 305 306 |
# File 'lib/rltk/lexer.rb', line 302 def set_state(state) @state[-1] = state nil end |
#state ⇒ Symbol
Returns Current state of the lexing environment.
309 310 311 |
# File 'lib/rltk/lexer.rb', line 309 def state @state.last end |
#unset_flag(flag) ⇒ void
This method returns an undefined value.
Unsets a flag in the current environment.
331 332 333 334 335 |
# File 'lib/rltk/lexer.rb', line 331 def unset_flag(flag) @flags.delete(flag) nil end |