lib/r-fxxk.rb in r-fxxk-0.1.0 vs lib/r-fxxk.rb in r-fxxk-0.2.0
- old
+ new
@@ -22,16 +22,21 @@
instance_variable_get(:@operations)[op]
end
end
def compile(src)
+ BrainFuck.new.translate(self, src)
+ end
+
+ def translate(other, src)
+ other = other.new if other.kind_of?(Class)
cur = 0
- inv = operations.invert
- reg = Regexp.compile "(#{operations.values.map{|v| Regexp.quote(v) }.join('|')})"
+ inv = other.operations.invert
+ reg = Regexp.compile "(#{other.operations.values.map{|v| Regexp.quote(v) }.join('|')})"
dst = ''
while matches = reg.match(src, cur)
op = inv[matches[1]]
- dst += self.class.bf_mapping[op]
+ dst += operations[op]
cur = src.index(reg, cur) + matches[1].length
end
dst
end