rdtool 0.6.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/COPYING.txt +674 -0
  2. data/Gemfile +9 -0
  3. data/HISTORY +284 -0
  4. data/LICENSE.txt +58 -0
  5. data/MANIFEST +89 -0
  6. data/README.html +44 -0
  7. data/README.ja.html +46 -0
  8. data/README.rd +52 -0
  9. data/README.rd.ja +54 -0
  10. data/Rakefile +29 -0
  11. data/TODO +15 -0
  12. data/VERSION +1 -0
  13. data/bin/rd2 +281 -0
  14. data/bin/rdswap.rb +207 -0
  15. data/doc/rd-draft.rd +479 -0
  16. data/doc/rd-draft.rd.ja +487 -0
  17. data/lib/rd/block-element.rb +114 -0
  18. data/lib/rd/complex-list-item.rb +65 -0
  19. data/lib/rd/desclist.rb +55 -0
  20. data/lib/rd/document-struct.rb +46 -0
  21. data/lib/rd/dot.rd2rc +18 -0
  22. data/lib/rd/element.rb +160 -0
  23. data/lib/rd/filter.rb +255 -0
  24. data/lib/rd/inline-element.rb +233 -0
  25. data/lib/rd/labeled-element.rb +14 -0
  26. data/lib/rd/list.rb +57 -0
  27. data/lib/rd/loose-struct.rb +11 -0
  28. data/lib/rd/methodlist.rb +57 -0
  29. data/lib/rd/output-format-visitor.rb +28 -0
  30. data/lib/rd/package.rb +4 -0
  31. data/lib/rd/parser-util.rb +14 -0
  32. data/lib/rd/post-install +1 -0
  33. data/lib/rd/rbl-file.rb +69 -0
  34. data/lib/rd/rbl-suite.rb +37 -0
  35. data/lib/rd/rd-struct.rb +86 -0
  36. data/lib/rd/rd2html-lib.rb +490 -0
  37. data/lib/rd/rd2html-opt.rb +67 -0
  38. data/lib/rd/rd2man-lib.rb +241 -0
  39. data/lib/rd/rd2rdo-lib.rb +19 -0
  40. data/lib/rd/rd2rmi-lib.rb +32 -0
  41. data/lib/rd/rdblockparser.ry +518 -0
  42. data/lib/rd/rdblockparser.tab.rb +1050 -0
  43. data/lib/rd/rdfmt.rb +15 -0
  44. data/lib/rd/rdinlineparser.ry +503 -0
  45. data/lib/rd/rdinlineparser.tab.rb +1243 -0
  46. data/lib/rd/rdvisitor.rb +214 -0
  47. data/lib/rd/reference-resolver.rb +114 -0
  48. data/lib/rd/search-file.rb +14 -0
  49. data/lib/rd/tree.rb +103 -0
  50. data/lib/rd/version.rb +39 -0
  51. data/lib/rd/visitor.rb +86 -0
  52. data/makerdtool.rb +75 -0
  53. data/setup.rb +1596 -0
  54. data/test.rb +33 -0
  55. data/test/data/includee1.html +1 -0
  56. data/test/data/includee2.html +1 -0
  57. data/test/data/includee3.nothtml +1 -0
  58. data/test/data/includee4.xhtml +0 -0
  59. data/test/data/label.rbl +2 -0
  60. data/test/data/label2.rbl +2 -0
  61. data/test/data/sub/includee2.html +1 -0
  62. data/test/data/sub/includee4.html +0 -0
  63. data/test/dummy-observer.rb +6 -0
  64. data/test/dummy.rb +33 -0
  65. data/test/temp-dir.rb +19 -0
  66. data/test/test-block-parser.rb +46 -0
  67. data/test/test-desclist-item.rb +219 -0
  68. data/test/test-document-element.rb +46 -0
  69. data/test/test-document-struct.rb +66 -0
  70. data/test/test-element.rb +46 -0
  71. data/test/test-headline.rb +80 -0
  72. data/test/test-inline-parser.rb +46 -0
  73. data/test/test-list-item.rb +54 -0
  74. data/test/test-list.rb +53 -0
  75. data/test/test-methodlist-item.rb +73 -0
  76. data/test/test-nonterminal-element.rb +170 -0
  77. data/test/test-nonterminal-inline.rb +33 -0
  78. data/test/test-output-format-visitor.rb +48 -0
  79. data/test/test-parser-util.rb +41 -0
  80. data/test/test-rbl-file.rb +156 -0
  81. data/test/test-rbl-suite.rb +43 -0
  82. data/test/test-rd2html-lib.rb +496 -0
  83. data/test/test-rdtree.rb +17 -0
  84. data/test/test-rdvisitor.rb +29 -0
  85. data/test/test-reference-resolver.rb +202 -0
  86. data/test/test-reference.rb +132 -0
  87. data/test/test-search-file.rb +22 -0
  88. data/test/test-terminal-inline.rb +41 -0
  89. data/test/test-textblock.rb +44 -0
  90. data/test/test-tree.rb +82 -0
  91. data/test/test-version.rb +57 -0
  92. data/test/test-visitor.rb +230 -0
  93. data/utils/rd-mode.el +425 -0
  94. metadata +203 -0
