
Several steps were made to achieve mutant working with Ruby 2.4 without warnings and spec failures: * Fix Fixnum deprecation warning * Update RuboCop to 0.47 and fix offenses * Relax version requirements on parser gem * Update diff-lcs to 1.3 * Update rake 11.x -> 12.x * Update reek 4.5 -> 4.6 (to work with parser 2.4) * Update json 2.0 -> 2.1 * Update parallel 1.10 -> 1.11 * Update simplecov 0.12 -> 0.14 * Run regexp_parser integration against v0.4.3 (as we requiring this exact version) * Update warnings.yml with new whitelist * Run CircleCI tests on Ruby 2.3 and 2.4 (Bundler.with_clean_env was causing troubles on new CircleCI 2.0 setup, so it was removed)
57 lines
1.2 KiB
Ruby
57 lines
1.2 KiB
Ruby
module Mutant
|
|
|
|
# Abstract base class for match expression
|
|
class Expression
|
|
include AbstractType, Adamantium::Flat
|
|
|
|
fragment = /[A-Za-z][A-Za-z\d_]*/.freeze
|
|
SCOPE_NAME_PATTERN = /(?<scope_name>#{fragment}(?:#{SCOPE_OPERATOR}#{fragment})*)/.freeze
|
|
SCOPE_SYMBOL_PATTERN = '(?<scope_symbol>[.#])'.freeze
|
|
|
|
private_constant(*constants(false))
|
|
|
|
# Syntax of expression
|
|
#
|
|
# @return [String]
|
|
abstract_method :syntax
|
|
|
|
# Match length with other expression
|
|
#
|
|
# @param [Expression] other
|
|
#
|
|
# @return [Integer]
|
|
def match_length(other)
|
|
if eql?(other)
|
|
syntax.length
|
|
else
|
|
0
|
|
end
|
|
end
|
|
|
|
# Test if expression is prefix
|
|
#
|
|
# @param [Expression] other
|
|
#
|
|
# @return [Boolean]
|
|
def prefix?(other)
|
|
!match_length(other).zero?
|
|
end
|
|
|
|
# Try to parse input into expression of receiver class
|
|
#
|
|
# @param [String] input
|
|
#
|
|
# @return [Expression]
|
|
# when successful
|
|
#
|
|
# @return [nil]
|
|
# otherwise
|
|
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
|
|
|
|
end # Expression
|
|
end # Mutant
|