Sha256: 8978d2f13fc93fa4db4b171bccad77027a96d1b0654813cfcf1901de656b1677

Contents?: true

Size: 786 Bytes

Versions: 63

Compression:

Stored size: 786 Bytes

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'regexp_parser'

module TwitterCldr
  module Resources

    class RegexpAstGenerator
      class << self

        def generate(regexp_str)
          tree = Regexp::Parser.parse(regexp_str)
          walk(tree)
        end

        private

        def walk(node)
          expressions = if node.respond_to?(:expressions)
            node.expressions.map { |expr| walk(expr) }
          else
            []
          end

          class_for(node).from_parser_node(node, expressions)
        end

        def class_for(klass)
          TwitterCldr::Utils::RegexpAst.const_get(
            klass.class.to_s.split("::").last.to_sym
          )
        end

      end
    end

  end
end

Version data entries

63 entries across 63 versions & 3 rubygems

Version Path
twitter_cldr-4.1.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-4.0.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.6.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.5.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.4.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.3.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/resources/regexp_ast_generator.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/resources/regexp_ast_generator.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.2.1 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.2.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.1.2 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.1.1 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.1.0 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.0.10 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.0.9 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.0.8 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.0.7 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.0.6 lib/twitter_cldr/resources/regexp_ast_generator.rb
twitter_cldr-3.0.5 lib/twitter_cldr/resources/regexp_ast_generator.rb