Skip to content

Commit

Permalink
Make tokenizer syntax ignorant
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Jan 25, 2012
1 parent 34281de commit fd9a25e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/turing_tarpit/scanner.rb
@@ -1,5 +1,8 @@
module TuringTarpit
class Scanner
FORWARD_JUMP = "["
BACKWARD_JUMP = "]"

def initialize(chars)
self.chars = chars
self.index = -1
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/turing_tarpit/tokenizer.rb
Expand Up @@ -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
Expand Down

0 comments on commit fd9a25e

Please sign in to comment.