Class: Spectre::Operators::Optional

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

Overview

Matches the given Node 0 or 1 times. Optional.new p is equal to -p.

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



314
315
316
# File 'lib/spectre/base/operators.rb', line 314

def inspect
    '(-' + @node.left.inspect + ')'
end

#scan(iter) ⇒ Object



304
305
306
307
308
309
310
311
312
# File 'lib/spectre/base/operators.rb', line 304

def scan iter
    ret = @node.left.parse iter
    if ret
        create_match iter, ret
    else
        backtrack iter
        create_match iter, iter.empty
    end
end