Class: Spectre::Operators::Intersection
- Inherits:
-
Object
- Object
- Spectre::Operators::Intersection
- Includes:
- Op
- Defined in:
- lib/spectre/base/operators.rb
Overview
Matches if both Nodes it receives as parameters match from the current position. Goes to the position in the input stream returned by the Node that matched the bigger input. Intersection.new p1, p2 is equal to p1 & p2.
Instance Attribute Summary
Attributes included from Parser
Instance Method Summary collapse
Methods included from Op
Methods included from Parser
#backtrack, #create_match, from_POD, #pre_skip?, #to_p
Instance Method Details
#inspect ⇒ Object
156 157 158 |
# File 'lib/spectre/base/operators.rb', line 156 def inspect '(' + @node.left.inspect + ' & ' + @node.right.inspect + ')' end |
#scan(iter) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/spectre/base/operators.rb', line 137 def scan iter first = @node.left.parse iter fiter = iter.dup backtrack iter return nil unless first second = @node.right.parse iter siter = iter.dup backtrack iter if first and second max = [[first,fiter], [second,siter]].max_by { |x| x[0].length } iter.to max[1].pos create_match iter, max[0] else nil end end |