Sha256: afc2b74016f207d788415904a174aecc3ccf7f6238068ffd82f0a270f7c209c7

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 Bytes

Contents

module Treetop
  module Compiler    
    class Regex < AtomicExpression
      def compile(address, builder, parent_expression = nil)
        super
        
        # I really think there should be 4 slashes in that replacement string, but 6 works. Deeply weird
        rx = text_value[2..-2].gsub("\\", "\\\\\\") # strip 'r(' and ')'
        rx = "%(#{rx})" 
        
        builder.if__ "(rx_match = regex_match?(#{rx}, index))" do
          assign_result "instantiate_node(#{node_class_name},input, index...(index + rx_match.length))"
          extend_result_with_inline_module
          builder << "@index += rx_match.length"
        end
        builder.else_ do
          builder << "terminal_parse_failure('/' + #{rx} + '/')"
          assign_result 'nil'
        end
      end
    end
 end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
regex-treetop-1.4.8 lib/treetop/compiler/node_classes/regex.rb