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
@@ -0,0 +1,214 @@
1
+ require 'rd/output-format-visitor'
2
+ require 'rd/reference-resolver'
3
+ require 'rd/rbl-file'
4
+ require 'forwardable'
5
+
6
+ module RD
7
+ # for Backward compatibility
8
+ class RDVisitor < OutputFormatVisitor
9
+ extend Forwardable
10
+
11
+ def apply_to_DescListItemTerm(element, contents)
12
+ contents
13
+ end
14
+
15
+ def apply_to_MethodListItemTerm(element)
16
+ apply_to_String(element.content)
17
+ end
18
+
19
+ def_delegator(:@reference_resolver, :labels, :__labels__)
20
+ def_delegator(:@reference_resolver, :label_prefix, :__label_prefix__)
21
+ def_delegator(:@reference_resolver, :rbl_suite)
22
+
23
+ def prepare_labels(tree, prefix = "label:")
24
+ @reference_resolver = ReferenceResolver.new(tree, prefix)
25
+ end
26
+
27
+ def_delegator(:@reference_resolver, :refer)
28
+ def_delegator(:@reference_resolver, :get_anchor)
29
+ def_delegator(:@reference_resolver, :make_rbl_file)
30
+
31
+ def refer_external(label)
32
+ label = @reference_resolver.refer_external_file(label)
33
+ return nil unless label
34
+ label[1]
35
+ end
36
+ end
37
+
38
+ module AutoLabel
39
+ def parse_rmi(src)
40
+ labels = {}
41
+ $method_index = []
42
+ eval(src)
43
+ $method_index.each do |c, k, m, f, l|
44
+ labels[c + k + m] = l
45
+ end
46
+ labels
47
+ end
48
+ private :parse_rmi
49
+ end # AutoLabel
50
+
51
+ =begin
52
+ == module RD::MethodParse
53
+ this module provide several functions for MehotList.
54
+ =end
55
+
56
+ module MethodParse
57
+
58
+ def analize_method(method)
59
+ klass = nil
60
+ args = nil
61
+ kind = nil
62
+ if /[^{(\s]+/ =~ method
63
+ method = $&
64
+ args = $' # '
65
+ end
66
+
67
+ if /^(.*)(#|::|\.)/ =~ method
68
+ klass = $1
69
+ kind = str2kind($2)
70
+ method = $' # '
71
+ end
72
+
73
+ if klass == "function" and kind == :instance_method
74
+ kind = :function
75
+ end
76
+
77
+ [klass, kind, method, args]
78
+ end
79
+ module_function :analize_method
80
+
81
+ def str2kind(str)
82
+ case str
83
+ when '#'
84
+ :instance_method
85
+ when '.'
86
+ :class_method
87
+ when '::'
88
+ :constant
89
+ end
90
+ end
91
+ module_function :str2kind
92
+
93
+ def kind2str(int)
94
+ case int
95
+ when :instance_method, :function
96
+ '#'
97
+ when :class_method
98
+ '.'
99
+ when :constant
100
+ '::'
101
+ end
102
+ end
103
+ module_function :kind2str
104
+
105
+ KIND2NUM = {:constant => 0, :class_method => 1, :instance_method => 2, :function => 2}
106
+ def kind2num(str)
107
+ KIND2NUM[str]
108
+ end
109
+ module_function :kind2num
110
+
111
+ def make_mindex_label(element)
112
+ klass, kind, method = analize_method(element.label)
113
+ case kind
114
+ when :class_method
115
+ klass + "_S_" + tr_method(method)
116
+ when :instance_method
117
+ klass + "_" + tr_method(method)
118
+ when :constant
119
+ klass + "_" + method
120
+ when :function
121
+ "function_" + tr_method(method)
122
+ else
123
+ element.label
124
+ end
125
+ end
126
+ module_function :make_mindex_label
127
+
128
+ def tr_method(method)
129
+ case method
130
+ when "[]"
131
+ "ref_"
132
+ when "[]="
133
+ "set_"
134
+ when "+"
135
+ "plus_"
136
+ when "+@"
137
+ "uplus_"
138
+ when "-"
139
+ "minus_"
140
+ when "-@"
141
+ "uminus_"
142
+ when "*"
143
+ "mul_"
144
+ when "/"
145
+ "div_"
146
+ when "%"
147
+ "mod_"
148
+ when "**"
149
+ "power_"
150
+ when "~"
151
+ "inv_"
152
+ when "=="
153
+ "eq_"
154
+ when "==="
155
+ "eqq_"
156
+ when "=~"
157
+ "match_"
158
+ when "&"
159
+ "and_"
160
+ when "|"
161
+ "or_"
162
+ when "<<"
163
+ "lshift_"
164
+ when ">>"
165
+ "rshift_"
166
+ when "<=>"
167
+ "cmp_"
168
+ when "<"
169
+ "lt_"
170
+ when "<="
171
+ "le_"
172
+ when ">"
173
+ "gt_"
174
+ when ">="
175
+ "ge_"
176
+ when "^"
177
+ "xor_"
178
+ when "`"
179
+ "backquote_"
180
+ when /!$/
181
+ $` + "_bang" # `
182
+ when /\?$/
183
+ $` + "_p" # `
184
+ when /=$/
185
+ $` + "_eq" # `
186
+ else
187
+ method
188
+ end
189
+ end
190
+ module_function :tr_method
191
+
192
+ def make_method_index(tree)
193
+ indexes = []
194
+ tree.each do |i|
195
+ if i.is_a?(MethodListItem)
196
+ klass, kind, method, args = analize_method(i.term.content)
197
+ indexes.push([klass, kind2num(kind), method, kind]) if kind
198
+ end
199
+ end
200
+ indexes.uniq!
201
+ indexes.sort.each {|i| i[1] = i.pop}
202
+ end
203
+ module_function :make_method_index
204
+
205
+ end # MethodParse
206
+ end # RD
207
+
208
+ =begin
209
+ == script info.
210
+ abstruct class for visitor of RDTree.
211
+ $Id: rdvisitor.rb,v 1.46 2003/02/18 16:20:25 tosh Exp $
212
+
213
+ =end
214
+
@@ -0,0 +1,114 @@
1
+ require 'rd/rbl-suite'
2
+ require 'rd/labeled-element'
3
+
4
+ require 'forwardable'
5
+
6
+ module RD
7
+ class ReferenceResolver
8
+ extend Forwardable
9
+ include Enumerable
10
+
11
+ attr_reader :labels
12
+ attr_reader :label_prefix
13
+ attr_reader :rbl_suite
14
+
15
+ def initialize(tree, prefix = "label:")
16
+ init_labels(tree)
17
+ @label_prefix = prefix
18
+ @rbl_suite = RBLSuite.new(tree.include_path)
19
+ end
20
+
21
+ def init_labels(tree)
22
+ @labels = {}
23
+ ary = (tree.find_all do |i|
24
+ i.is_a? LabeledElement
25
+ end)
26
+ num = 0
27
+ ary.each do |i|
28
+ push_to_labels(i.to_label, [i, num])
29
+ num += 1
30
+ end
31
+ end
32
+ private :init_labels
33
+
34
+ def push_to_labels(key, value)
35
+ if labels[key]
36
+ labels[key].push(value)
37
+ else
38
+ labels[key] = [value]
39
+ end
40
+ end
41
+ private :push_to_labels
42
+
43
+ def each_label
44
+ tmp = []
45
+ labels.each_value do |i|
46
+ i.each do |j|
47
+ tmp.push(j)
48
+ end
49
+ end
50
+ tmp.sort{|i,j| i[1] <=> j[1]}.each do |i|
51
+ yield(i[0])
52
+ end
53
+ end
54
+ alias each each_label
55
+
56
+ def referent_of_label(label)
57
+ label = label.label if label.is_a? Reference
58
+ if label.filename
59
+ refer_external_file(label)
60
+ else
61
+ anchor = refer(label)
62
+ return nil unless anchor
63
+ [nil, anchor]
64
+ end
65
+ end
66
+
67
+ def refer(label)
68
+ matched = labels[label2str(label)]
69
+ return nil unless matched
70
+ num2anchor(matched[0][1])
71
+ end
72
+
73
+ def refer_element(label)
74
+ labels.fetch(label2str(label), []).collect{|i| i[0] }
75
+ end
76
+
77
+ def refer_external_file(label)
78
+ label = label.label if label.is_a? Reference
79
+ rbl_suite.refer(label.element_label, label.filename)
80
+ end
81
+
82
+ def get_label_num(element)
83
+ entry = labels[element.to_label].find{|i| i[0] == element }
84
+ return nil unless entry
85
+ entry[1]
86
+ end
87
+
88
+ def get_anchor(element)
89
+ if num = get_label_num(element)
90
+ num2anchor(num)
91
+ end
92
+ end
93
+
94
+ def num2anchor(num)
95
+ label_prefix + num.to_s
96
+ end
97
+ private :num2anchor
98
+
99
+ def label2str(label)
100
+ case label
101
+ when String
102
+ label
103
+ when Element, Reference::RDLabel
104
+ label.to_label
105
+ else
106
+ raise ArgumentError, "can't extract Label from #{label}."
107
+ end
108
+ end
109
+
110
+ def make_rbl_file(filename)
111
+ RBLFile.create_rbl_file(filename, self)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module RD
3
+ module SearchFile
4
+ def search_file(base, include_path, suffixes)
5
+ include_path.each do |dir|
6
+ suffixes.each do |suffix|
7
+ file = dir + "/" + base + "." + suffix
8
+ return file if File.exist? file
9
+ end
10
+ end
11
+ nil
12
+ end
13
+ end
14
+ end
data/lib/rd/tree.rb ADDED
@@ -0,0 +1,103 @@
1
+ require "rd/rdblockparser.tab"
2
+ require "rd/filter"
3
+ require "rd/document-struct"
4
+ require "rd/version"
5
+
6
+ module RD
7
+
8
+ # document tree
9
+ class Tree
10
+ include Enumerable
11
+
12
+ SYSTEM_NAME = "RDtool Framework -- Document Tree"
13
+ SYSTEM_VERSION = "$Version: 0.6.23$" #"
14
+ VERSION = Version.new_from_version_string(SYSTEM_NAME, SYSTEM_VERSION)
15
+
16
+ def Tree.version
17
+ VERSION
18
+ end
19
+
20
+ TMP_DIR = "/tmp"
21
+
22
+ def Tree.tmp_dir
23
+ TMP_DIR
24
+ end
25
+
26
+ attr_reader :root
27
+ attr_reader :document_struct
28
+ attr_accessor :include_paths
29
+ alias include_path include_paths
30
+ alias include_path= include_paths=
31
+ attr_reader :filters
32
+ alias filter filters
33
+ attr_accessor :tmp_dir
34
+
35
+ def Tree.new_with_document_struct(document_struct, include_paths = [])
36
+ Tree.new(document_struct, nil, include_paths)
37
+ end
38
+
39
+ def initialize(document_struct, src_str = nil, include_paths = [])
40
+ @src = src_str
41
+ @document_struct = document_struct
42
+ @include_paths = include_paths
43
+ @filters = Hash.new()
44
+ @tmp_dir = TMP_DIR
45
+ @root = nil
46
+ end
47
+
48
+ def parse
49
+ parser = RDParser.new
50
+ src = @src.respond_to?(:to_a) ? @src.to_a : @src.split(/^/)
51
+ set_root(parser.parse(src, self))
52
+ end
53
+
54
+ def set_root(element)
55
+ raise ArgumentError, "#{element.class} can't be root." unless
56
+ @document_struct.is_valid?(self, element)
57
+ @root = element
58
+ element.parent = self
59
+ end
60
+ alias root= set_root
61
+
62
+ def make_root(&block)
63
+ child = DocumentElement.new
64
+ set_root(child)
65
+ child.build(&block) if block_given?
66
+ child
67
+ end
68
+
69
+ def check_valid
70
+ each_element do |i|
71
+ raise RuntimeError,
72
+ "mismatched document structure, #{i.parent} <-/- #{i}." unless
73
+ @document_struct.is_valid?(i.parent, i)
74
+ end
75
+ true
76
+ end
77
+
78
+ def accept(visitor)
79
+ @root.accept(visitor)
80
+ end
81
+
82
+ def each_element(&block)
83
+ return nil unless @root
84
+ @root.each(&block)
85
+ end
86
+ alias each each_element
87
+
88
+ def tree
89
+ self
90
+ end
91
+
92
+ def Tree.new_from_rdo(*rdos) # rdos: IOs
93
+ tree = Tree.new("", [], nil)
94
+ tree_content = []
95
+ rdos.each do |i|
96
+ subtree = Marshal.load(i)
97
+ tree_content.concat(subtree.root.blocks)
98
+ end
99
+ tree.root = DocumentElement.new(tree_content)
100
+ tree
101
+ end
102
+ end
103
+ end