Reduce duplication in mutant/constants.rb via class level helper
This commit is contained in:
parent
0df898b0ef
commit
9134b57ae7
2 changed files with 24 additions and 23 deletions
|
@ -2,30 +2,36 @@
|
|||
|
||||
module Mutant
|
||||
|
||||
# Return a frozen set of symbols from string enumerable
|
||||
#
|
||||
# @param [Enumerable<String>]
|
||||
#
|
||||
# @return [Set<Symbol>]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.symbolset(strings)
|
||||
strings.map(&:to_sym).to_set.freeze
|
||||
end
|
||||
private_class_method :symbolset
|
||||
|
||||
# Set of nodes that cannot be on the LHS of an assignment
|
||||
NOT_ASSIGNABLE = [
|
||||
:int, :float, :str, :dstr, :class, :module, :self
|
||||
].to_set.freeze
|
||||
NOT_ASSIGNABLE = symbolset %w(
|
||||
int float str dstr class module self
|
||||
)
|
||||
|
||||
# Set of op-assign types
|
||||
OP_ASSIGN = [
|
||||
:or_asgn, :and_asgn, :op_asgn
|
||||
].to_set.freeze
|
||||
|
||||
OP_ASSIGN = symbolset %w(or_asgn and_asgn op_asgn)
|
||||
# Set of node types that are not valid when emitted standalone
|
||||
NOT_STANDALONE = [:splat, :restarg, :block_pass].to_set.freeze
|
||||
NOT_STANDALONE = symbolset %w( splat restarg block_pass)
|
||||
INDEX_OPERATORS = symbolset %w([] []=)
|
||||
UNARY_METHOD_OPERATORS = symbolset %w(~@ +@ -@ !)
|
||||
|
||||
# Operators ruby implementeds as methods
|
||||
METHOD_OPERATORS = %w(
|
||||
METHOD_OPERATORS = symbolset %w(
|
||||
<=> === []= [] <= >= == !~ != =~ <<
|
||||
>> ** * % / | ^ & < > + - ~@ +@ -@ !
|
||||
).map(&:to_sym).to_set.freeze
|
||||
|
||||
INDEX_OPERATORS = [:[], :[]=].to_set.freeze
|
||||
|
||||
UNARY_METHOD_OPERATORS = %w(
|
||||
~@ +@ -@ !
|
||||
).map(&:to_sym).to_set.freeze
|
||||
)
|
||||
|
||||
BINARY_METHOD_OPERATORS = (
|
||||
METHOD_OPERATORS - (INDEX_OPERATORS + UNARY_METHOD_OPERATORS)
|
||||
|
@ -39,14 +45,10 @@ module Mutant
|
|||
#
|
||||
# not - 1.8 only, mutant does not support 1.8
|
||||
#
|
||||
NODE_BLACKLIST = %w(
|
||||
not
|
||||
).map(&:to_sym).freeze
|
||||
NODE_BLACKLIST = symbolset %w(not)
|
||||
|
||||
# Nodes that are NOT generated by parser but used by mutant / unparser.
|
||||
NODE_EXTRA = %w(
|
||||
empty
|
||||
).map(&:to_sym).freeze
|
||||
NODE_EXTRA = symbolset %w(empty)
|
||||
|
||||
NODE_TYPES = ((Parser::Meta::NODE_TYPES + NODE_EXTRA) - NODE_BLACKLIST).to_set.freeze
|
||||
|
||||
|
|
|
@ -22,4 +22,3 @@ module Parser
|
|||
).map(&:to_sym).to_set.freeze
|
||||
end # Meta
|
||||
end # Parser
|
||||
|
||||
|
|
Loading…
Reference in a new issue