Class: Peggy::Production
- 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
-
#child ⇒ Object
The production definition.
Attributes inherited from Reference
Instance Method Summary collapse
-
#initialize(name = nil, child = nil) ⇒ Production
constructor
Init the name and child.
-
#match(parser, index) ⇒ Object
Match the production one time.
-
#to_s ⇒ Object
Convert element to String.
Methods included from OneChild
Methods inherited from Element
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
#child ⇒ Object
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_s ⇒ Object
Convert element to String.
279 280 281 |
# File 'lib/parse/builder.rb', line 279 def to_s "#{name}: #{child}" end |