class Ragel::Bitmap::Replace
A ruby parser that finds instances of table declarations in a ragel-outputted file.
Attributes
tables[R]
Public Class Methods
bitmap_args_from(numbers)
click to toggle source
Get the required args for a bitmap from a set of numbers
# File lib/ragel/bitmap/replace.rb, line 12 def bitmap_args_from(numbers) size = (Math.log2(numbers.max) / 8).ceil strings = size.downto(1).map do |index| shift = (index - 1) * 8 numbers.map { |number| (number >> shift) & 0xff }.pack('C*') end [class_from(size), strings] end
new(*)
click to toggle source
Calls superclass method
# File lib/ragel/bitmap/replace.rb, line 79 def initialize(*) super @tables = [] end
replace(source)
click to toggle source
# File lib/ragel/bitmap/replace.rb, line 95 def self.replace(source) buffer = Buffer.new(source) new(source).each_table { |table| buffer.replace(table) } buffer.to_source end
Private Class Methods
class_from(size)
click to toggle source
# File lib/ragel/bitmap/replace.rb, line 25 def class_from(size) case size when 1 then :Array8 when 2 then :Array16 when 3 then :Array24 else :ArrayGeneric end end
Public Instance Methods
each_table(&block)
click to toggle source
# File lib/ragel/bitmap/replace.rb, line 84 def each_table(&block) parse if error? warn 'Invalid ruby' exit 1 end tables.reverse_each(&block) end
Private Instance Methods
on_assign(left, right)
click to toggle source
Calls superclass method
# File lib/ragel/bitmap/replace.rb, line 103 def on_assign(left, right) super.tap do next if left[0] != :field || right[0] != :array tables << Table.new(left, right, lineno) end end