rdtool 0.6.23
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.txt +674 -0
- data/Gemfile +9 -0
- data/HISTORY +284 -0
- data/LICENSE.txt +58 -0
- data/MANIFEST +89 -0
- data/README.html +44 -0
- data/README.ja.html +46 -0
- data/README.rd +52 -0
- data/README.rd.ja +54 -0
- data/Rakefile +29 -0
- data/TODO +15 -0
- data/VERSION +1 -0
- data/bin/rd2 +281 -0
- data/bin/rdswap.rb +207 -0
- data/doc/rd-draft.rd +479 -0
- data/doc/rd-draft.rd.ja +487 -0
- data/lib/rd/block-element.rb +114 -0
- data/lib/rd/complex-list-item.rb +65 -0
- data/lib/rd/desclist.rb +55 -0
- data/lib/rd/document-struct.rb +46 -0
- data/lib/rd/dot.rd2rc +18 -0
- data/lib/rd/element.rb +160 -0
- data/lib/rd/filter.rb +255 -0
- data/lib/rd/inline-element.rb +233 -0
- data/lib/rd/labeled-element.rb +14 -0
- data/lib/rd/list.rb +57 -0
- data/lib/rd/loose-struct.rb +11 -0
- data/lib/rd/methodlist.rb +57 -0
- data/lib/rd/output-format-visitor.rb +28 -0
- data/lib/rd/package.rb +4 -0
- data/lib/rd/parser-util.rb +14 -0
- data/lib/rd/post-install +1 -0
- data/lib/rd/rbl-file.rb +69 -0
- data/lib/rd/rbl-suite.rb +37 -0
- data/lib/rd/rd-struct.rb +86 -0
- data/lib/rd/rd2html-lib.rb +490 -0
- data/lib/rd/rd2html-opt.rb +67 -0
- data/lib/rd/rd2man-lib.rb +241 -0
- data/lib/rd/rd2rdo-lib.rb +19 -0
- data/lib/rd/rd2rmi-lib.rb +32 -0
- data/lib/rd/rdblockparser.ry +518 -0
- data/lib/rd/rdblockparser.tab.rb +1050 -0
- data/lib/rd/rdfmt.rb +15 -0
- data/lib/rd/rdinlineparser.ry +503 -0
- data/lib/rd/rdinlineparser.tab.rb +1243 -0
- data/lib/rd/rdvisitor.rb +214 -0
- data/lib/rd/reference-resolver.rb +114 -0
- data/lib/rd/search-file.rb +14 -0
- data/lib/rd/tree.rb +103 -0
- data/lib/rd/version.rb +39 -0
- data/lib/rd/visitor.rb +86 -0
- data/makerdtool.rb +75 -0
- data/setup.rb +1596 -0
- data/test.rb +33 -0
- data/test/data/includee1.html +1 -0
- data/test/data/includee2.html +1 -0
- data/test/data/includee3.nothtml +1 -0
- data/test/data/includee4.xhtml +0 -0
- data/test/data/label.rbl +2 -0
- data/test/data/label2.rbl +2 -0
- data/test/data/sub/includee2.html +1 -0
- data/test/data/sub/includee4.html +0 -0
- data/test/dummy-observer.rb +6 -0
- data/test/dummy.rb +33 -0
- data/test/temp-dir.rb +19 -0
- data/test/test-block-parser.rb +46 -0
- data/test/test-desclist-item.rb +219 -0
- data/test/test-document-element.rb +46 -0
- data/test/test-document-struct.rb +66 -0
- data/test/test-element.rb +46 -0
- data/test/test-headline.rb +80 -0
- data/test/test-inline-parser.rb +46 -0
- data/test/test-list-item.rb +54 -0
- data/test/test-list.rb +53 -0
- data/test/test-methodlist-item.rb +73 -0
- data/test/test-nonterminal-element.rb +170 -0
- data/test/test-nonterminal-inline.rb +33 -0
- data/test/test-output-format-visitor.rb +48 -0
- data/test/test-parser-util.rb +41 -0
- data/test/test-rbl-file.rb +156 -0
- data/test/test-rbl-suite.rb +43 -0
- data/test/test-rd2html-lib.rb +496 -0
- data/test/test-rdtree.rb +17 -0
- data/test/test-rdvisitor.rb +29 -0
- data/test/test-reference-resolver.rb +202 -0
- data/test/test-reference.rb +132 -0
- data/test/test-search-file.rb +22 -0
- data/test/test-terminal-inline.rb +41 -0
- data/test/test-textblock.rb +44 -0
- data/test/test-tree.rb +82 -0
- data/test/test-version.rb +57 -0
- data/test/test-visitor.rb +230 -0
- data/utils/rd-mode.el +425 -0
- metadata +203 -0
data/README.ja.html
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
6
|
+
<head>
|
7
|
+
<title>README.ja</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1><a name="label-0" id="label-0">RDtool 0.6.23</a></h1><!-- RDLabel: "RDtool 0.6.23" -->
|
11
|
+
<h2><a name="label-1" id="label-1">RDってなに?</a></h2><!-- RDLabel: "RDってなに?" -->
|
12
|
+
<p>RDはRubyにおけるPOD(Plain Old Documentation)のようなものです。
|
13
|
+
RDtoolはRDのフォーマッタであり、RDをHTMLなどに変換できます。</p>
|
14
|
+
<h2><a name="label-2" id="label-2">何が変わった?</a></h2><!-- RDLabel: "何が変わった?" -->
|
15
|
+
<p>HISTORYを見てください。</p>
|
16
|
+
<h2><a name="label-3" id="label-3">インストールの方法</a></h2><!-- RDLabel: "インストールの方法" -->
|
17
|
+
<ol>
|
18
|
+
<li>必要なら、<kbd>su</kbd></li>
|
19
|
+
<li><kbd>ruby setup.rb</kbd></li>
|
20
|
+
<li>utils/rd-mode.elを使いたいならば
|
21
|
+
それらを<em>手で</em>インストールします。</li>
|
22
|
+
</ol>
|
23
|
+
<h2><a name="label-4" id="label-4">どうやって使うか。</a></h2><!-- RDLabel: "どうやって使うか。" -->
|
24
|
+
<p>基本的には、こんな感じ。</p>
|
25
|
+
<pre>% rd2 rdfile.rd > outputfile</pre>
|
26
|
+
<p>フォーマットライブラリを指定したい時は、こう。</p>
|
27
|
+
<pre>% rd2 -r library rdfile.rd > outputfile</pre>
|
28
|
+
<p><kbd> rd2 --help </kbd>でオプションの詳細がでます。</p>
|
29
|
+
<p>フォーマットライブラリ依存のオプションは先にフォーマットライブラリの
|
30
|
+
指定をしてから<kbd>--help</kbd>。例えば、</p>
|
31
|
+
<pre>% rd2 -r rd/rd2html-lib.rb --help</pre>
|
32
|
+
<p>rd2はホームディレクトリにある".rd2rc"というファイルを読み込みます。
|
33
|
+
これはRubyスクリプトです。</p>
|
34
|
+
<h2><a name="label-5" id="label-5">RDの書き方</a></h2><!-- RDLabel: "RDの書き方" -->
|
35
|
+
<p>doc/rd-draft.rdを読んでください。</p>
|
36
|
+
<h2><a name="label-6" id="label-6">バグ報告</a></h2><!-- RDLabel: "バグ報告" -->
|
37
|
+
<p>バグを見付けた時は、次のアドレスまでメールしてください。
|
38
|
+
<a href="mailto:uwabami@gfd-dennou.org"><URL:mailto:uwabami@gfd-dennou.org></a></p>
|
39
|
+
<h2><a name="label-7" id="label-7">ライセンス</a></h2><!-- RDLabel: "ライセンス" -->
|
40
|
+
<p>RDtoolはRuby's LicenseかGPLの下で使用/配布/改造してください。
|
41
|
+
RDtoolのパッケージにはTosh以外の人が著作権を持つファイルが含まれています。
|
42
|
+
それらのファイルについての配布条件はファイル自体に書かれたライセンスの下で
|
43
|
+
行ってください。</p>
|
44
|
+
|
45
|
+
</body>
|
46
|
+
</html>
|
data/README.rd
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- mode: rd; coding: utf-8-unix; indent-tabs-mode: nil -*-
|
2
|
+
=begin
|
3
|
+
= RDtool 0.6.23
|
4
|
+
== What is RDtool
|
5
|
+
|
6
|
+
RD is Ruby's POD. RDtool is formatter for RD.
|
7
|
+
|
8
|
+
== What is Changed
|
9
|
+
|
10
|
+
See HISTORY.
|
11
|
+
|
12
|
+
== How to Install
|
13
|
+
|
14
|
+
(1)((%su%)) if you install into public directories.
|
15
|
+
(2)((%ruby setup.rb%))
|
16
|
+
(3)If you want to use , utils/rd-mode.el, install it ((*by hand*)).
|
17
|
+
|
18
|
+
== How to use
|
19
|
+
|
20
|
+
Simply,
|
21
|
+
% rd2 rdfile.rd > outputfile
|
22
|
+
|
23
|
+
If you want to indicate format-library, do
|
24
|
+
% rd2 -r library rdfile.rd > outputfile
|
25
|
+
|
26
|
+
Use ((% rd2 --help %)) for more options.
|
27
|
+
|
28
|
+
For options depend on format-library, enter ((%--help%)) after
|
29
|
+
the indication of format-library. For example,
|
30
|
+
|
31
|
+
% rd2 -r rd/rd2html-lib.rb --help
|
32
|
+
|
33
|
+
rd2 load "${HOME}/.rd2rc" when it runs.
|
34
|
+
|
35
|
+
== How to write RD?
|
36
|
+
|
37
|
+
Please read doc/rd-draft.rd.
|
38
|
+
|
39
|
+
== About bug report
|
40
|
+
|
41
|
+
If you find a bug in RDtool, please E-mail me
|
42
|
+
((<URL:mailto:uwabami@gfd-dennou.org>)).
|
43
|
+
|
44
|
+
== License
|
45
|
+
|
46
|
+
You can use/re-distribute/change RDtool under Ruby's License or GPL, see
|
47
|
+
LICNESE.txt and COPYING.txt. This distribution of RDtool include files
|
48
|
+
that are copyrighted by somebody else, and these files can be
|
49
|
+
re-distributed under those own license. These files include the
|
50
|
+
condition of those licenses in themselves.
|
51
|
+
|
52
|
+
=end
|
data/README.rd.ja
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- mode: rd; coding: utf-8-unix; indent-tabs-mode: nil -*-
|
2
|
+
=begin
|
3
|
+
= RDtool 0.6.23
|
4
|
+
== RDってなに?
|
5
|
+
|
6
|
+
RDはRubyにおけるPOD(Plain Old Documentation)のようなものです。
|
7
|
+
RDtoolはRDのフォーマッタであり、RDをHTMLなどに変換できます。
|
8
|
+
|
9
|
+
== 何が変わった?
|
10
|
+
|
11
|
+
HISTORYを見てください。
|
12
|
+
|
13
|
+
== インストールの方法
|
14
|
+
|
15
|
+
(1)必要なら、((%su%))
|
16
|
+
(2)((%ruby setup.rb%))
|
17
|
+
(3)utils/rd-mode.elを使いたいならば
|
18
|
+
それらを((*手で*))インストールします。
|
19
|
+
|
20
|
+
== どうやって使うか。
|
21
|
+
|
22
|
+
基本的には、こんな感じ。
|
23
|
+
% rd2 rdfile.rd > outputfile
|
24
|
+
|
25
|
+
フォーマットライブラリを指定したい時は、こう。
|
26
|
+
% rd2 -r library rdfile.rd > outputfile
|
27
|
+
|
28
|
+
((% rd2 --help %))でオプションの詳細がでます。
|
29
|
+
|
30
|
+
フォーマットライブラリ依存のオプションは先にフォーマットライブラリの
|
31
|
+
指定をしてから((%--help%))。例えば、
|
32
|
+
|
33
|
+
% rd2 -r rd/rd2html-lib.rb --help
|
34
|
+
|
35
|
+
rd2はホームディレクトリにある".rd2rc"というファイルを読み込みます。
|
36
|
+
これはRubyスクリプトです。
|
37
|
+
|
38
|
+
== RDの書き方
|
39
|
+
|
40
|
+
doc/rd-draft.rdを読んでください。
|
41
|
+
|
42
|
+
== バグ報告
|
43
|
+
|
44
|
+
バグを見付けた時は、次のアドレスまでメールしてください。
|
45
|
+
((<URL:mailto:uwabami@gfd-dennou.org>))
|
46
|
+
|
47
|
+
== ライセンス
|
48
|
+
|
49
|
+
RDtoolはRuby's LicenseかGPLの下で使用/配布/改造してください。
|
50
|
+
RDtoolのパッケージにはTosh以外の人が著作権を持つファイルが含まれています。
|
51
|
+
それらのファイルについての配布条件はファイル自体に書かれたライセンスの下で
|
52
|
+
行ってください。
|
53
|
+
|
54
|
+
=end
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
9
|
+
gem.name = "rdtool"
|
10
|
+
gem.homepage = "http://github.com/uwabami/rdtool"
|
11
|
+
gem.license = ['GPL', 'Ruby']
|
12
|
+
gem.summary = %Q{RDtool is formatter for RD.}
|
13
|
+
gem.description = %Q{RD is multipurpose documentation format created for documentating Ruby and output of Ruby world. You can embed RD into Ruby script. And RD have neat syntax which help you to read document in Ruby script. On the other hand, RD have a feature for class reference.}
|
14
|
+
gem.email = "uwabami@gfd-dennou.org"
|
15
|
+
gem.authors = ["Youhei SASAKI"]
|
16
|
+
# dependencies defined in Gemfile
|
17
|
+
end
|
18
|
+
Jeweler::RubygemsDotOrgTasks.new
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib'
|
23
|
+
test.libs << 'test'
|
24
|
+
test.pattern = 'test.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => :test
|
29
|
+
|
data/TODO
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- mode: rd; coding: utf-8-unix; indent-tabs-mode: nil -*-
|
2
|
+
= TODO
|
3
|
+
|
4
|
+
== Moonwolf さんから指摘された事
|
5
|
+
|
6
|
+
* Ruby1,9での動作確認(全機能)+encoding周り
|
7
|
+
* gem化した際に、通常のsetup.rbによるインストール方法も残すか
|
8
|
+
* 原作者のToshさんの認識していたバグが直っているかの確認(できるの?)
|
9
|
+
((<URL:http://pub.cozmixng.org/~the-rwiki/rw-cgi.rb?cmd=view;name=RDtool+Bug+List>))
|
10
|
+
|
11
|
+
== 佐々木が気になっている事/やりたいこと
|
12
|
+
|
13
|
+
* COPYRIGHT の表記. きちんとまとめておきたい|おくべき.
|
14
|
+
* makerdtool.rb などを Rake のタスクに落としこむ
|
15
|
+
* Windows での, テストしておくべき Ruby 環境ってドレなの?
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.6.23
|
data/bin/rd2
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
#! /usr/bin/ruby1.8 -Kn
|
2
|
+
# -*- coding: ASCII-8BIT -*-
|
3
|
+
=begin
|
4
|
+
= NAME
|
5
|
+
rd2 - converter from RD to other mark-up language.
|
6
|
+
= SYNOPSIS
|
7
|
+
rd2 [-r <visitor>] [options] <file>
|
8
|
+
|
9
|
+
= DESCRIPTION
|
10
|
+
rd2 inputs from ((|<file>|)) and outputs into (({STDOUT})). you can
|
11
|
+
choose ((|<visitor>|)) to select output format. For example, use
|
12
|
+
"rd/rd2html-lib.rb" to translate it into HTML, and "rd/rd2man-lib.rb"
|
13
|
+
to tranlate it into roff with man macros.
|
14
|
+
|
15
|
+
= OPTIONS
|
16
|
+
please read output of
|
17
|
+
% rd2 --help
|
18
|
+
and
|
19
|
+
% rd2 -r rd/rd2html-lib.rb --help
|
20
|
+
|
21
|
+
= FILES
|
22
|
+
* ~/.rd2rc - User configration file.
|
23
|
+
|
24
|
+
= SEE ALSO
|
25
|
+
ruby(1)
|
26
|
+
=end
|
27
|
+
|
28
|
+
require "kconv"
|
29
|
+
require "optparse"
|
30
|
+
require "rd/rdfmt"
|
31
|
+
require "rd/visitor"
|
32
|
+
require "rd/version"
|
33
|
+
|
34
|
+
module Kconv
|
35
|
+
NAME2CONST = {
|
36
|
+
"iso-2022-jp" => Kconv::JIS,
|
37
|
+
"euc-jp" => Kconv::EUC,
|
38
|
+
"shift_jis" => Kconv::SJIS,
|
39
|
+
}
|
40
|
+
NAME_ALIAS = {
|
41
|
+
'jis' => 'iso-2022-jp',
|
42
|
+
'euc' => 'euc-jp',
|
43
|
+
'sjis' => 'shift_jis',
|
44
|
+
'shift-jis' => 'shift_jis',
|
45
|
+
}
|
46
|
+
if defined?(Kconv::UTF8)
|
47
|
+
NAME2CONST['utf-8'] = Kconv::UTF8
|
48
|
+
NAME_ALIAS['utf8'] = 'utf-8'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
include RD
|
53
|
+
|
54
|
+
SYSTEM_NAME = "RDtool -- rd2"
|
55
|
+
SYSTEM_VERSION = "$Version: 0.6.23$" #"
|
56
|
+
RD2_VERSION = Version.new_from_version_string(SYSTEM_NAME, SYSTEM_VERSION)
|
57
|
+
|
58
|
+
# global vars
|
59
|
+
$Visitor_Class = nil
|
60
|
+
$Visitor = nil
|
61
|
+
$RD2_Sub_OptionParser = nil
|
62
|
+
|
63
|
+
# local vars
|
64
|
+
include_path = []
|
65
|
+
with_part = []
|
66
|
+
output_file = nil
|
67
|
+
output_index = nil
|
68
|
+
out_code = nil
|
69
|
+
from_rdo = nil
|
70
|
+
|
71
|
+
# user option
|
72
|
+
$DEFAULT_FORMAT_LIB = "rd/rd2html-lib"
|
73
|
+
$RC = {}
|
74
|
+
$RC["filter"] = Hash.new(RD::INCLUDE_FILTER)
|
75
|
+
begin
|
76
|
+
if test(?r, File.expand_path("~/.rd2rc"))
|
77
|
+
load "~/.rd2rc"
|
78
|
+
# STDERR << "#{$0}: loading ~/.rd2rc\n"
|
79
|
+
else
|
80
|
+
load "rd/dot.rd2rc"
|
81
|
+
# STDERR << "#{$0}: loading rd/dot.rd2rc\n"
|
82
|
+
end
|
83
|
+
rescue
|
84
|
+
load "rd/dot.rd2rc"
|
85
|
+
end
|
86
|
+
|
87
|
+
# initialize OptionParser
|
88
|
+
ARGV.options do |q|
|
89
|
+
q.banner = "Usage: #{$0} [options] rd-file > output\n"
|
90
|
+
q.on_head("global options:")
|
91
|
+
|
92
|
+
q.on("-rLIB", "--require=LIB",
|
93
|
+
String,
|
94
|
+
"choose format library.") do |i|
|
95
|
+
# require LIB
|
96
|
+
require i
|
97
|
+
if $Visitor_Class && !$Visitor
|
98
|
+
$Visitor = $Visitor_Class.new()
|
99
|
+
if $RD2_Sub_OptionParser
|
100
|
+
require $RD2_Sub_OptionParser
|
101
|
+
$RD2_Sub_OptionParser = nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
q.on("-oNAME",
|
107
|
+
String,
|
108
|
+
"indicate base name of output file") do |i|
|
109
|
+
output_file = i
|
110
|
+
end
|
111
|
+
|
112
|
+
q.on("--out-code=KCODE",
|
113
|
+
Kconv::NAME2CONST.keys, Kconv::NAME_ALIAS,
|
114
|
+
"character encoding of output.(jis|euc|sjis|utf8)") do |i|
|
115
|
+
out_code = i
|
116
|
+
end
|
117
|
+
|
118
|
+
q.on("--output-index",
|
119
|
+
"output method index file (*.rmi)") do |i|
|
120
|
+
output_index = true
|
121
|
+
end
|
122
|
+
|
123
|
+
q.on("-IPATH", "--include-path=PATH",
|
124
|
+
String,
|
125
|
+
"add PATH to list of include path") do |i|
|
126
|
+
# add to include path
|
127
|
+
include_path.unshift(i)
|
128
|
+
end
|
129
|
+
|
130
|
+
# accept "PART:FILTER" and "PART"
|
131
|
+
class PART ; end
|
132
|
+
q.accept(PART, /(\w+)(?:\s*:\s*(\w+))?/) {|s, p, f| [s, p, f] }
|
133
|
+
q.on("--with-part=PART",
|
134
|
+
PART,
|
135
|
+
"include PART with Filter") do |src, part, filter|
|
136
|
+
with_part.push([part, filter || part])
|
137
|
+
unless include_path.index(RD::RDTree.tmp_dir)
|
138
|
+
include_path.push(RD::RDTree.tmp_dir)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
q.on("--from-rdo",
|
143
|
+
"load from *.rdo instead of *.rd") do
|
144
|
+
from_rdo = true
|
145
|
+
end
|
146
|
+
|
147
|
+
q.on("--version",
|
148
|
+
"print versions.") do
|
149
|
+
STDERR.puts RD2_VERSION
|
150
|
+
STDERR.puts Tree::version
|
151
|
+
STDERR.puts Visitor::version
|
152
|
+
STDERR.puts $Visitor_Class.version if $Visitor_Class
|
153
|
+
exit(0)
|
154
|
+
end
|
155
|
+
|
156
|
+
q.on_tail("--help",
|
157
|
+
"print this message") do
|
158
|
+
STDERR.print(q.to_s)
|
159
|
+
exit(0)
|
160
|
+
end
|
161
|
+
end # OptionParser.new
|
162
|
+
|
163
|
+
# require format lib implicitly
|
164
|
+
if /rd2.+/ =~ File.basename($0, ".*").downcase
|
165
|
+
visitor_lib = "rd/" + $& + "-lib.rb"
|
166
|
+
require visitor_lib
|
167
|
+
require $RD2_Sub_OptionParser if $RD2_Sub_OptionParser
|
168
|
+
# make visitor
|
169
|
+
$Visitor = $Visitor_Class.new()
|
170
|
+
end
|
171
|
+
|
172
|
+
begin
|
173
|
+
ARGV.parse!
|
174
|
+
rescue
|
175
|
+
STDERR.print("Error: " + $!.inspect + "\n")
|
176
|
+
STDERR.print(ARGV.options.to_s)
|
177
|
+
exit(1)
|
178
|
+
end
|
179
|
+
|
180
|
+
unless $Visitor_Class
|
181
|
+
require $DEFAULT_FORMAT_LIB
|
182
|
+
$Visitor = $Visitor_Class.new
|
183
|
+
end
|
184
|
+
|
185
|
+
# make tree (but not parsed yet)
|
186
|
+
if from_rdo
|
187
|
+
rdos = []
|
188
|
+
ARGV.each do |path|
|
189
|
+
rdos.push(File.open(path))
|
190
|
+
dirname = File.dirname(path)
|
191
|
+
include_path.push(dirname, dirname + "/include")
|
192
|
+
end
|
193
|
+
tree = RDTree.new_from_rdo(*rdos)
|
194
|
+
tree.include_path = include_path
|
195
|
+
else
|
196
|
+
# input from ARGF
|
197
|
+
src = readlines
|
198
|
+
if src.find{|i| /\S/ === i } and !src.find{|i| /^=begin\b/ === i }
|
199
|
+
src.unshift("=begin\n").push("=end\n")
|
200
|
+
end
|
201
|
+
|
202
|
+
# set Include_Path
|
203
|
+
if ARGF.filename
|
204
|
+
dir = File.dirname(ARGF.filename)
|
205
|
+
else
|
206
|
+
dir = "."
|
207
|
+
end
|
208
|
+
include_path.push(dir)
|
209
|
+
include_path.push(dir + "/include")
|
210
|
+
|
211
|
+
tree = RDTree.new(src, include_path, nil)
|
212
|
+
|
213
|
+
# filter set tree.filter
|
214
|
+
with_part.each do |i|
|
215
|
+
tree.filter[i[0]] = $RC["filter"][i[1]]
|
216
|
+
end
|
217
|
+
|
218
|
+
# parse
|
219
|
+
begin
|
220
|
+
tree.parse
|
221
|
+
rescue Racc::ParseError
|
222
|
+
STDERR.puts($!.message)
|
223
|
+
exit(10)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# filter: set visitor.include_suffix
|
228
|
+
with_part.each do |i|
|
229
|
+
$Visitor.include_suffix.push(i[0])
|
230
|
+
end
|
231
|
+
|
232
|
+
# file base name setup
|
233
|
+
$Visitor.filename = output_file if output_file
|
234
|
+
|
235
|
+
# character encoding
|
236
|
+
if out_code
|
237
|
+
begin
|
238
|
+
$Visitor.charcode = out_code
|
239
|
+
$Visitor.lang = "ja"
|
240
|
+
rescue NameError
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# output
|
245
|
+
out = $Visitor.visit(tree)
|
246
|
+
|
247
|
+
# character encoding convert
|
248
|
+
out = Kconv.kconv(out, Kconv::NAME2CONST[out_code], Kconv::AUTO) if out_code
|
249
|
+
|
250
|
+
if output_file
|
251
|
+
filename = output_file + "." + $Visitor.class::OUTPUT_SUFFIX
|
252
|
+
file = open(filename, "w")
|
253
|
+
file.print(out)
|
254
|
+
file.close
|
255
|
+
STDERR.print("#{$0}: output to #{filename}...\n")
|
256
|
+
else
|
257
|
+
print(out)
|
258
|
+
end
|
259
|
+
|
260
|
+
# RMI
|
261
|
+
if output_index
|
262
|
+
if output_file
|
263
|
+
require "rd/rd2rmi-lib"
|
264
|
+
rmivisitor = RD2RMIVisitor.new
|
265
|
+
rmivisitor.filename = output_file
|
266
|
+
rmi = rmivisitor.visit(tree)
|
267
|
+
filename = output_file + ".rmi"
|
268
|
+
file = open(filename, "w")
|
269
|
+
file.print(rmi)
|
270
|
+
file.close
|
271
|
+
STDERR.print("#{$0}: output to #{filename}...\n")
|
272
|
+
else
|
273
|
+
raise %Q[Error: option "--output-index" must be used with option "-oNAME"]
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
# filter: remove tmp file
|
279
|
+
Dir.glob("#{RD::RDTree.tmp_dir}/rdtmp.#{$$}.*.*").each do |i|
|
280
|
+
File.delete(i)
|
281
|
+
end
|