Class: Mutant::Expression
- Inherits:
-
Object
- Object
- Mutant::Expression
- Includes:
- AbstractType, Adamantium
- 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: AmbigousExpressionError, 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
- SCOPE_PATTERN =
/#{SCOPE_NAME_PATTERN}(?:#{SCOPE_OPERATOR}#{SCOPE_NAME_PATTERN})*/.freeze
- REGISTRY =
{}
Instance Attribute Summary collapse
-
#syntax ⇒ String
readonly
private
Return syntax.
Class Method Summary collapse
-
.parse(input) ⇒ Expression
private
Parse input into expression or raise.
-
.try_parse(input) ⇒ Expression?
private
Parse input into expression.
Instance Method Summary collapse
-
#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
32 33 34 35 |
# File 'lib/mutant/expression.rb', line 32 def initialize(*) super @syntax = match.to_s end |
Instance Attribute Details
#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
43 44 45 |
# File 'lib/mutant/expression.rb', line 43 def syntax @syntax end |
Class Method Details
.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
96 97 98 |
# File 'lib/mutant/expression.rb', line 96 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
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mutant/expression.rb', line 112 def self.try_parse(input) expressions = expressions(input) case expressions.length when 0 when 1 expressions.first else fail AmbigousExpressionError, "Ambigous expression: #{input.inspect}" end 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.
Return match length for expression
53 54 55 56 57 58 59 |
# File 'lib/mutant/expression.rb', line 53 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
69 70 71 |
# File 'lib/mutant/expression.rb', line 69 def prefix?(other) !match_length(other).zero? end |