ridl 2.8.2 → 2.9.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.
data/lib/ridl/options.rb CHANGED
@@ -14,13 +14,11 @@ require 'ostruct'
14
14
  require 'json'
15
15
 
16
16
  module IDL
17
-
18
17
  RIDLRC = '.ridlrc'
19
18
  RIDLRC_GLOBAL = File.expand_path(File.join(ENV['HOME'] || ENV['HOMEPATH'] || '~', RIDLRC))
20
19
 
21
20
  class Options < OpenStruct
22
-
23
- def initialize(hash=nil, marked=nil)
21
+ def initialize(hash = nil, marked = nil)
24
22
  super(hash)
25
23
  @marked = marked
26
24
  end
@@ -35,7 +33,7 @@ module IDL
35
33
  end
36
34
 
37
35
  def copy!(from, *keys)
38
- keys.flatten.each {|k| self[k] = from[k] }
36
+ keys.flatten.each { |k| self[k] = from[k] }
39
37
  self
40
38
  end
41
39
 
@@ -67,7 +65,6 @@ module IDL
67
65
  self.class.new(_dup_elem(@marked || @table), @marked)
68
66
  end
69
67
 
70
-
71
68
  def load(rcpath)
72
69
  IDL.log(3, "Loading #{RIDLRC} from #{rcpath}")
73
70
  _cfg = JSON.parse(IO.read(rcpath))
@@ -94,7 +91,7 @@ module IDL
94
91
  protected
95
92
 
96
93
  def _merge(to, from, *keys)
97
- keys = keys.flatten.collect {|k| k.to_sym}
94
+ keys = keys.flatten.collect { |k| k.to_sym }
98
95
  keys = from.keys if keys.empty?
99
96
  keys.each do |k|
100
97
  if from.has_key?(k)
@@ -122,9 +119,10 @@ module IDL
122
119
  def _dup_elem(v)
123
120
  case v
124
121
  when Array
125
- v.collect {|e| _dup_elem(e) }
122
+ v.collect { |e| _dup_elem(e) }
126
123
  when Hash
127
- v.inject({}) {|h, (k, e)| h[k] = _dup_elem(e); h }
124
+ v.inject({}) { |h, (k, e)| h[k] = _dup_elem(e)
125
+ h }
128
126
  when OpenStruct
129
127
  v.class.new(_dup_elem(v.__send__(:table)))
130
128
  else
@@ -136,12 +134,12 @@ module IDL
136
134
 
137
135
  def self.load_config(opt)
138
136
  # first collect config from known (standard and configured) locations
139
- _rc_paths = [ RIDLRC_GLOBAL ]
137
+ _rc_paths = [RIDLRC_GLOBAL]
140
138
  _loaded_rc_paths = []
141
139
  (ENV['RIDLRC'] || '').split(/:|;/).each do |p|
142
140
  _rc_paths << p unless _rc_paths.include?(p)
143
141
  end
144
- _rc_paths.collect {|path| File.expand_path(path) }.each do |rcp|
142
+ _rc_paths.collect { |path| File.expand_path(path) }.each do |rcp|
145
143
  IDL.log(3, "Testing rc path #{rcp}")
146
144
  if File.readable?(rcp) && !_loaded_rc_paths.include?(rcp)
147
145
  opt.load(rcp)
@@ -163,6 +161,7 @@ module IDL
163
161
  IDL.log(3, "Ignoring #{File.readable?(_rcp) ? 'already loaded' : 'inaccessible'} rc path #{_rcp}")
164
162
  end
165
163
  break if /\A(.:(\\|\/)|\.|\/)\Z/ =~ _cwd
164
+
166
165
  _cwd = File.dirname(_cwd)
167
166
  end while true
168
167
  # now load them in reverse order
@@ -172,5 +171,4 @@ module IDL
172
171
  end
173
172
  end
174
173
  end
175
-
176
174
  end
@@ -47,13 +47,9 @@ end
47
47
 
48
48
  module IDL
49
49
  class OptionList
50
-
51
50
  class Option
52
-
53
51
  class Group
54
-
55
52
  class ParamSet
56
-
57
53
  class Configurator
58
54
  def initialize(set)
59
55
  @set = set
@@ -70,11 +66,12 @@ module IDL
70
66
  end
