lib/sequitur/dynamic_grammar.rb in sequitur-0.1.24 vs lib/sequitur/dynamic_grammar.rb in sequitur-0.1.25
- old
+ new
@@ -11,17 +11,17 @@
# Each production has a rhs that is a sequence of grammar symbols.
# Grammar symbols are categorized into
# -terminal symbols (i.e. String, Ruby Symbol,...)
# -non-terminal symbols (i.e. ProductionRef)
class DynamicGrammar
- # Link to the start production.
+ # @return [Sequitur::Production] Link to the start production.
attr_reader(:start)
- # The set of production rules of the grammar
+ # @return [Array<Sequitur::Production>] The set of production rules of the grammar
attr_reader(:productions)
- # nodoc Trace the execution of the algorithm.
+ # @return [TrueClass, FalseClass] Trace the execution of the algorithm.
attr_accessor(:trace)
# Constructor.
# Build a grammar with one empty rule as start/start rule.
def initialize
@@ -36,21 +36,22 @@
def to_string
productions.map(&:to_string).join("\n")
end
# Add a given production to the grammar.
- # @param aProduction [Production]
+ # @param aProduction [Sequitur::Production]
+ # @return [Array<Sequitur::Production>]
def add_production(aProduction)
# TODO: remove output
puts "Adding #{aProduction.object_id}" if trace
puts aProduction.to_string if trace
productions << aProduction
end
# Remove a production with given index from the grammar
- # @param anIndex [Fixnum]
- # @return [Production] the production removed from the grammar.
+ # @param anIndex [Integer]
+ # @return [Sequitur::Production] the production removed from the grammar.
def remove_production(anIndex)
puts "Before production removal #{productions[anIndex].object_id}" if trace
puts to_string if trace
prod = productions.delete_at(anIndex)
# TODO: remove output
@@ -67,21 +68,21 @@
append_symbol_to(start, aToken)
end
# Part of the 'visitee' role in the Visitor design pattern.
# A visitee is expected to accept the visit from a visitor object
- # @param aVisitor [GrammarVisitor] the visitor object
+ # @param aVisitor [Sequitur::GrammarVisitor] the visitor object
def accept(aVisitor)
aVisitor.start_visit_grammar(self)
# Let's proceed with the visit of productions
productions.each { |prod| prod.accept(aVisitor) }
aVisitor.end_visit_grammar(self)
end
# Factory method. Returns a visitor for this grammar.
- # @return [GrammarVisitor]
+ # @return [Sequitur::GrammarVisitor]
def visitor
GrammarVisitor.new(self)
end
protected