Permalink
Browse files

Make tokenizer syntax ignorant

  • Loading branch information...
practicingruby committed Jan 25, 2012
1 parent 34281de commit fd9a25ec4ab618b6d0e10649af550723e233d919
Showing with 8 additions and 5 deletions.
  1. +5 −2 lib/turing_tarpit/scanner.rb
  2. +3 −3 lib/turing_tarpit/tokenizer.rb
@@ -1,5 +1,8 @@
module TuringTarpit
class Scanner
+ FORWARD_JUMP = "["
+ BACKWARD_JUMP = "]"
+
def initialize(chars)
self.chars = chars
self.index = -1
@@ -21,11 +24,11 @@ def next_while(char)
end
def jump_forward
- jump("[", "]", 1)
+ jump(FORWARD_JUMP, BACKWARD_JUMP, 1)
end
def jump_back
- jump("]", "[", -1)
+ jump(BACKWARD_JUMP, FORWARD_JUMP, -1)
end
private
@@ -8,12 +8,12 @@ def initialize(source_text)
def next(cell_value)
case scanner.next_char
- when "["
+ when Scanner::FORWARD_JUMP
scanner.jump_forward if cell_value.zero?
scanner.next_char
- when "]"
+ when Scanner::BACKWARD_JUMP
if cell_value.zero?
- scanner.next_while("]")
+ scanner.next_while(Scanner::BACKWARD_JUMP)
else
scanner.jump_back
scanner.next_char

0 comments on commit fd9a25e

Please sign in to comment.