71
67
 
72
68
  def without(*params)
73
- params.each {|p| @set.params.delete(p.to_sym) }
69
+ params.each { |p| @set.params.delete(p.to_sym) }
74
70
  end
75
71
  end
76
72
 
77
73
  attr_reader :params
74
+
78
75
  def initialize(options)
79
76
  @description = Array === options[:description] ? options[:description] : (options[:description] || '').split('\n')
80
77
  @all_params = options[:all_params] == true
@@ -108,7 +105,7 @@ module IDL
108
105
  end
109
106
 
110
107
  def description
111
- @params.values.inject(@description) {|list, vopt| list.concat(vopt[:description] || []) }
108
+ @params.values.inject(@description) { |list, vopt| list.concat(vopt[:description] || []) }
112
109
  end
113
110
 
114
111
  def define_params(spec = {})
@@ -116,7 +113,7 @@ module IDL
116
113
  when String, Hash
117
114
  define_param(spec)
118
115
  when Array
119
- spec.each {|p| define_param(p) }
116
+ spec.each { |p| define_param(p) }
120
117
  end
121
118
  end
122
119
 
@@ -124,6 +121,7 @@ module IDL
124
121
 
125
122
  def to_key(param)
126
123
  return param if Symbol === param
124
+
127
125
  # convert empty strings to single space strings before symbolizing
128
126
  String === param ? (param.empty? ? ' ' : param).to_sym : nil
129
127
  end
@@ -132,18 +130,18 @@ module IDL
132
130
  case spec
133
131
  when String
134
132
  key = to_key(spec)
135
- @params[key] = { :option_name => key }
133
+ @params[key] = { option_name: key }
136
134
  when Hash
137
135
  spec.each do |k, v|
138
136
  @params[to_key(k)] = (if Hash === v
139
137
  {
140
- :option_name => to_key(v[:option_name] || k),
141
- :option_type => v[:type],
142
- :option_value => v.has_key?(:value) ? v[:value] : true,
143
- :description => Array === v[:description] ? v[:description] : (v[:description] || '').split('\n')
138
+ option_name: to_key(v[:option_name] || k),
139
+ option_type: v[:type],
140
+ option_value: v.has_key?(:value) ? v[:value] : true,
141
+ description: Array === v[:description] ? v[:description] : (v[:description] || '').split('\n')
144
142
  }
145
143
  else
146
- { :option_name => to_key(v) }
144
+ { option_name: to_key(v) }
147
145
  end)
148
146
  end
149
147
  end
@@ -164,6 +162,7 @@ module IDL
164
162
  def define_param_set(id, options = {}, &block)
165
163
  id = id.to_sym
166
164
  raise "option parameter set [#{id}] already exists" if @group.sets.has_key?(id)
165
+
167
166
  @group.sets[id] = ParamSet.new(options)
168
167
  block.call(ParamSet::Configurator.new(@group.sets[id])) if block_given?
169
168
  end
@@ -179,7 +178,7 @@ module IDL
179
178
  alias :modify_params :modify_param_set
180
179
  alias :with_params :modify_param_set
181
180
 
182
- def define_param(id, options={}, &block)
181
+ def define_param(id, options = {}, &block)
183
182
  define_param_set("#{id}_set", options) do |pscfg|
184
183
  pscfg.with(id)
185
184
  pscfg.on_exec(&block)
@@ -193,21 +192,21 @@ module IDL
193
192
  end
194
193
  alias :without_set :without_param
195
194
  alias :without_params :without_param
196
-
197
195
  end # Configurator
198
196
 
199
197
  attr_reader :sets
198
+
200
199
  def initialize(id, options)
201
200
  @test = options[:test] || true
202
201
  @description = Array === options[:description] ? options[:description] : (options[:description] || '').split('\n')
203
202
  @sets = {}
204
203
  if options[:params] && Hash === options[:params]
205
- @sets[id] = ParamSet.new(:params => options[:params])
204
+ @sets[id] = ParamSet.new(params: options[:params])
206
205
  end
207
206
  end
208
207
 
209
208
  def description
210
- @sets.values.inject(@description.dup) {|desc, a| desc.concat(a.description) }
209
+ @sets.values.inject(@description.dup) { |desc, a| desc.concat(a.description) }
211
210
  end
