lib/grok-pure.rb
def compile_captures_func(re)
    re_match = ["lambda do |match, &block|"]
    re.named_captures.each do |name, indices|
      pattern, name, coerce = name.split(":")
      indices.each do |index|
        coerce = case coerce
                   when "int"; ".to_i"
                   when "float"; ".to_f"
                   else; ""
                 end
        name = pattern if name.nil?
        if coerce
          re_match << "  m = match[#{index}]"
          re_match << "  block.call(#{name.inspect}, (m ? m#{coerce} : m))"
        else
          re_match << "  block.call(#{name.inspect}, match[#{index}])"
        end
      end
    end
    re_match << "end"
    return eval(re_match.join("\n"))
  end
# compiles the captures lambda so runtime match can be optimized
compiles the captures lambda so runtime match can be optimized
compiles the captures lambda so runtime match can be optimized
def compile_captures_func(re)
    re_match = ["lambda do |match, &block|"]
    re.named_captures.each do |name, indices|
      pattern, name, coerce = name.split(":")
      indices.each do |index|
        coerce = case coerce
                   when "int"; ".to_i"
                   when "float"; ".to_f"
                   else; ""
                 end
        name = pattern if name.nil?
        if coerce
          re_match << "  m = match[#{index}]"
          re_match << "  block.call(#{name.inspect}, (m ? m#{coerce} : m))"
        else
          re_match << "  block.call(#{name.inspect}, match[#{index}])"
        end
      end
    end
    re_match << "end"
    return eval(re_match.join("\n"))
  end
def compile_captures_func ( re ) re_match = [ "lambda do |match, &block|" ] re . named_captures . each do | name , indices | pattern , name , coerce = name . split ( ":" ) indices . each do | index | coerce = case coerce when "int" ; ".to_i" when "float" ; ".to_f" else ; "" end name = pattern if name . nil? if coerce re_match << "  m = match[#{index}]" re_match << "  block.call(#{name.inspect}, (m ? m#{coerce} : m))" else re_match << "  block.call(#{name.inspect}, match[#{index}])" end end end re_match << "end" return eval ( re_match . join ( "\n" ) ) end
compiles the captures lambda so runtime match can be optimized
compiles the captures lambda so runtime match can be optimized
re