Merge pull request #89 from mbj/named-capture-regexp

WIP - Replace position regexp matching with named captures
This commit is contained in:
Markus Schirp 2013-09-08 14:18:28 -07:00
commit 39f508060f
4 changed files with 60 additions and 16 deletions

View file

@ -15,17 +15,12 @@ module Mutant
REGEXP = /
\A
(#{SCOPE_PATTERN})
([.#])
(#{METHOD_NAME_PATTERN})
(?<scope_name>#{SCOPE_PATTERN})
(?<scope_symbol>[.#])
(?<method_name>#{METHOD_NAME_PATTERN})
\z
/x.freeze
# Positions of captured regexp groups
SCOPE_NAME_POSITION = 1
SCOPE_SYMBOL_POSITION = 2
METHOD_NAME_POSITION = 3
private
# Return method matcher
@ -59,7 +54,7 @@ module Mutant
# @api private
#
def scope_name
match[SCOPE_NAME_POSITION]
match[__method__]
end
# Return scope
@ -79,7 +74,7 @@ module Mutant
# @api private
#
def method_name
match[METHOD_NAME_POSITION].to_sym
match[__method__].to_sym
end
# Return scope symbol
@ -89,7 +84,7 @@ module Mutant
# @api private
#
def scope_symbol
match[SCOPE_SYMBOL_POSITION]
match[__method__]
end
# Return matcher class

View file

@ -26,12 +26,12 @@ module Mutant
# @api private
#
def namespace
Classifier.constant_lookup(match[1].to_s)
Classifier.constant_lookup(match[__method__].to_s)
end
# Recursive namespace classifier
class Recursive < self
REGEXP = /\A(#{SCOPE_PATTERN})\*\z/.freeze
REGEXP = /\A(?<namespace>#{SCOPE_PATTERN})\*\z/.freeze
MATCHER = Matcher::Namespace
register
@ -39,7 +39,7 @@ module Mutant
# Recursive namespace classifier
class Flat < self
REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze
REGEXP = /\A(?<namespace>#{SCOPE_PATTERN})\z/.freeze
MATCHER = Matcher::Scope
register

View file

@ -7,7 +7,7 @@ module Mutant
# Scope classifier
class Scope < self
REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze
REGEXP = /\A(?<scope>#{SCOPE_PATTERN})\z/.freeze
private
@ -28,7 +28,7 @@ module Mutant
# @api private
#
def scope
Classifier.constant_lookup(match[1].to_s)
Classifier.constant_lookup(match[__method__].to_s)
end
end # Scope

View file

@ -0,0 +1,49 @@
# encoding: utf-8
module Mutant
class Mutation
class Filter
# Mutation filter that filters on mutation codes
class Code < self
include Concord::Public.new(:code)
# Test for match
#
# @param [Mutation] mutation
#
# @return [true]
# returns true if mutation code matches filter code
#
# @return [false]
# returns false otherwise
#
# @api private
#
def match?(mutation)
mutation.code.eql?(code)
end
PATTERN = /\Acode:(?<code>[a-f0-9]{1,6})\z/.freeze
# Test if class handles string
#
# @param [String] notation
#
# @return [Filter]
# return code filter instance if notation matches pattern
#
# @return [nil]
# returns nil otherwise
#
# @api private
#
def self.handle(notation)
match = PATTERN.match(notation)
return unless match
new(match[:code])
end
end # Code
end # Filter
end # Mutation
end # Mutant