Class: Sequitur::Formatter::BaseText

Inherits:
BaseFormatter show all
Defined in:
lib/sequitur/formatter/base_text.rb

Overview

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)

Instance Attribute Summary

Attributes inherited from BaseFormatter

#output

Instance Method Summary collapse

Methods inherited from BaseFormatter

#render

Constructor Details

#initialize(anIO) ⇒ BaseText

Constructor. [anIO]



17
18
19
20
# File 'lib/sequitur/formatter/base_text.rb', line 17

def initialize(anIO)
  super(anIO)
  @prod_lookup = {}
end

Instance Method Details

#after_production(_) ⇒ Object



49
50
51
# File 'lib/sequitur/formatter/base_text.rb', line 49

def after_production(_)
  output.print ".\n"
end

#before_grammar(aGrammar) ⇒ Object



24
25
26
27
28
# File 'lib/sequitur/formatter/base_text.rb', line 24

def before_grammar(aGrammar)
  aGrammar.productions.each_with_index do |a_prod, index|
    prod_lookup[a_prod] = index
  end
end

#before_non_terminal(aProduction) ⇒ Object



44
45
46
47
# File 'lib/sequitur/formatter/base_text.rb', line 44

def before_non_terminal(aProduction)
  p_name = prod_name(aProduction)
  output.print " #{p_name}"
end

#before_production(aProduction) ⇒ Object



30
31
32
33
# File 'lib/sequitur/formatter/base_text.rb', line 30

def before_production(aProduction)
  p_name = prod_name(aProduction)
  output.print p_name
end

#before_rhs(_) ⇒ Object



35
36
37
# File 'lib/sequitur/formatter/base_text.rb', line 35

def before_rhs(_)
  output.print ' :'
end

#before_terminal(aSymbol) ⇒ Object



39
40
41
# File 'lib/sequitur/formatter/base_text.rb', line 39

def before_terminal(aSymbol)
  output.print " #{aSymbol}"
end