Module: Mutant::AST::Regexp Private

Defined in:
lib/mutant/ast/regexp.rb,
lib/mutant/ast/regexp/transformer.rb,
lib/mutant/ast/regexp/transformer/root.rb,
lib/mutant/ast/regexp/transformer/text.rb,
lib/mutant/ast/regexp/transformer/direct.rb,
lib/mutant/ast/regexp/transformer/recursive.rb,
lib/mutant/ast/regexp/transformer/quantifier.rb,
lib/mutant/ast/regexp/transformer/named_group.rb,
lib/mutant/ast/regexp/transformer/options_group.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Regexp source mapper

Defined Under Namespace

Classes: Transformer

Class Method Summary collapse

Class Method Details

.expand_regexp_ast(node) ⇒ Parser::AST::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert’s a ‘parser` `regexp` node into more fine-grained AST nodes.

Parameters:

  • node (Parser::AST::Node)

Returns:

  • (Parser::AST::Node)


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mutant/ast/regexp.rb', line 41

def self.expand_regexp_ast(node)
  *body, _opts = node.children

  # NOTE: We only mutate parts of regexp body if the body is composed of
  # only strings. Regular expressions with interpolation are skipped
  return unless body.all? { |child| child.type.equal?(:str) }

  body_expression = parse(body.map(&:children).join)

  to_ast(body_expression)
end

.parse(regexp) ⇒ Regexp::Expression?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse regex string into expression

Parameters:

  • regexp (String)

Returns:

  • (Regexp::Expression, nil)


12
13
14
# File 'lib/mutant/ast/regexp.rb', line 12

def self.parse(regexp)
  ::Regexp::Parser.parse(regexp)
end

.to_ast(expression) ⇒ Parser::AST::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert expression into ast node

Parameters:

  • expression (Regexp::Expression)

Returns:

  • (Parser::AST::Node)


21
22
23
24
25
# File 'lib/mutant/ast/regexp.rb', line 21

def self.to_ast(expression)
  ast_type = :"regexp_#{expression.token}_#{expression.type}"

  Transformer.lookup(ast_type).to_ast(expression)
end

.to_expression(node) ⇒ Regexp::Expression

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert node into expression

Parameters:

  • node (Parser::AST::Node)

Returns:

  • (Regexp::Expression)


32
33
34
# File 'lib/mutant/ast/regexp.rb', line 32

def self.to_expression(node)
  Transformer.lookup(node.type).to_expression(node)
end