212
211
 
213
212
  def run(arg, options)
@@ -215,6 +214,7 @@ module IDL
215
214
  if self.respond_to?(:_prepare, true)
216
215
  result = _prepare(arg, options)
217
216
  return false unless result && !result.empty?
217
+
218
218
  arg = result.shift
219
219
  ext_args = result
220
220
  else
@@ -232,7 +232,7 @@ module IDL
232
232
  private
233
233
 
234
234
  def handle_sets(param, options, *ext_args)
235
- @sets.values.inject(false) {|f, s| s.run(param, options, *ext_args) || f }
235
+ @sets.values.inject(false) { |f, s| s.run(param, options, *ext_args) || f }
236
236
  end
237
237
  end # Group
238
238
 
@@ -244,6 +244,7 @@ module IDL
244
244
  def define_group(id, options = {}, &block)
245
245
  id = id.to_sym
246
246
  raise "option group [#{id}] already exists" if @option.groups.has_key?(id)
247
+
247
248
  @option.groups[id] = Group.new(id, options)
248
249
  block.call(Group::Configurator.new(@option.groups[id])) if block_given?
249
250
  end
@@ -254,7 +255,7 @@ module IDL
254
255
  parms = options[:params] ? options.delete(:params) : options.delete(:param)
255
256
  @option.groups[id] ||= Group.new(id, options)
256
257
  grpcfg = Group::Configurator.new(@option.groups[id])
257
- grpcfg.modify_param_set(id, :params => parms) if parms
258
+ grpcfg.modify_param_set(id, params: parms) if parms
258
259
  block.call(grpcfg) if block_given?
259
260
  end
260
261
  alias :with_group :modify_group
@@ -264,23 +265,23 @@ module IDL
264
265
  end
265
266
 
266
267
  def define_param_set(id, options = {}, &block)
267
- modify_group :default, {:test => true} do |grpcfg|
268
+ modify_group :default, {test: true} do |grpcfg|
268
269
  grpcfg.define_param_set(id, options, &block)
269
270
  end
270
271
  end
271
272
  alias :for_set :define_param_set
272
273
  alias :for_params :define_param_set
273
274
 
274
- def on_exec(options={}, &block)
275
- modify_group :default, {:test => true} do |grpcfg|
276
- grpcfg.modify_param_set(:default, options.merge({:all_params => true})) do |pscfg|
275
+ def on_exec(options = {}, &block)
276
+ modify_group :default, {test: true} do |grpcfg|
277
+ grpcfg.modify_param_set(:default, options.merge({all_params: true})) do |pscfg|
277
278
  pscfg.on_exec(&block)
278
279
  end
279
280
  end
280
281
  end
281
282
 
282
- def define_param(id, options={}, &block)
283
- modify_group :default, {:test => true} do |grpcfg|
283
+ def define_param(id, options = {}, &block)
284
+ modify_group :default, {test: true} do |grpcfg|
284
285
  grpcfg.define_param_set("#{id}_set", options) do |pscfg|
285
286
  pscfg.with(id)
286
287
  pscfg.on_exec(&block)
@@ -300,10 +301,8 @@ module IDL
300
301
  alias :without_params :without_param
301
302
  end
302
303
 
303
- attr_reader :switch
304
- attr_reader :type
305
- attr_reader :separator
306
- attr_reader :groups
304
+ attr_reader :switch, :type, :separator, :groups
305
+
307
306
  def initialize(switch, options)
308
307
  @switch = switch
309
308
  @type = options[:type] || TrueClass
@@ -313,23 +312,24 @@ module IDL
313
312
  end
314
313
 
315
314
  def description(indent = "")
316
- @groups.values.inject(@description.dup) {|desc, h| desc.concat(h.description.collect {|desc| "\r#{indent} #{desc}"}) }
315
+ @groups.values.inject(@description.dup) { |desc, h| desc.concat(h.description.collect { |desc| "\r#{indent} #{desc}" }) }
317
316
  end
318
317
 
319
318
  def run(arg, options)
320
- unless @groups.values.inject(false) {|f, h| h.run(arg, options) || f }
319
+ unless @groups.values.inject(false) { |f, h| h.run(arg, options) || f }
321
320
  raise ArgumentError, "unknown option [#{arg}] for switch '#{@switch}'"
