Sha256: 6dcb242eca187c69596137fe430cfab1adb9463a0318b977b21181ba531d6923

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

module Mutant
  module AST
    module Regexp
      class Transformer
        # Transformer for character sets
        #
        # The `Regexp::Expression` representation of a character set
        # is unique due to its usage of the `#members` attribute which
        # is why it gets its own transformer
        class CharacterSet < self
          register :regexp_character_set

          # Mapper from `Regexp::Expression` to `Parser::AST::Node`
          class ExpressionToAST < Transformer::ExpressionToAST
            # Transform character set expression into node
            #
            # @return [Parser::AST::Node]
            def call
              quantify(ast(*expression.members))
            end
          end # ExpressionToAST

          # Mapper from `Parser::AST::Node` to `Regexp::Expression`
          class ASTToExpression < Transformer::ASTToExpression
            CHARACTER_SET = IceNine.deep_freeze(
              ::Regexp::Expression::CharacterSet.new(
                ::Regexp::Token.new(:set, :character, '[')
              )
            )

          private

            # Transform node into expression
            #
            # @return [Regexp::Expression]
            def transform
              CHARACTER_SET.dup.tap do |expression|
                expression.members = node.children
              end
            end
          end # ASTToExpression
        end # CharacterSet
      end # Transformer
    end # Regexp
  end # AST
end # Mutant

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mutant-0.8.16 lib/mutant/ast/regexp/transformer/character_set.rb
mutant-0.8.15 lib/mutant/ast/regexp/transformer/character_set.rb
mutant-0.8.14 lib/mutant/ast/regexp/transformer/character_set.rb
mutant-0.8.13 lib/mutant/ast/regexp/transformer/character_set.rb
mutant-0.8.12 lib/mutant/ast/regexp/transformer/character_set.rb
mutant-0.8.11 lib/mutant/ast/regexp/transformer/character_set.rb