Sha256: 3c40bce4927ded0b302e9aab1a43a99e313aed81d61a14b9e51cf0d55ed77b3b

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module Mutant
  module AST
    module Regexp
      class Transformer
        # Transformer for Regexp `alternative` nodes
        #
        # This transformer is very similar to the generic recursive mapper
        # except for the fact that the `Regexp::Expression` class for
        # `alternative` nodes has a unique constructor
        class Alternative < self
          register :regexp_sequence_expression

          # Mapper from `Regexp::Expression` to `Parser::AST::Node`
          ExpressionToAST = Class.new(Recursive::ExpressionToAST)

          # Mapper from `Parser::AST::Node` to `Regexp::Expression`
          class ASTToExpression < Transformer::ASTToExpression
            # Alternative instance with dummy values for `level`, `set_level`,
            # and `conditional_level`. These values do not affect unparsing
            ALTERNATIVE = IceNine.deep_freeze(
              ::Regexp::Expression::Alternative.new(0, 0, 0)
            )

          private

            # Transform ast into expression
            #
            # @return [Regexp::Expression::Alternative]
            def transform
              ALTERNATIVE.dup.tap do |alt|
                alt.expressions = subexpressions
              end
            end
          end # ASTToExpression
        end # Alternative
      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/alternative.rb
mutant-0.8.15 lib/mutant/ast/regexp/transformer/alternative.rb
mutant-0.8.14 lib/mutant/ast/regexp/transformer/alternative.rb
mutant-0.8.13 lib/mutant/ast/regexp/transformer/alternative.rb
mutant-0.8.12 lib/mutant/ast/regexp/transformer/alternative.rb
mutant-0.8.11 lib/mutant/ast/regexp/transformer/alternative.rb