322
321
  end
323
322
  end
324
323
  end # Option
325
324
 
326
- def initialize()
325
+ def initialize
327
326
  @options = {}
328
327
  end
329
328
 
330
329
  def define_switch(switch, options = {}, &block)
331
330
  switch = switch.to_s
332
331
  raise "switch types mismatch" if @options.has_key?(switch) && options[:type] && options[:type] != @options[switch].type
332
+
333
333
  @options[switch] ||= Option.new(switch, options)
334
334
  block.call(Option::Configurator.new(@options[switch])) if block_given?
335
335
  end
@@ -351,7 +351,5 @@ module IDL
351
351
  optp.separator '' if op.separator
352
352
  end
353
353
  end
354
-
355
354
  end # OptionList
356
-
357
355
  end # IDL
data/lib/ridl/parser.rb CHANGED
@@ -648,7 +648,6 @@ end
648
648
  require 'ridl/delegate'
649
649
 
650
650
  module IDL
651
-
652
651
  class Parser < Racc::Parser
653
652
 
654
653
  module_eval(<<'...end parser.ry/module_eval...', 'parser.ry', 830)
@@ -4247,6 +4246,4 @@ def _reduce_none(val, _values)
4247
4246
  end
4248
4247
 
4249
4248
  end # class Parser
4250
-
4251
-
4252
4249
  end #of module IDL
data/lib/ridl/runner.rb CHANGED
@@ -18,23 +18,21 @@ require 'ridl/options'
18
18
  # -----------------------------------------------------------------------
19
19
 
20
20
  module IDL
21
-
22
21
  OPTIONS = Options.new({
23
- :outputdir => nil,
24
- :includepaths => [],
25
- :xincludepaths => [],
26
- :verbose => (ENV['RIDL_VERBOSE'] || 0).to_i,
27
- :debug => false,
28
- :namespace => nil,
29
- :search_incpath => false,
30
- :backend => nil,
31
- :macros => {
22
+ outputdir: nil,
23
+ includepaths: [],
24
+ xincludepaths: [],
25
+ verbose: (ENV['RIDL_VERBOSE'] || 0).to_i,
26
+ debug: false,
27
+ namespace: nil,
28
+ search_incpath: false,
29
+ backend: nil,
30
+ macros: {
32
31
  }
33
32
  })
34
33
  CORE_OPTIONS = OPTIONS.keys
35
34
 
36
35
  class Engine
37
-
38
36
  class ProductionStack
39
37
  def initialize
40
38
  @stack = []
@@ -56,6 +54,7 @@ module IDL
56
54
 
57
55
  def pop
58
56
  return nil if empty?
57
+
59
58
  id, prod = @stack.shift
60
59
  @index.delete(id)
61
60
  prod
@@ -63,12 +62,14 @@ module IDL
63
62
 
64
63
  def peek
65
64
  return nil if empty?
65
+
66
66
  id, _ = @stack.first
67
67
  id
68
68
  end
69
69
 
70
70
  def remove(id)
71
71
  return nil unless has?(id)
72
+
72
73
  i = @index.delete(id.to_sym)
73
74
  _, producer = @productionstack.delete(i)
74
75
  producer
@@ -129,6 +130,7 @@ module IDL
129
130
 
130
131
  def push_production(id, producer)
131
132
  raise "Producer #{id} already queued" if @productionstack.has?(id)
133
+
132
134
  @productionstack.push(id, producer)
133
135
  end
134
136
 
@@ -183,9 +185,9 @@ module IDL
183
185
  # parse arguments
184
186
  begin
185
187
  @optparser.parse!(argv)
186
- rescue ArgumentError => ex
187
- IDL.error(ex.inspect)
188
- IDL.error(ex.backtrace.join("\n")) if IDL.verbose_level > 0
188
+ rescue ArgumentError => e
189
+ IDL.error(e.inspect)
190
+ IDL.error(e.backtrace.join("\n")) if IDL.verbose_level.positive?
189
191
  return false
190
192
  end
191
193
 
@@ -231,7 +233,7 @@ module IDL
231
233
  # process parse result -> code generation
232
234
  IDL.log(2, 'RIDL - processing input')
233
235
 
234
- GenFile.transaction do
236
+ GenFile.transaction do
235
237
  begin
236
238
 
237
239
  backend.process_input(_parser, _opts)
@@ -250,9 +252,9 @@ module IDL
250
252
  rescue Backend::ProcessStop
251
253
  IDL.log(2, "RIDL - processing #{IO === _idlfile ? 'from STDIN' : (StringIO === _idlfile ? 'from string' : _idlfile)} stopped with \"#{$!.message}\"")
252
254
 
253
- rescue => ex
254
- IDL.error(ex)
255
- IDL.error(ex.backtrace.join("\n")) unless ex.is_a? IDL::ParseError
255
+ rescue => e
256
+ IDL.error(e)
257
+ IDL.error(e.backtrace.join("\n")) unless e.is_a? IDL::ParseError
256
258
  return false
257
259
  end
258
260
  end
@@ -272,9 +274,9 @@ module IDL
272
274
 
273
275
  begin
274
276
  _parser.parse(io)
275
- rescue => ex
276
- IDL.error(ex.inspect)
277
- IDL.error(ex.backtrace.join("\n")) unless ex.is_a? IDL::ParseError
277
+ rescue => e
278
+ IDL.error(e.inspect)
279
+ IDL.error(e.backtrace.join("\n")) unless e.is_a? IDL::ParseError
278
280
  return nil
279
281
  ensure
280
282
  io.close unless String === io || io == $stdin
@@ -328,7 +330,7 @@ module IDL
328
330
 
329
331
  def init_optparser
330
332
  script_name = File.basename($0, '.*')
331
- if not script_name =~ /ridlc/
333
+ unless script_name =~ /ridlc/
332
334
  script_name = 'ruby ' + $0
333
335
  end
334
336
 
@@ -398,11 +400,12 @@ module IDL
398
400
  opts.separator ""
399
401
 
400
402
  opts.on('-h', '--help',
401
- 'Show this help message.') { puts opts; puts; exit }
403
+ 'Show this help message.') { puts opts
404
+ puts
405
+ exit }
402
406
 
