Class: Sequitur::Formatter::BaseText
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- Sequitur::Formatter::BaseText
- Defined in:
- lib/sequitur/formatter/base_text.rb
Overview
A formatter class that can render a dynamic grammar in plain text.
Instance Attribute Summary
Attributes inherited from BaseFormatter
Instance Method Summary collapse
-
#after_production(_) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed.
-
#before_grammar(aGrammar) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed.
-
#before_non_terminal(aProduction) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed.
-
#before_production(aProduction) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed.
-
#before_rhs(_) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed.
-
#before_terminal(aSymbol) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed.
-
#initialize(anIO) ⇒ BaseText
constructor
Constructor.
Methods inherited from BaseFormatter
Constructor Details
#initialize(anIO) ⇒ BaseText
Constructor. is written.
18 19 20 21 |
# File 'lib/sequitur/formatter/base_text.rb', line 18 def initialize(anIO) super(anIO) @prod_lookup = {} end |
Instance Method Details
#after_production(_) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor complete the visit of a production
70 71 72 |
# File 'lib/sequitur/formatter/base_text.rb', line 70 def after_production(_) output.print ".\n" end |
#before_grammar(aGrammar) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a grammar
26 27 28 29 30 |
# File 'lib/sequitur/formatter/base_text.rb', line 26 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
Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a non-terminal (= an allusion to a production) in the rhs of a production
62 63 64 65 |
# File 'lib/sequitur/formatter/base_text.rb', line 62 def before_non_terminal(aProduction) p_name = prod_name(aProduction) output.print " #{p_name}" end |
#before_production(aProduction) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a production
36 37 38 39 |
# File 'lib/sequitur/formatter/base_text.rb', line 36 def before_production(aProduction) p_name = prod_name(aProduction) output.print p_name end |
#before_rhs(_) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit the rhs of a production
45 46 47 |
# File 'lib/sequitur/formatter/base_text.rb', line 45 def before_rhs(_) output.print ' :' end |
#before_terminal(aSymbol) ⇒ Object
Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a terminal symbol from the rhs of a production
53 54 55 |
# File 'lib/sequitur/formatter/base_text.rb', line 53 def before_terminal(aSymbol) output.print " #{aSymbol}" end |