ctioga2 0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. data/COPYING +339 -0
  2. data/Changelog +6 -0
  3. data/bin/ctioga2 +26 -0
  4. data/lib/ctioga2/commands/arguments.rb +58 -0
  5. data/lib/ctioga2/commands/commands.rb +258 -0
  6. data/lib/ctioga2/commands/doc/doc.rb +118 -0
  7. data/lib/ctioga2/commands/doc/documentation-commands.rb +119 -0
  8. data/lib/ctioga2/commands/doc/help.rb +95 -0
  9. data/lib/ctioga2/commands/doc/html.rb +230 -0
  10. data/lib/ctioga2/commands/doc/introspection.rb +211 -0
  11. data/lib/ctioga2/commands/doc/man.rb +279 -0
  12. data/lib/ctioga2/commands/doc/markup.rb +359 -0
  13. data/lib/ctioga2/commands/general-commands.rb +119 -0
  14. data/lib/ctioga2/commands/general-types.rb +118 -0
  15. data/lib/ctioga2/commands/groups.rb +73 -0
  16. data/lib/ctioga2/commands/interpreter.rb +257 -0
  17. data/lib/ctioga2/commands/parsers/command-line.rb +187 -0
  18. data/lib/ctioga2/commands/parsers/file.rb +186 -0
  19. data/lib/ctioga2/commands/strings.rb +303 -0
  20. data/lib/ctioga2/commands/type.rb +100 -0
  21. data/lib/ctioga2/commands/variables.rb +101 -0
  22. data/lib/ctioga2/data/backends/backend.rb +260 -0
  23. data/lib/ctioga2/data/backends/backends.rb +39 -0
  24. data/lib/ctioga2/data/backends/backends/gnuplot.rb +140 -0
  25. data/lib/ctioga2/data/backends/backends/math.rb +121 -0
  26. data/lib/ctioga2/data/backends/backends/text.rb +335 -0
  27. data/lib/ctioga2/data/backends/description.rb +405 -0
  28. data/lib/ctioga2/data/backends/factory.rb +73 -0
  29. data/lib/ctioga2/data/backends/parameter.rb +109 -0
  30. data/lib/ctioga2/data/datacolumn.rb +245 -0
  31. data/lib/ctioga2/data/dataset.rb +233 -0
  32. data/lib/ctioga2/data/filters.rb +131 -0
  33. data/lib/ctioga2/data/merge.rb +43 -0
  34. data/lib/ctioga2/data/point.rb +72 -0
  35. data/lib/ctioga2/data/stack.rb +294 -0
  36. data/lib/ctioga2/graphics/coordinates.rb +73 -0
  37. data/lib/ctioga2/graphics/elements.rb +111 -0
  38. data/lib/ctioga2/graphics/elements/containers.rb +111 -0
  39. data/lib/ctioga2/graphics/elements/curve2d.rb +155 -0
  40. data/lib/ctioga2/graphics/elements/element.rb +90 -0
  41. data/lib/ctioga2/graphics/elements/primitive.rb +256 -0
  42. data/lib/ctioga2/graphics/elements/subplot.rb +140 -0
  43. data/lib/ctioga2/graphics/generator.rb +68 -0
  44. data/lib/ctioga2/graphics/legends.rb +108 -0
  45. data/lib/ctioga2/graphics/legends/area.rb +199 -0
  46. data/lib/ctioga2/graphics/legends/items.rb +183 -0
  47. data/lib/ctioga2/graphics/legends/provider.rb +58 -0
  48. data/lib/ctioga2/graphics/legends/storage.rb +65 -0
  49. data/lib/ctioga2/graphics/root.rb +209 -0
  50. data/lib/ctioga2/graphics/styles.rb +30 -0
  51. data/lib/ctioga2/graphics/styles/axes.rb +247 -0
  52. data/lib/ctioga2/graphics/styles/background.rb +122 -0
  53. data/lib/ctioga2/graphics/styles/base.rb +115 -0
  54. data/lib/ctioga2/graphics/styles/carrays.rb +53 -0
  55. data/lib/ctioga2/graphics/styles/curve.rb +101 -0
  56. data/lib/ctioga2/graphics/styles/drawable.rb +87 -0
  57. data/lib/ctioga2/graphics/styles/factory.rb +351 -0
  58. data/lib/ctioga2/graphics/styles/legend.rb +63 -0
  59. data/lib/ctioga2/graphics/styles/plot.rb +410 -0
  60. data/lib/ctioga2/graphics/styles/sets.rb +64 -0
  61. data/lib/ctioga2/graphics/styles/texts.rb +277 -0
  62. data/lib/ctioga2/graphics/subplot-commands.rb +141 -0
  63. data/lib/ctioga2/graphics/types.rb +188 -0
  64. data/lib/ctioga2/graphics/types/bijection.rb +79 -0
  65. data/lib/ctioga2/graphics/types/boundaries.rb +170 -0
  66. data/lib/ctioga2/graphics/types/boxes.rb +157 -0
  67. data/lib/ctioga2/graphics/types/dimensions.rb +157 -0
  68. data/lib/ctioga2/graphics/types/point.rb +247 -0
  69. data/lib/ctioga2/log.rb +97 -0
  70. data/lib/ctioga2/metabuilder/type.rb +316 -0
  71. data/lib/ctioga2/metabuilder/types.rb +39 -0
  72. data/lib/ctioga2/metabuilder/types/coordinates.rb +124 -0
  73. data/lib/ctioga2/metabuilder/types/dates.rb +43 -0
  74. data/lib/ctioga2/metabuilder/types/lists.rb +188 -0
  75. data/lib/ctioga2/metabuilder/types/numbers.rb +97 -0
  76. data/lib/ctioga2/metabuilder/types/strings.rb +93 -0
  77. data/lib/ctioga2/metabuilder/types/styles.rb +178 -0
  78. data/lib/ctioga2/plotmaker.rb +677 -0
  79. data/lib/ctioga2/postprocess.rb +115 -0
  80. data/lib/ctioga2/utils.rb +120 -0
  81. data/setup.rb +1586 -0
  82. metadata +144 -0