403
407
  opts
404
408
  end
405
-
406
409
  end
407
410
 
408
411
  def IDL.engine?
@@ -419,11 +422,13 @@ module IDL
419
422
 
420
423
  def IDL.pop_input
421
424
  return nil unless engine?
425
+
422
426
  Thread.current[:ridl_engine].pop_input
423
427
  end
424
428
 
425
429
  def IDL.peek_input
426
430
  return nil unless engine?
431
+
427
432
  Thread.current[:ridl_engine].peek_input
428
433
  end
429
434
 
@@ -437,11 +442,13 @@ module IDL
437
442
 
438
443
  def IDL.pop_production
439
444
  return nil unless engine?
445
+
440
446
  Thread.current[:ridl_engine].pop_production
441
447
  end
442
448
 
443
449
  def IDL.remove_production(id)
444
450
  return nil unless engine?
451
+
445
452
  Thread.current[:ridl_engine].remove_production(id)
446
453
  end
447
454
 
@@ -455,6 +462,7 @@ module IDL
455
462
 
456
463
  def IDL.production(id)
457
464
  return nil unless engine?
465
+
458
466
  Thread.current[:ridl_engine].production(id)
459
467
  end
460
468
 
@@ -503,7 +511,7 @@ module IDL
503
511
  # add optional search paths for RIDL backends
504
512
  options[:be_path] ||= []
505
513
  options[:be_path].unshift(*ENV['RIDL_BE_PATH'].split(/#{File::PATH_SEPARATOR}/)) if ENV['RIDL_BE_PATH']
506
- options[:be_path].collect! {|p| p.gsub('\\', '/') } # cleanup to prevent mixed path separators
514
+ options[:be_path].collect! { |p| p.gsub('\\', '/') } # cleanup to prevent mixed path separators
507
515
  $:.concat(options[:be_path]) unless options[:be_path].empty?
508
516
 
509
517
  # check for special bootstrapping switches
@@ -527,5 +535,4 @@ module IDL
527
535
  exit(1) unless Thread.current[:ridl_engine].run(argv)
528
536
  end
529
537
  end # IDL.run
530
-
531
538
  end