Class: Mutant::Expression
- Inherits:
-
Object
- Object
- Mutant::Expression
- Includes:
- AbstractType, Adamantium::Flat
- Defined in:
- lib/mutant/expression.rb,
lib/mutant/expression/method.rb,
lib/mutant/expression/methods.rb,
lib/mutant/expression/namespace.rb
Overview
Abstract base class for match expression
Defined Under Namespace
Classes: AmbiguousExpressionError, InvalidExpressionError, Method, Methods, Namespace
Constant Summary collapse
- SCOPE_NAME_PATTERN =
/[A-Za-z][A-Za-z\d_]*/.freeze
- METHOD_NAME_PATTERN =
Regexp.union( /[A-Za-z_][A-Za-z\d_]*[!?=]?/, *AST::Types::OPERATOR_METHODS.map(&:to_s) ).freeze
- INSPECT_FORMAT =
'<Mutant::Expression: %s>'.freeze
- SCOPE_PATTERN =
/#{SCOPE_NAME_PATTERN}(?:#{SCOPE_OPERATOR}#{SCOPE_NAME_PATTERN})*/.freeze
- REGISTRY =
{}
Instance Attribute Summary collapse
-
#inspect ⇒ String
readonly
private
Return inspection.
-
#syntax ⇒ String
readonly
private
Return syntax.
Class Method Summary collapse
-
._load(syntax) ⇒ String, Expression
private
Load serializable representation.
-
.parse(input) ⇒ Expression
private
Parse input into expression or raise.
-
.try_parse(input) ⇒ Expression?
private
Parse input into expression.
Instance Method Summary collapse
-
#_dump(_level) ⇒ String
private
Return marshallable representation.
-
#initialize ⇒ Expression
constructor
private
Initialize expression.
-
#match_length(other) ⇒ Fixnum
private
Return match length for expression.
-
#prefix?(other) ⇒ Boolean
private
Test if expression is prefix.
Constructor Details
#initialize ⇒ 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.
Initialize expression
34 35 36 37 38 |
# File 'lib/mutant/expression.rb', line 34 def initialize(*) super @syntax = match.to_s @inspect = format(INSPECT_FORMAT, syntax) end |
Instance Attribute Details
#inspect ⇒ String (readonly)
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.
Return inspection
73 74 75 |
# File 'lib/mutant/expression.rb', line 73 def inspect @inspect end |
#syntax ⇒ String (readonly)
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.
Return syntax
81 82 83 |
# File 'lib/mutant/expression.rb', line 81 def syntax @syntax end |
Class Method Details
._load(syntax) ⇒ String, 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.
Load serializable representation
63 64 65 |
# File 'lib/mutant/expression.rb', line 63 def self._load(syntax) parse(syntax) end |
.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.
Parse input into expression or raise
134 135 136 |
# File 'lib/mutant/expression.rb', line 134 def self.parse(input) try_parse(input) or fail InvalidExpressionError, "Expression: #{input.inspect} is not valid" end |
.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.
Parse input into expression
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/mutant/expression.rb', line 150 def self.try_parse(input) expressions = expressions(input) case expressions.length when 0 when 1 expressions.first else fail AmbiguousExpressionError, "Ambiguous expression: #{input.inspect}" end end |
Instance Method Details
#_dump(_level) ⇒ String
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.
Return marshallable representation
FIXME: Remove the need for this.
Refactoring Expression objects not to reference a MatchData instance.
This will make this hack unneeded.
51 52 53 |
# File 'lib/mutant/expression.rb', line 51 def _dump(_level) syntax end |
#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.
Return match length for expression
91 92 93 94 95 96 97 |
# File 'lib/mutant/expression.rb', line 91 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
107 108 109 |
# File 'lib/mutant/expression.rb', line 107 def prefix?(other) !match_length(other).zero? end |