Module: Dendroid::GrmAnalysis::ProductionItems
- Defined in:
- lib/dendroid/grm_analysis/production_items.rb
Overview
Mix-in module for extending the Dendroid::Syntax::Production class with dotted items manipulation methods and an attribute named ‘items`.
Instance Method Summary collapse
-
#build_items ⇒ Array<GrmAnalysis::DottedItem>
Build the dotted items for this production and assign them to the ‘items` attributes.
-
#items ⇒ Array<GrmAnalysis::DottedItem>
Read accessor for the ‘items` attribute.
-
#next_item(anItem) ⇒ GrmAnalysis::DottedItem|NilClass
Return the next item given the provided item.
-
#predicted_items ⇒ Array<GrmAnalysis::DottedItem>
Return the predicted item (i.e. the dotted item with the dot at start) for this production.
-
#reduce_items ⇒ Array<GrmAnalysis::DottedItem>
Return the reduce item (i.e. the dotted item with the dot at end) for this production.
Instance Method Details
#build_items ⇒ Array<GrmAnalysis::DottedItem>
Build the dotted items for this production and assign them to the ‘items` attributes
13 14 15 16 17 18 19 20 21 |
# File 'lib/dendroid/grm_analysis/production_items.rb', line 13 def build_items @items = if empty? [DottedItem.new(self, 0)] else (0..body.size).reduce([]) do |result, pos| result << GrmAnalysis::DottedItem.new(self, pos) end end end |
#items ⇒ Array<GrmAnalysis::DottedItem>
Read accessor for the ‘items` attribute. Return the dotted items for this production
26 27 28 |
# File 'lib/dendroid/grm_analysis/production_items.rb', line 26 def items @items end |
#next_item(anItem) ⇒ GrmAnalysis::DottedItem|NilClass
Return the next item given the provided item. In other words, advance the dot by one position.
48 49 50 51 52 |
# File 'lib/dendroid/grm_analysis/production_items.rb', line 48 def next_item(anItem) return nil if anItem == @items.last @items[anItem.position + 1] end |
#predicted_items ⇒ Array<GrmAnalysis::DottedItem>
Return the predicted item (i.e. the dotted item with the dot at start) for this production.
33 34 35 |
# File 'lib/dendroid/grm_analysis/production_items.rb', line 33 def predicted_items [@items.first] end |
#reduce_items ⇒ Array<GrmAnalysis::DottedItem>
Return the reduce item (i.e. the dotted item with the dot at end) for this production.
40 41 42 |
# File 'lib/dendroid/grm_analysis/production_items.rb', line 40 def reduce_items [@items.last] end |