Class: RLTK::Lexer::Environment
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.
251 252 253 254 255 |
# File 'lib/rltk/lexer.rb', line 251 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.
242 243 244 |
# File 'lib/rltk/lexer.rb', line 242 def flags @flags end |
#match ⇒ Match
Returns Match object generated by a rule’s regular expression.
245 246 247 |
# File 'lib/rltk/lexer.rb', line 245 def match @match end |
Instance Method Details
#clear_flags ⇒ void
This method returns an undefined value.
Unsets all flags in the current environment.
330 331 332 333 334 |
# File 'lib/rltk/lexer.rb', line 330 def clear_flags @flags = Array.new nil end |
#pop_state ⇒ void
This method returns an undefined value.
Pops a state from the state stack.
272 273 274 275 276 |
# File 'lib/rltk/lexer.rb', line 272 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.
281 282 283 284 285 |
# File 'lib/rltk/lexer.rb', line 281 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.
263 264 265 266 267 |
# File 'lib/rltk/lexer.rb', line 263 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.
308 309 310 311 312 313 314 |
# File 'lib/rltk/lexer.rb', line 308 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.
292 293 294 295 296 |
# File 'lib/rltk/lexer.rb', line 292 def set_state(state) @state[-1] = state nil end |
#state ⇒ Symbol
Returns Current state of the lexing environment.
299 300 301 |
# File 'lib/rltk/lexer.rb', line 299 def state @state.last end |
#unset_flag(flag) ⇒ void
This method returns an undefined value.
Unsets a flag in the current environment.
321 322 323 324 325 |
# File 'lib/rltk/lexer.rb', line 321 def unset_flag(flag) @flags.delete(flag) nil end |