Class: Dhaka::LexerSupport::DFARun
- Inherits:
-
Object
- Object
- Dhaka::LexerSupport::DFARun
- Defined in:
- lib/dhaka/lexer/dfa.rb
Instance Method Summary collapse
- #accept(pattern) ⇒ Object
- #accept_last_saved_checkpoint(pattern) ⇒ Object
-
#initialize(dfa, input) ⇒ DFARun
constructor
A new instance of DFARun.
- #match ⇒ Object
- #save_checkpoint(pattern) ⇒ Object
Constructor Details
#initialize(dfa, input) ⇒ DFARun
Returns a new instance of DFARun.
89 90 91 92 93 94 |
# File 'lib/dhaka/lexer/dfa.rb', line 89 def initialize(dfa, input) @dfa, @input = dfa, input @matched = "" @not_yet_accepted = "" @curr_state = @dfa.start_state end |
Instance Method Details
#accept(pattern) ⇒ Object
110 111 112 113 |
# File 'lib/dhaka/lexer/dfa.rb', line 110 def accept(pattern) @matched.concat @not_yet_accepted @not_yet_accepted = "" end |
#accept_last_saved_checkpoint(pattern) ⇒ Object
115 116 117 118 |
# File 'lib/dhaka/lexer/dfa.rb', line 115 def accept_last_saved_checkpoint(pattern) @matched = @last_saved_checkpoint @not_yet_accepted = "" end |
#match ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/dhaka/lexer/dfa.rb', line 96 def match @input.unpack("C*").each do |i| break unless dest_state = @curr_state.transitions[i.chr] @not_yet_accepted << i.chr @curr_state = dest_state @curr_state.process(self) end @matched end |
#save_checkpoint(pattern) ⇒ Object
106 107 108 |
# File 'lib/dhaka/lexer/dfa.rb', line 106 def save_checkpoint(pattern) @last_saved_checkpoint = @matched + @not_yet_accepted end |