Class: Mutant::Expression

Inherits:
Object
  • Object
show all
Includes:
AbstractType, Adamantium::Flat
Defined in:
lib/mutant/expression.rb,
lib/mutant/expression/method.rb,
lib/mutant/expression/parser.rb,
lib/mutant/expression/methods.rb,
lib/mutant/expression/namespace.rb

Overview

Abstract base class for match expression

Direct Known Subclasses

Method, Methods, Namespace

Defined Under Namespace

Classes: Method, Methods, Namespace, Parser

Constant Summary collapse

SCOPE_NAME_PATTERN =
/(?<scope_name>#{fragment}(?:#{SCOPE_OPERATOR}#{fragment})*)/.freeze
SCOPE_SYMBOL_PATTERN =
'(?<scope_symbol>[.#])'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.try_parse(input) ⇒ 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.

Try to parse input into expression of receiver class

Parameters:

  • input (String)

Returns:

  • (Expression)

    when successful

  • (nil)

    otherwise



57
58
59
60
61
62
# File 'lib/mutant/expression.rb', line 57

def self.try_parse(input)
  match = self::REGEXP.match(input)
  return unless match
  names = anima.attribute_names
  new(Hash[names.zip(names.map(&match.method(:[])))])
end

Instance Method Details

#match_length(other) ⇒ Fixnum

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.

Match length with other expression

Parameters:

Returns:

  • (Fixnum)


27
28
29
30
31
32
33
# File 'lib/mutant/expression.rb', line 27

def match_length(other)
  if eql?(other)
    syntax.length
  else
    0
  end
end

#prefix?(other) ⇒ Boolean

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.

Test if expression is prefix

Parameters:

Returns:

  • (Boolean)


42
43
44
# File 'lib/mutant/expression.rb', line 42

def prefix?(other)
  !match_length(other).zero?
end

#syntaxString

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.

Syntax of expression

Returns:

  • (String)


18
# File 'lib/mutant/expression.rb', line 18

abstract_method :syntax