lib/sequitur/formatter/base_text.rb in sequitur-0.1.00 vs lib/sequitur/formatter/base_text.rb in sequitur-0.1.01

- old
+ new

@@ -1,32 +1,27 @@ +require_relative 'base_formatter' + module Sequitur module Formatter # A formatter class that can render a dynamic grammar in plain text. # Synopsis: # some_grammar = ... # Points to a DynamicGrammar-like object # Output the result to the standard console output # formatter = Sequitur::Formatter::BaseText.new(STDOUT) # Render the grammar (through a visitor) # formatter.run(some_grammar.visitor) - class BaseText - attr(:output) + class BaseText < BaseFormatter # Constructor. # [anIO] def initialize(anIO) - @output = anIO + super(anIO) @prod_lookup = {} end public - - def render(aVisitor) - aVisitor.subscribe(self) - aVisitor.start() - aVisitor.unsubscribe(self) - end def before_grammar(aGrammar) aGrammar.productions.each_with_index do |a_prod, index| prod_lookup[a_prod] = index end @@ -61,10 +56,10 @@ return @prod_lookup end def prod_name(aProduction) prod_index = prod_lookup[aProduction] - name = (prod_index == 0) ? 'start' : "P_#{prod_index}" + name = (prod_index == 0) ? 'start' : "P#{prod_index}" return name end end # class end # module