Class: Resyma::Core::PTNodeMatcher
- Inherits:
-
Object
- Object
- Resyma::Core::PTNodeMatcher
- Includes:
- Matchable
- Defined in:
- lib/resyma/core/algorithm/matcher.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(type, value = nil) ⇒ PTNodeMatcher
constructor
Create a instance of parse tree node matcher.
-
#match_with_value?(parsetree) ⇒ true, false
Whether the matcher matches with the parse tree.
Constructor Details
#initialize(type, value = nil) ⇒ PTNodeMatcher
Create a instance of parse tree node matcher
15 16 17 18 |
# File 'lib/resyma/core/algorithm/matcher.rb', line 15 def initialize(type, value = nil) @type = type @value = value end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
20 21 22 |
# File 'lib/resyma/core/algorithm/matcher.rb', line 20 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
20 21 22 |
# File 'lib/resyma/core/algorithm/matcher.rb', line 20 def value @value end |
Instance Method Details
#==(other) ⇒ Object
22 23 24 25 26 |
# File 'lib/resyma/core/algorithm/matcher.rb', line 22 def ==(other) other.is_a?(PTNodeMatcher) && other.type == @type && other.value == @value end |
#match_with_value?(parsetree) ⇒ true, false
Whether the matcher matches with the parse tree
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/resyma/core/algorithm/matcher.rb', line 35 def match_with_value?(parsetree) if parsetree.is_a?(Resyma::Core::ParseTree) parsetree.symbol == @type && (@value.nil? || (parsetree.leaf? && parsetree.children[0] == @value)) elsif parsetree.is_a?(PTNodeMatcher) self == parsetree else false end end |