Class: Peggy::Positive

Inherits:
Element show all
Defined in:
lib/builder.rb,
lib/Copy of builder.rb

Overview

An element which tries its single child but does not advance the index if found. If not found, however, it returns NO_MATCH. Used for a positive semantic predicate.

Direct Known Subclasses

Negative

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Element

build, #report

Instance Attribute Details

#childObject

The single child



134
135
136
# File 'lib/builder.rb', line 134

def child
  @child
end

Instance Method Details

#match(parser, index) ⇒ Object

Matches the child once. If found the original index is returned. If not found NO_MATCH is returned.



141
142
143
144
145
# File 'lib/builder.rb', line 141

def match parser, index
  raise "positive element child not set" unless child
  found = child.match parser, index
  found ? index : NO_MATCH
end