@@ -0,0 +1,359 @@
1
+ # markup.rb: simple markup system used wirhin the documentation.
2
+ # copyright (c) 2009 by Vincent Fourmond
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details (in the COPYING file).
13
+
14
+ require 'ctioga2/utils'
15
+ require 'ctioga2/log'
16
+
17
+ module CTioga2
18
+
19
+ Version::register_svn_info('$Revision: 84 $', '$Date: 2009-06-12 00:09:41 +0200 (Fri, 12 Jun 2009) $')
20
+
21
+ module Commands
22
+
23
+ module Documentation
24
+
25
+ # The documentation strings are written in a simple markup
26
+ # language.
27
+ class MarkedUpText
28
+
29
+ # Do we really need logging ?
30
+ include Log
31
+
32
+ # The base class for markup items.
33
+ class MarkupItem
34
+ # The documentation object
35
+ attr_accessor :doc
36
+
37
+ def initialize(doc)
38
+ @doc = doc
39
+ end
40
+
41
+ def to_s
42
+ end
43
+
44
+ def dump_string
45
+ return ""
46
+ end
47
+
48
+ end
49
+
50
+ # A markup item representing plain text.
51
+ #
52
+ # TODO: in to_s a simple word-wrapping algorithm could be
53
+ # used.
54
+ class MarkupText < MarkupItem
55
+ # The text
56
+ attr_accessor :text
57
+
58
+ def initialize(doc, text = "", strip = true)
59
+ super(doc)
60
+ @text = text
61
+ if strip
62
+ @text.gsub!(/\n/, " ")
63
+ end
64
+ end
65
+
66
+ def to_s
67
+ return text
68
+ end
69
+
70
+ def dump_string
71
+ return "text: #{@text}"
72
+ end
73
+
74
+ end
75
+
76
+ # A markup item representing verbatim text, with the given
77
+ # class
78
+ class MarkupVerbatim < MarkupItem
79
+ # The text
80
+ attr_accessor :text
81
+
82
+ # The verbatim text class
83
+ attr_accessor :cls
84
+
85
+ def initialize(doc, text, cls)
86
+ super(doc)
87
+ @text = text
88
+ @cls = cls
89
+ end
90
+
91
+ def to_s
92
+ return text
93
+ end
94
+
95
+ def dump_string
96
+ return "#{@cls}: #{@text}"
97
+ end
98
+
99
+ end
100
+
101
+ # A link to a type/group/command
102
+ class MarkupLink < MarkupItem
103
+ # The object target of the link
104
+ attr_accessor :target
105
+
106
+ # _target_ is the name of the target, which can be of _type_
107
+ # 'group', 'command' and 'type'.
108
+ def initialize(doc, target, type)
109
+ super(doc)
110
+ @target = doc.send("#{type}s")[target]
111
+ end
112
+
113
+ def to_s
114
+ if @target
115
+ return @target.name
116
+ else
117
+ return "unknown"
118
+ end
119
+ end
120
+
121
+ def dump_string
122
+ return "link: #{@target}"
123
+ end
124
+ end
125
+
126
+ # An itemize object
127
+ class MarkupItemize < MarkupItem
128
+
129
+ # An array of arrays of MarkupItem, each representing an
130
+ # element of the itemize object.
131
+ attr_accessor :items
132
+
133
+ def initialize(doc, items = [])
134
+ super(doc)
135
+ @items = items
136
+ end
137
+
138
+ def to_s
139
+ str = ""
140
+ for i in @items
141
+ str << " * "
142
+ for j in i
143
+ str << j.to_s
144
+ end
145
+ str << "\n"
146
+ end
147
+ return str
148
+ end
149
+
150
+ def dump_string
151
+ return @items.map {|x|
152
+ "* #{x.map do |y| y.dump_string; end}\n"
153
+ }.join('')
154
+ end
155
+
156
+ end
157
+
158
+ # An item that contains a paragraph
159
+ class MarkupParagraph < MarkupItem
160
+ attr_accessor :elements
161
+
162
+ def initialize(doc, elements)
163
+ super(doc)
164
+ @elements = elements
165
+ end
166
+
167
+ def to_s
168
+ return @elements.map {|x| x.to_s }.join('')
169
+ end
170
+
171
+ def dump_string
172
+ return "par: " + @elements.map {|x|
173
+ " #{x.dump_string}\n"
174
+ }.join('')
175
+ end
176
+
177
+ end
178
+
179
+ # The reference Doc object
180
+ attr_accessor :doc
181
+
182
+ # The elements that make up the MarkedUpText
183
+ attr_accessor :elements
184
+
185
+ # Creates a MarkedUpText object.
186
+ def initialize(doc, text = nil)
187
+ @elements = []
188
+ @doc = doc
189
+ if text
190
+ parse_from_string(text)
191
+ end
192
+ end
193
+
194
+
195
+ def dump
196
+ puts "Number of elements: #{@elements.size}"
197
+ for el in @elements
198
+ puts "#{el.class} -> #{el.to_s}"
199
+ end
200
+ end
201
+
202
+
203
+ # Parses the given _string_ and append the results to the
204
+ # MarkedUpText's elements.
205
+ #
206
+ # Markup elements:
207
+ #
208
+ # * a line beginning with '> ' is an example for command-line
209
+ # * a line beginning with '# ' is an example for use within a
210
+ # command file.
211
+ # * a line beginning with '@ ' is a generic verbatim text.
212
+ # * a line beginning with ' *' is an element of an
213
+ # itemize. The itemize finishes when a new paragraph is
214
+ # starting.
215
+ # * a {group: ...} or {type: ...} or {command: ...} is a link
216
+ # to the element.
217
+ # * a blank line marks a paragraph break.
218
+ def parse_from_string(string)
219
+ @last_type = nil
220
+ @last_string = ""
221
+
222
+ lines = string.split(/[ \t]*\n/)
223
+ for l in lines
224
+ l.chomp!
225
+ case l
226
+ when /^[#>@]\s(.*)/ # a verbatim line
227
+ case l[0,1]
228
+ when '#'
229
+ type = :cmdfile
230
+ when '>'
231
+ type = :cmdline
232
+ else
233
+ type = :example
234
+ end
235
+ if @last_type == type
236
+ @last_string << "#{$1}\n"
237
+ else
238
+ flush_element
239
+ @last_type = type
240
+ @last_string = "#{$1}\n"
241
+ end
242
+ when /^\s\*\s*(.*)/
243
+ flush_element
244
+ @last_type = :item
245
+ @last_string = "#{$1}\n"
246
+ when /^\s*$/ # Blank line:
247
+ flush_element
248
+ @last_type = nil
249
+ @last_string = ""
250
+ else
251
+ case @last_type
252
+ when :item, :paragraph # simply go on
253
+ @last_string << "#{l}\n"
254
+ else
255
+ flush_element
256
+ @last_type = :paragraph
257
+ @last_string = "#{l}\n"
258
+ end
259
+ end
260
+ end
261
+ flush_element
262
+ end
263
+
264
+ protected
265
+
266
+ # Parses the markup found within a paragraph (ie: links and
267
+ # other text attributes, but not verbatim, list or other
268
+ # markings) and returns an array containing the MarkupItem
269
+ # elements.
270
+ def parse_paragraph_markup(doc, string)
271
+ els = []
272
+ while string =~ /\{(group|type|command):\s*([^}]+?)\s*\}/
273
+ els << MarkupText.new(doc, $`)
274
+ els << MarkupLink.new(doc, $2, $1)
275
+ string = $'
276
+ end
277
+ els << MarkupText.new(doc, string)
278
+ return els
279
+ end
280
+
281
+ # Adds the element accumulated so far to the @elements array.
282
+ def flush_element
283
+ case @last_type
284
+ when :cmdline, :cmdfile
285
+ @elements << MarkupVerbatim.new(@doc, @last_string,
286
+ "examples-#{@last_type}")
287
+ when :example
288
+ @elements << MarkupVerbatim.new(@doc, @last_string, "examples")
289
+ when :paragraph
290
+ @elements <<
291
+ MarkupParagraph.new(@doc,
292
+ parse_paragraph_markup(doc, @last_string))
293
+ when :item
294
+ if @elements.last.is_a?(MarkupItemize)
295
+ @elements.last.items <<
296
+ parse_paragraph_markup(doc, @last_string)
297
+ else
298
+ @elements <<
299
+ MarkupItemize.new(@doc,
300
+ [ parse_paragraph_markup(doc, @last_string)])
301
+ end
302
+ else # In principle, nil
303
+ return
304
+ end
305
+ end
306
+
307
+
308
+ end
309
+
310
+ # A class dumping markup information to standard output
311
+ class Markup
312
+ # The Doc object the Markup class should dump
313
+ attr_accessor :doc
314
+
315
+ def initialize(doc)
316
+ @doc = doc
317
+ end
318
+
319
+ # Dumps the markup of all commands
320
+ def write_commands(out = STDOUT)
321
+ cmds, groups = @doc.documented_commands
322
+
323
+ for g in groups
324
+ out.puts "Group markup: #{g.name}"
325
+ out.puts dump_markup(g.description)
326
+
327
+ commands = cmds[g].sort {|a,b|
328
+ a.name <=> b.name
329
+ }
330
+
331
+ for cmd in commands
332
+ out.puts "Command: #{cmd.name}"
333
+ out.puts dump_markup(cmd.long_description)
334
+ end
335
+ end
336
+ end
337
+
338
+ # Dumps the markup of all types
339
+ def write_types(out = STDOUT)
340
+ types = @doc.types.sort.map { |d| d[1]}
341
+ for t in types
342
+ out.puts "Type: #{t.name}"
343
+ out.puts dump_markup(t.description)
344
+ end
345
+ end
346
+
347
+ def dump_markup(items)
348
+ if items.is_a? String
349
+ mup = MarkedUpText.new(@doc, items)
350
+ return dump_markup(mup.elements)
351
+ end
352
+ return items.map { |x| "-> #{x.dump_string}\n"}
353
+ end
354
+
355
+ end
356
+ end
357
+
358
+ end
359
+ end
@@ -0,0 +1,119 @@
1
+ # general-commands.rb: various global scope commands
2
+ # copyright (c) 2009 by Vincent Fourmond
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details (in the COPYING file).
13
+
14
+ require 'ctioga2/utils'
15
+ require 'ctioga2/commands/general-types'
16
+ require 'ctioga2/commands/parsers/file'
17
+
18
+ module CTioga2
19
+
20
+ Version::register_svn_info('$Revision: 55 $', '$Date: 2009-05-27 00:01:34 +0200 (Wed, 27 May 2009) $')
21
+
22
+ module Commands
23
+
24
+ # General scope commands.
25
+ GeneralGroup =
26
+ CmdGroup.new('general', "General commands",
27
+ "General scope commands", 1000)
28
+
29
+
30
+
31
+ # Display help on the command-line
32
+ CommandLineHelpCommand =
33
+ Cmd.new("command-line-help", 'h',
34
+ "--help", [ ]) do |plotmaker|
35
+ plotmaker.interpreter.doc.display_command_line_help
36
+ exit
37
+ end
38
+
39
+ CommandLineHelpCommand.describe("Prints help on command-line options and exits",
40
+ <<EOH, GeneralGroup)
41
+ Prints helps about short and long options available when run from the
42
+ command-line.
43
+ EOH
44
+
45
+ # Prints the version of ctioga2 used
46
+ PrintVersion = Cmd.new("version", '-V', "--version", []) do |plotmaker|
47
+ puts "This is ctioga2 version #{CTioga2::Version::version}"
48
+ end
49
+
50
+ PrintVersion.describe("Prints the version",
51
+ "Prints the version of ctioga in use",
52
+ GeneralGroup)
53
+
54
+ # Includes a file
55
+ RunCommandFile =
56
+ Cmd.new("include", '-f', "--file",
57
+ [ CmdArg.new('file'), ]) do |plotmaker, file|
58
+ plotmaker.interpreter.run_command_file(file)
59
+ end
60
+
61
+ RunCommandFile.describe("Runs given command file", <<EOH, GeneralGroup)
62
+ Reads the file and runs commands found in them, using the ctioga language.
63
+ > ctioga2 -f my_file.ct2
64
+ EOH
65
+
66
+ # Evaluate a series of commands.
67
+ EvalCommand = Cmd.new("eval", '-e', "--eval",
68
+ [ CmdArg.new('commands'), ]) do |plotmaker, string|
69
+ plotmaker.interpreter.run_commands(string)
70
+ end
71
+
72
+ EvalCommand.describe("Runs the given commands", <<EOH, GeneralGroup)
73
+ Runs the given strings as commands, as if given from a command file.
74
+ EOH
75
+
76
+ # Increases verbosity
77
+ VerboseLogging =
78
+ Cmd.new("verbose", '-v', "--verbose", [ ]) do |plotmaker|
79
+ CTioga2::Log::set_level(Logger::INFO)
80
+ end
81
+
82
+ VerboseLogging.describe("Makes ctioga2 more verbose", <<EOH, GeneralGroup)
83
+ With this on, ctioga2 outputs quite a fair amount of informative messages.
84
+ EOH
85
+
86
+ # Write debugging information.
87
+ #
88
+ # TODO: this should be the place where a lot of customization of
89
+ # the debug output could go - including channels or things like
90
+ # that. To be seen later on...
91
+ DebugLogging =
92
+ Cmd.new("debug", nil, "--debug", [ ]) do |plotmaker|
93
+ CTioga2::Log::set_level(Logger::DEBUG)
94
+ end
95
+
96
+ DebugLogging.describe("Makes ctioga2 write out debugging information",
97
+ <<EOH, GeneralGroup)
98
+ With this on, ctioga2 writes a whole lot of debugging information. You
99
+ probably will not need that unless you intend to file a bug report or
100
+ to tackle a problem yourself.
101
+ EOH
102
+
103
+ # Includes a file
104
+ EchoCmd =
105
+ Cmd.new("echo", nil, "--echo", [ ]) do |plotmaker|
106
+ STDERR.puts "Command-line used: "
107
+ STDERR.puts plotmaker.quoted_command_line
108
+ end
109
+
110
+ EchoCmd.describe("Prints command-line used to standard error",
111
+ <<EOH, GeneralGroup)
112
+ Writes the whole command-line used to standard error, quoted in such a
113
+ way that it should be usable directly for copy/paste.
114
+ EOH
115
+
116
+
117
+ end
118
+ end
119
+