Class: Spectre::Operators::Xor

Inherits:
Object
  • Object
show all
Includes:
Op
Defined in:
lib/spectre/base/operators.rb

Overview

Matches if either the first Node or the second matches, but not if both match. Xor.new p1, p2 is equal to p1 ^ p2.

Instance Attribute Summary

Attributes included from Parser

#node

Instance Method Summary collapse

Methods included from Op

#pre_skip?

Methods included from Parser

#backtrack, #create_match, from_POD, #pre_skip?, #to_p

Instance Method Details

#inspectObject



218
219
220
# File 'lib/spectre/base/operators.rb', line 218

def inspect
    '(' + @node.left.inspect + ' ^ ' + @node.right.inspect + ')'
end

#scan(iter) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/spectre/base/operators.rb', line 199

def scan iter
    first = @node.left.parse iter
    fiter = iter.dup
    backtrack iter
    second = @node.right.parse iter
    siter = iter.dup
    backtrack iter

    if first and not second
        iter.to fiter.pos
        create_match iter, first
    elsif second and not first
        iter.to siter.pos
        create_match iter, second
    else
        nil
    end
end