Class: Dhaka::TokenizerState

Inherits:
Object
  • Object
show all
Defined in:
lib/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

Instance Method Summary collapse

Constructor Details

#initializeTokenizerState

Returns a new instance of TokenizerState.



44
45
46
# File 'lib/tokenizer/tokenizer.rb', line 44

def initialize
  @actions = {}
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



42
43
44
# File 'lib/tokenizer/tokenizer.rb', line 42

def actions
  @actions
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/tokenizer/tokenizer.rb', line 49

def for_characters(characters, &blk)
  characters.each do |character|
    actions[character] = blk
  end
end

#to_sObject

:nodoc:



57
58
59
# File 'lib/tokenizer/tokenizer.rb', line 57

def to_s #:nodoc:
  actions.inspect
end