data/lib/rd/filter.rb ADDED
@@ -0,0 +1,255 @@
1
+ =begin
2
+ = filter.rb
3
+ Definition of Filter structure.
4
+ =end
5
+
6
+ module RD
7
+ class Filter
8
+ attr_accessor :mode
9
+
10
+ def initialize(mode = :target, &block)
11
+ @mode = mode
12
+ @block = block
13
+ end
14
+
15
+ # inn, out: RD::Part
16
+ def call(inn)
17
+ out = RD::Part.new("", nil, "w")
18
+ result = @block.call(inn, out)
19
+ if out.empty?
20
+ result
21
+ else
22
+ out.to_s
23
+ end
24
+ end
25
+
26
+ module FileInclude
27
+ def find_file(file, part)
28
+ for dir in part.tree.include_path
29
+ begin
30
+ return open(dir + "/" + file)
31
+ rescue
32
+ next
33
+ end
34
+ end
35
+ nil
36
+ end
37
+ module_function :find_file
38
+ end # Filter::Include
39
+ end # Filter
40
+
41
+ # Build-in Filter
42
+ # Simple inclusion
43
+ INCLUDE_FILTER = Filter.new(:target) do |inn, out|
44
+ inn.each do |line|
45
+ out.print(line)
46
+ end
47
+ end
48
+
49
+ # Simple RD inclusion
50
+ RD_FILTER = Filter.new(:rd) do |inn, out|
51
+ out.print("=begin\n")
52
+ inn.each do |line|
53
+ out.print(line)
54
+ end
55
+ out.print("\n=end\n")
56
+ end
57
+
58
+ # Eval ruby script
59
+ # "out.print" to output.
60
+ EVAL_FILTER = Filter.new(:target) do |inn, out|
61
+ begin
62
+ eval(inn.to_s)
63
+ rescue
64
+ out.print "!!Error occured when eval!!\n"
65
+ end
66
+ end
67
+
68
+ # RD::Part is a pseudo IO class
69
+ class Part
70
+ attr(:tree)
71
+ attr_accessor :lineno
72
+ attr_accessor :pos
73
+
74
+ def initialize(content = "", tree = nil, mode = "r")
75
+ @content = content
76
+ if mode == "r"
77
+ @content.freeze
78
+ end
79
+ @tree = tree
80
+ @pos = 0
81
+ @lineno = 0
82
+ @unget = nil
83
+ end
84
+
85
+ def each_line(rs = $/)
86
+ while line = gets
87
+ yield(line)
88
+ end
89
+ end
90
+ alias each each_line
91
+
92
+ def each_byte
93
+ while char = getc
94
+ yield(char)
95
+ end
96
+ end
97
+
98
+ def eof?
99
+ @pos == @content.size
100
+ end
101
+ alias eof eof?
102
+
103
+ def get_char(ex)
104
+ ret = nil
105
+ if @unget
106
+ ret = @unget
107
+ else
108
+ unless eof?
109
+ ret = @content[@pos]
110
+ @pos += 1
111
+ else
112
+ raise EOFError if ex
113
+ end
114
+ end
115
+ ret
116
+ end
117
+ private :get_char
118
+
119
+ def getc
120
+ get_char(nil)
121
+ end
122
+
123
+ def readchar
124
+ get_char(true)
125
+ end
126
+
127
+ def ungetc(char)
128
+ @ungetc = char
129
+ nil
130
+ end
131
+
132
+ def get_line(ex, rs)
133
+ ret = nil
134
+ unless eof?
135
+ new_pos = @content.index(rs, @pos)
136
+ if new_pos
137
+ ret = @content[@pos .. new_pos]
138
+ @pos = new_pos + 1
139
+ @lineno += 1
140
+ else
141
+ ret = @content[@pos .. @content.size - 1]
142
+ @pos = @content.size
143
+ @lineno += 1
144
+ end
145
+ else
146
+ raise EOFError if ex
147
+ end
148
+ $_ = ret
149
+ end
150
+ private :get_line
151
+
152
+ def gets(rs = $/)
153
+ get_line(nil, rs)
154
+ end
155
+
156
+ def readline(rs = $/)
157
+ get_line(true, $/)
158
+ end
159
+
160
+ def read(length = @content.size - @pos)
161
+ ret = ""
162
+ length.times do
163
+ ret << getc
164
+ end
165
+ ret
166
+ end
167
+
168
+ def readlines(rs = $/)
169
+ ret = []
170
+ each_line(rs) do |line|
171
+ ret.push(line)
172
+ end
173
+ ret
174
+ end
175
+
176
+ def rewind
177
+ @pos = 0
178
+ end
179
+
180
+ def seek(offset, whence)
181
+ case whence
182
+ when 0
183
+ @pos = offset
184
+ when 1
185
+ @pos += offset
186
+ when 2
187
+ @pos += @content.size - 1
188
+ else
189
+ raise Errno::EINVAL
190
+ end
191
+ end
192
+
193
+ alias tell pos
194
+
195
+ def << (arg)
196
+ begin
197
+ @content << arg.to_s
198
+ self
199
+ rescue
200
+ raise IOError
201
+ end
202
+ end
203
+
204
+ def print(*args)
205
+ begin
206
+ args.each do |i|
207
+ @content << i.to_s
208
+ end
209
+ nil
210
+ rescue
211
+ raise IOError
212
+ end
213
+ end
214
+
215
+ def printf(format, *args)
216
+ str = sprintf(format, *args)
217
+ begin
218
+ @content << str
219
+ nil
220
+ rescue
221
+ raise IOError
222
+ end
223
+ end
224
+
225
+ def putc(char)
226
+ self.printf("%c", char)
227
+ char
228
+ end
229
+
230
+ def puts(*args)
231
+ args.flatten.each do |i|
232
+ self.print(i, "\n")
233
+ end
234
+ end
235
+
236
+ def write(str)
237
+ @content << str.to_s
238
+ str.to_s.size
239
+ end
240
+
241
+ def empty?
242
+ @content.empty?
243
+ end
244
+
245
+ def to_s
246
+ @content
247
+ end
248
+ end
249
+ end
250
+
251
+ =begin
252
+ == script info.
253
+ filter structure.
254
+ $Id: filter.rb,v 1.7 2001/03/19 15:20:08 toshirok Exp $
255
+ =end
@@ -0,0 +1,233 @@
1
+ require 'rd/element'
2
+
3
+ module RD
4
+
5
+ # Inline-level Element of document tree
6
+ class InlineElement < Element
7
+ end
8
+
9
+ # abstruct class.
10
+ class TerminalInline < InlineElement
11
+ include TerminalElement
12
+
13
+ attr_accessor :content
14
+
15
+ def initialize(content)
16
+ super()
17
+ @content = content
18
+ end
19
+ end
20
+
21
+ # abstract class.
22
+ class NonterminalInline < InlineElement
23
+ include NonterminalElement
24
+
25
+ attr_reader :content
26
+
27
+ def initialize
28
+ super()
29
+ @content = []
30
+ end
31
+
32
+ def children
33
+ @content
34
+ end
35
+
36
+ def to_label
37
+ ret = ""
38
+ children.each do |i|
39
+ ret << i.to_label
40
+ end
41
+ ret.strip
42
+ end
43
+ end # NonterminalInline
44
+
45
+ class StringElement < TerminalInline
46
+ def accept(visitor)
47
+ visitor.visit_StringElement(self)
48
+ end
49
+
50
+ def to_label
51
+ @content
52
+ end
53
+ end
54
+
55
+ class Verb < TerminalInline
56
+ def accept(visitor)
57
+ visitor.visit_Verb(self)
58
+ end
59
+
60
+ def to_label
61
+ @content.strip
62
+ end
63
+ end
64
+
65
+ class Emphasis < NonterminalInline
66
+ def accept(visitor)
67
+ visitor.visit_Emphasis(self)
68
+ end
69
+ end
70
+
71
+ class Code < NonterminalInline
72
+ def accept(visitor)
73
+ visitor.visit_Code(self)
74
+ end
75
+ end
76
+
77
+ class Var < NonterminalInline
78
+ def accept(visitor)
79
+ visitor.visit_Var(self)
80
+ end
81
+ end
82
+
83
+ class Keyboard < NonterminalInline
84
+ def accept(visitor)
85
+ visitor.visit_Keyboard(self)
86
+ end
87
+ end
88
+
89
+ class Index < NonterminalInline
90
+ def accept(visitor)
91
+ visitor.visit_Index(self)
92
+ end
93
+ end
94
+
95
+ class Footnote < NonterminalInline
96
+ def accept(visitor)
97
+ visitor.visit_Footnote(self)
98
+ end
99
+ end
100
+
101
+ class Reference < NonterminalInline
102
+ attr_accessor :label # Reference::Label
103
+ alias set_label label=
104
+
105
+ def initialize(label)
106
+ super()
107
+ @content = []
108
+ @label = label.renew_label
109
+ end
110
+
111
+ def Reference.new_from_label(label)
112
+ ref = Reference.new(label)
113
+ ref.add_children(label.to_reference_content)
114
+ return ref
115
+ end
116
+
117
+ def Reference.new_from_label_under_document_struct(label, struct)
118
+ ref = Reference.new(label)
119
+ ref.add_children_under_document_struct(label.to_reference_content,
120
+ struct)
121
+ return ref
122
+ end
123
+
124
+ def Reference.new_from_label_without_document_struct(label)
125
+ ref = Reference.new(label)
126
+ ref.add_children_without_document_struct(label.to_reference_content)
127
+ return ref
128
+ end
129
+
130
+ def accept(visitor)
131
+ visitor.visit_Reference(self)
132
+ end
133
+
134
+ def result_of_apply_method_of(visitor, children)
135
+ label.result_of_apply_method_of(visitor, self, children)
136
+ end
137
+
138
+ def to_label
139
+ @label.to_label
140
+ end
141
+
142
+ # abstruct class. Label for Reference
143
+ class Label
144
+ def extract_label
145
+ raise NotImplementedError, "[BUG] must be overridden."
146
+ end
147
+
148
+ def to_reference_content
149
+ raise NotImplementedError, "[BUG] must be overridden."
150
+ end
151
+
152
+ def result_of_apply_method_of(visitor)
153
+ raise NotImplementedError, "[BUG] must be overridden."
154
+ end
155
+ end
156
+
157
+ class URL < Label
158
+ attr_accessor :url
159
+
160
+ def initialize(url_str)
161
+ @url = url_str
162
+ end
163
+
164
+ def to_label
165
+ ""
166
+ end
167
+
168
+ def result_of_apply_method_of(visitor, reference, children)
169
+ visitor.apply_to_Reference_with_URL(reference, children)
170
+ end
171
+
172
+ def to_reference_content
173
+ [StringElement.new("<URL:#{self.url}>")]
174
+ end
175
+
176
+ def renew_label
177
+ self
178
+ end
179
+ end # URL
180
+
181
+ class RDLabel < Label
182
+ attr_accessor :element_label
183
+ attr_accessor :filename
184
+
185
+ def initialize(element_label, filename = nil)
186
+ @element_label = element_label
187
+ @filename = filename
188
+ end
189
+
190
+ def result_of_apply_method_of(visitor, reference, children)
191
+ visitor.apply_to_Reference_with_RDLabel(reference, children)
192
+ end
193
+
194
+ def to_reference_content
195
+ []
196
+ end
197
+
198
+ def renew_label
199
+ self
200
+ end
201
+
202
+ alias to_label element_label
203
+ end # RDLabel
204
+
205
+ # for initialization. Parameter Object(?)
206
+ class TemporaryLabel < Label
207
+ attr_accessor :element_label
208
+ attr_accessor :filename
209
+
210
+ def initialize(element_label = [], filename = nil)
211
+ @element_label = element_label
212
+ @filename = filename
213
+ end
214
+
215
+ def to_reference_content
216
+ self.element_label
217
+ end
218
+
219
+ def renew_label
220
+ RDLabel.new(extract_label(self.element_label), self.filename)
221
+ end
222
+
223
+ def extract_label(elements)
224
+ ret = ""
225
+ elements.each do |i|
226
+ ret << i.to_label
227
+ end
228
+ ret.strip
229
+ end
230
+ private :extract_label
231
+ end
232
+ end # Reference
233
+ end