Class: Peggy::Production

Inherits:
Reference show all
Includes:
OneChild
Defined in:
lib/parse/builder.rb

Overview

Matcher of a grammar production. The one and only child defines the production.

Instance Attribute Summary collapse

Attributes inherited from Reference

#name

Instance Method Summary collapse

Methods included from OneChild

#wrap

Methods inherited from Element

build, #report

Constructor Details

#initialize(name = nil, child = nil) ⇒ Production

Init the name and child.



262
263
264
265
# File 'lib/parse/builder.rb', line 262

def initialize name=nil, child=nil
  super name
  @child = child
end

Instance Attribute Details

#childObject

The production definition.



259
260
261
# File 'lib/parse/builder.rb', line 259

def child
  @child
end

Instance Method Details

#match(parser, index) ⇒ Object

Match the production one time. If it matches the end index is returned. If not, NO_MATCH is returned.



272
273
274
275
276
# File 'lib/parse/builder.rb', line 272

def match parser, index
  raise "production name not set" unless name
  raise "production child not set" unless child
  report @child.match(parser, index)
end

#to_sObject

Convert element to String.



279
280
281
# File 'lib/parse/builder.rb', line 279

def to_s
  "#{name}: #{child}"
end