Class: Dhaka::TokenizerState
- Inherits:
-
Object
- Object
- Dhaka::TokenizerState
- Defined in:
- lib/dhaka/tokenizer/tokenizer.rb
Overview
A tokenizer state encapsulates actions that should be performed upon encountering each permissible character for that state.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#default_action ⇒ Object
readonly
Returns the value of attribute default_action.
Instance Method Summary collapse
-
#for_characters(characters, &blk) ⇒ Object
(also: #for_character)
Define the action (
blk
) to be performed when encountering any ofcharacters
in the token stream. -
#for_default(&blk) ⇒ Object
define the action (
blk
) to be performed for anycharacters
that don’t have an action to perform. -
#initialize ⇒ TokenizerState
constructor
A new instance of TokenizerState.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ TokenizerState
Returns a new instance of TokenizerState.
44 45 46 |
# File 'lib/dhaka/tokenizer/tokenizer.rb', line 44 def initialize @actions = {} end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
42 43 44 |
# File 'lib/dhaka/tokenizer/tokenizer.rb', line 42 def actions @actions end |
#default_action ⇒ Object (readonly)
Returns the value of attribute default_action.
42 43 44 |
# File 'lib/dhaka/tokenizer/tokenizer.rb', line 42 def default_action @default_action end |
Instance Method Details
#for_characters(characters, &blk) ⇒ Object Also known as: for_character
Define the action (blk
) to be performed when encountering any of characters
in the token stream.
49 50 51 52 53 |
# File 'lib/dhaka/tokenizer/tokenizer.rb', line 49 def for_characters(characters, &blk) characters.each do |character| actions[character] = blk end end |
#for_default(&blk) ⇒ Object
define the action (blk
) to be performed for any characters
that don’t have an action to perform.
58 59 60 |
# File 'lib/dhaka/tokenizer/tokenizer.rb', line 58 def for_default(&blk) @default_action = blk end |
#to_s ⇒ Object
:nodoc:
62 63 64 |
# File 'lib/dhaka/tokenizer/tokenizer.rb', line 62 def to_s #:nodoc: actions.inspect end |