Class: Juli::Absyn::Visitor

Inherits:
Object
  • Object
show all
Defined in:
lib/juli/absyn.rb

Overview

Abstract VISITOR-pattern around Absyn tree.

How to add new generator

Document generator, which juli(1) command says, points to ‘visitor’ internally because it is VISITOR-pattern. After adding new visitor, for example PDF-generator, it can be used by ‘juli -g pdf’ (let me assume the file name is pdf.rb). Follow the steps below to add new visitor:

  1. create LIB/juli/visitor/pdf.rb. Probably, it is easy to copy from another visitor file (e.g. html.rb) as the skelton. Where, LIB is ‘lib/’ directory in package environment, or one of $LOAD_PATH in installed environment.

  2. implement the pdf.rb. It’s the most important task, of course…

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Visitor

Visitor object is initialized when juli(1) gen command is executed. In other words, it is NOT initialized for each input text file. Some global initialization can be done here.

Take care that this is executed every juli(1) execution.



166
167
168
# File 'lib/juli/absyn.rb', line 166

def initialize(opts = {})
  @opts = opts.dup
end

Instance Method Details

#run_bulkObject

‘run’ bulk-mode (when no files are specified at juli(1) command line). Derived class should implement this.



172
# File 'lib/juli/absyn.rb', line 172

def run_bulk; end

#run_file(in_file, root) ⇒ Object

run for a file and its node-tree. Here is just sample implementation. Derived class can re-implement this.

INPUTS

in_file

input filename

root

Absyn tree root



181
182
183
# File 'lib/juli/absyn.rb', line 181

def run_file(in_file, root)
  root.accept(self)
end

#visit_array(n) ⇒ Object



193
194
195
196
197
# File 'lib/juli/absyn.rb', line 193

def visit_array(n)
  for node in n.array do
    node.accept(self)
  end
end

#visit_chapter(n) ⇒ Object



198
# File 'lib/juli/absyn.rb', line 198

def visit_chapter(n); end

#visit_compact_dictionary_list(n) ⇒ Object



201
# File 'lib/juli/absyn.rb', line 201

def visit_compact_dictionary_list(n); end

#visit_compact_dictionary_list_item(n) ⇒ Object



202
# File 'lib/juli/absyn.rb', line 202

def visit_compact_dictionary_list_item(n); end

#visit_dictionary_list(n) ⇒ Object



203
# File 'lib/juli/absyn.rb', line 203

def visit_dictionary_list(n); end

#visit_dictionary_list_item(n) ⇒ Object



204
# File 'lib/juli/absyn.rb', line 204

def visit_dictionary_list_item(n); end

#visit_node(n) ⇒ Object

Methods for each Absyn node. Derived class should implement these.

INPUTS

n

Absyn node



190
# File 'lib/juli/absyn.rb', line 190

def visit_node(n); end

#visit_ordered_list(n) ⇒ Object



199
# File 'lib/juli/absyn.rb', line 199

def visit_ordered_list(n); end

#visit_str(n) ⇒ Object



191
# File 'lib/juli/absyn.rb', line 191

def visit_str(n); end

#visit_unordered_list(n) ⇒ Object



200
# File 'lib/juli/absyn.rb', line 200

def visit_unordered_list(n); end

#visit_verbatim(n) ⇒ Object



192
# File 'lib/juli/absyn.rb', line 192

def visit_verbatim(n); end