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.
- checksums.yaml +4 -4
- data/README.rdoc +5 -3
- data/lib/ridl/backend.rb +11 -12
- data/lib/ridl/delegate.rb +88 -58
- data/lib/ridl/expression.rb +65 -27
- data/lib/ridl/genfile.rb +22 -16
- data/lib/ridl/node.rb +325 -185
- data/lib/ridl/options.rb +9 -11
- data/lib/ridl/optparse_ext.rb +32 -34
- data/lib/ridl/parser.rb +0 -3
- data/lib/ridl/runner.rb +33 -26
- data/lib/ridl/scanner.rb +170 -139
- data/lib/ridl/type.rb +113 -13
- data/lib/ridl/version.rb +2 -4
- metadata +2 -2
data/lib/ridl/scanner.rb
CHANGED
@@ -14,10 +14,12 @@ require 'delegate'
|
|
14
14
|
module IDL
|
15
15
|
class ParseError < StandardError
|
16
16
|
attr_reader :positions
|
17
|
+
|
17
18
|
def initialize(msg, positions)
|
18
19
|
super(msg)
|
19
20
|
@positions = positions
|
20
21
|
end
|
22
|
+
|
21
23
|
def inspect
|
22
24
|
puts "#{self.class.name}: #{message}"
|
23
25
|
@positions.each { |pos|
|
@@ -35,6 +37,7 @@ module IDL
|
|
35
37
|
def to_s
|
36
38
|
format('%s: line %d, column %d', name.to_s, line, column)
|
37
39
|
end
|
40
|
+
|
38
41
|
def inspect
|
39
42
|
to_s
|
40
43
|
end
|
@@ -48,15 +51,20 @@ module IDL
|
|
48
51
|
@pos = Position.new(name, line, column)
|
49
52
|
@mark = nil
|
50
53
|
end
|
54
|
+
|
51
55
|
def position
|
52
56
|
@pos
|
53
57
|
end
|
58
|
+
|
54
59
|
def column
|
55
60
|
@pos.column
|
56
61
|
end
|
62
|
+
|
57
63
|
# cursor set at last gotten character.
|
58
64
|
# ex: after initialization, position is (0,0).
|
59
|
-
def to_s
|
65
|
+
def to_s
|
66
|
+
@src.to_s
|
67
|
+
end
|
60
68
|
|
61
69
|
def lookc
|
62
70
|
@fwd
|
@@ -66,8 +74,8 @@ module IDL
|
|
66
74
|
cur = @fwd
|
67
75
|
@fwd = @src.getc unless @src.nil?
|
68
76
|
@mark << cur unless @mark.nil?
|
69
|
-
if [nil,
|
70
|
-
if @bwd ==
|
77
|
+
if [nil, "\n", "\r"].include? @bwd
|
78
|
+
if @bwd == "\r" and cur == "\n"
|
71
79
|
else
|
72
80
|
@pos.line += 1
|
73
81
|
@pos.column = 1
|
@@ -89,28 +97,30 @@ module IDL
|
|
89
97
|
return nil if @fwd.nil?
|
90
98
|
|
91
99
|
s = ''
|
92
|
-
s << getc until [nil,
|
93
|
-
s << getc while [
|
100
|
+
s << getc until [nil, "\n", "\r"].include? lookc
|
101
|
+
s << getc while ["\n", "\r"].include? lookc
|
94
102
|
|
95
103
|
@mark << s unless @mark.nil?
|
96
104
|
s
|
97
105
|
end
|
98
106
|
alias skipc getc
|
99
107
|
|
100
|
-
def skipwhile(*
|
108
|
+
def skipwhile(*_chars, &block)
|
101
109
|
if block
|
102
110
|
until (ch = lookc).nil?
|
103
111
|
return ch unless block.call(ch)
|
112
|
+
|
104
113
|
skipc
|
105
114
|
end
|
106
115
|
end
|
107
116
|
nil
|
108
117
|
end
|
109
118
|
|
110
|
-
def skipuntil(*
|
119
|
+
def skipuntil(*_chars, &block)
|
111
120
|
if block
|
112
121
|
until (ch = lookc).nil?
|
113
122
|
return ch if block.call(ch)
|
123
|
+
|
114
124
|
skipc
|
115
125
|
end
|
116
126
|
end
|
@@ -148,14 +158,17 @@ module IDL
|
|
148
158
|
@src = src
|
149
159
|
@ix = 0
|
150
160
|
end
|
161
|
+
|
151
162
|
def to_s
|
152
163
|
@src
|
153
164
|
end
|
165
|
+
|
154
166
|
def getc
|
155
167
|
ch = @src[@ix]
|
156
168
|
@ix += 1
|
157
169
|
ch
|
158
170
|
end
|
171
|
+
|
159
172
|
def close
|
160
173
|
@ix = 0
|
161
174
|
end
|
@@ -165,15 +178,19 @@ module IDL
|
|
165
178
|
def [](key)
|
166
179
|
super(::Symbol === key ? key : key.to_s.to_sym)
|
167
180
|
end
|
181
|
+
|
168
182
|
def []=(key, val)
|
169
183
|
super(::Symbol === key ? key : key.to_s.to_sym, val.to_s)
|
170
184
|
end
|
185
|
+
|
171
186
|
def has_key?(key)
|
172
187
|
super(::Symbol === key ? key : key.to_s.to_sym)
|
173
188
|
end
|
189
|
+
|
174
190
|
def delete(key)
|
175
191
|
super(::Symbol === key ? key : key.to_s.to_sym)
|
176
192
|
end
|
193
|
+
|
177
194
|
def assoc(key)
|
178
195
|
k_ = (::Symbol === key ? key : key.to_s.to_sym)
|
179
196
|
self.has_key?(k_) ? [k_, self[k_]] : nil
|
@@ -184,6 +201,7 @@ module IDL
|
|
184
201
|
def initialize(table_)
|
185
202
|
@table = table_
|
186
203
|
end
|
204
|
+
|
187
205
|
def [](key)
|
188
206
|
key = (::Integer === key) ? key.chr.to_sym : key.to_sym
|
189
207
|
@table[key]
|
@@ -194,8 +212,8 @@ module IDL
|
|
194
212
|
# to carry both 'raw' IDL name as well as language mapped
|
195
213
|
# name
|
196
214
|
class Identifier < DelegateClass(::String)
|
197
|
-
attr_reader :checked_name
|
198
|
-
|
215
|
+
attr_reader :checked_name, :unescaped_name
|
216
|
+
|
199
217
|
def initialize(idl_id, checked_id, unescaped_idl_id = nil)
|
200
218
|
super(idl_id)
|
201
219
|
@checked_name = checked_id
|
@@ -219,7 +237,7 @@ module IDL
|
|
219
237
|
@defined[name] = value
|
220
238
|
end
|
221
239
|
end
|
222
|
-
@ifdef =
|
240
|
+
@ifdef = []
|
223
241
|
@ifskip = false
|
224
242
|
@ifnest = 0
|
225
243
|
i = nil
|
@@ -241,6 +259,7 @@ module IDL
|
|
241
259
|
@scan_comment = false # true if parsing commented annotation
|
242
260
|
@in_annotation = false # true if parsing annotation
|
243
261
|
end
|
262
|
+
|
244
263
|
def find_include(fname, all = true)
|
245
264
|
if File.file?(fname) && File.readable?(fname)
|
246
265
|
File.expand_path(fname)
|
@@ -261,6 +280,7 @@ module IDL
|
|
261
280
|
fp
|
262
281
|
end
|
263
282
|
end
|
283
|
+
|
264
284
|
def check_include(path, fname)
|
265
285
|
fp = path + fname
|
266
286
|
File.file?(fp) && File.readable?(fp)
|
@@ -282,32 +302,37 @@ module IDL
|
|
282
302
|
# record file dir as new searchpath
|
283
303
|
@xincludepaths << (File.dirname(fpath) + '/')
|
284
304
|
@prefix = nil
|
285
|
-
@ifdef =
|
305
|
+
@ifdef = []
|
286
306
|
@in = In.new(File.open(fpath, 'r'), fpath)
|
287
307
|
@directiver.enter_include(src, fpath)
|
288
308
|
@directiver.pragma_prefix(nil)
|
289
309
|
end
|
290
310
|
end
|
311
|
+
|
291
312
|
def enter_expansion(src, define)
|
292
313
|
IDL.log(2, "** RIDL - enter_expansion > #{define} = #{src}")
|
293
314
|
@stack << [:define, nil, nil, @in, nil]
|
294
315
|
@expansions << define
|
295
316
|
@in = In.new(StrIStream.new(src), @in.position.name, @in.position.line, @in.position.column)
|
296
317
|
end
|
318
|
+
|
297
319
|
def is_expanded?(define)
|
298
320
|
@expansions.include?(define)
|
299
321
|
end
|
322
|
+
|
300
323
|
def more_source?
|
301
|
-
|
324
|
+
!@stack.empty?
|
302
325
|
end
|
326
|
+
|
303
327
|
def in_expansion?
|
304
328
|
more_source? and @stack.last[0] == :define
|
305
329
|
end
|
330
|
+
|
306
331
|
def leave_source
|
307
332
|
# make sure to close the input source
|
308
333
|
@in.close
|
309
334
|
# check if we have any previous source still stacked up
|
310
|
-
|
335
|
+
unless @stack.empty?
|
311
336
|
if @stack.last[0] == :include
|
312
337
|
@xincludepaths.pop # remove directory of finished include
|
313
338
|
@directiver.leave_include
|
@@ -319,48 +344,51 @@ module IDL
|
|
319
344
|
end
|
320
345
|
end
|
321
346
|
end
|
347
|
+
|
322
348
|
def do_parse?
|
323
349
|
@ifdef.empty? || @ifdef.last
|
324
350
|
end
|
351
|
+
|
325
352
|
def positions
|
326
|
-
@stack.reverse.inject(@in.nil? ? [] : [@in.position]) {|pos_arr, (_, _, _, in_, _)| pos_arr << in_.position }
|
353
|
+
@stack.reverse.inject(@in.nil? ? [] : [@in.position]) { |pos_arr, (_, _, _, in_, _)| pos_arr << in_.position }
|
327
354
|
end
|
355
|
+
|
328
356
|
def parse_error(msg, ex = nil)
|
329
357
|
e = IDL::ParseError.new(msg, positions)
|
330
358
|
e.set_backtrace(ex.backtrace) unless ex.nil?
|
331
359
|
raise e
|
332
360
|
end
|
333
361
|
|
334
|
-
LFCR = [ (
|
335
|
-
SPACES = [ (
|
362
|
+
LFCR = [ ("\n"), ("\r") ]
|
363
|
+
SPACES = [ ("\ "), ("\t") ]
|
336
364
|
WHITESPACE = SPACES + LFCR
|
337
365
|
|
338
|
-
ANNOTATION =
|
366
|
+
ANNOTATION = '@'
|
339
367
|
ANNOTATION_STR = '@'
|
340
368
|
|
341
369
|
BREAKCHARS = [
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
SHIFTCHARS = [
|
349
|
-
|
350
|
-
DIGITS = (
|
351
|
-
ALPHA_LC = (
|
352
|
-
ALPHA_UC = (
|
353
|
-
OCTALS = (
|
354
|
-
HEXCHARS = DIGITS + (
|
355
|
-
SIGNS = [
|
356
|
-
DOT =
|
357
|
-
|
358
|
-
IDCHARS = [
|
370
|
+
'(', ')', '[', ']', '{', '}',
|
371
|
+
'^', '~',
|
372
|
+
'*', '%', '&', '|',
|
373
|
+
'<', '=', '>',
|
374
|
+
',', ';' ]
|
375
|
+
|
376
|
+
SHIFTCHARS = [ '<', '>' ]
|
377
|
+
|
378
|
+
DIGITS = ('0'..'9').to_a
|
379
|
+
ALPHA_LC = ('a'..'z').to_a
|
380
|
+
ALPHA_UC = ('A'..'Z').to_a
|
381
|
+
OCTALS = ('0'..'7').to_a
|
382
|
+
HEXCHARS = DIGITS + ('a'..'f').to_a + ('A'..'F').to_a
|
383
|
+
SIGNS = ['-', '+']
|
384
|
+
DOT = '.'
|
385
|
+
|
386
|
+
IDCHARS = ['_' ] + ALPHA_LC + ALPHA_UC
|
359
387
|
FULL_IDCHARS = IDCHARS + DIGITS
|
360
388
|
|
361
389
|
ESCTBL = CharRegistry.new({
|
362
|
-
:
|
363
|
-
:
|
390
|
+
n: "\n", t: "\t", v: "\v", b: "\b",
|
391
|
+
r: "\r", f: "\f", a: "\a"
|
364
392
|
})
|
365
393
|
|
366
394
|
KEYWORDS = %w(
|
@@ -369,7 +397,8 @@ module IDL
|
|
369
397
|
long manages mirrorport module multiple native Object octet oneway out port porttype primarykey private provides
|
370
398
|
public publishes raises readonly setraises sequence short string struct supports switch TRUE truncatable typedef
|
371
399
|
typeid typename typeprefix unsigned union uses ValueBase valuetype void wchar wstring
|
372
|
-
).inject(TokenRegistry.new) { |h, a| h[a.downcase.to_sym] = a
|
400
|
+
).inject(TokenRegistry.new) { |h, a| h[a.downcase.to_sym] = a
|
401
|
+
h }
|
373
402
|
|
374
403
|
LITERALS = [
|
375
404
|
:integer_literal,
|
@@ -379,11 +408,11 @@ module IDL
|
|
379
408
|
# :wide_character_literal,
|
380
409
|
:fixed_pt_literal,
|
381
410
|
:floating_pt_literal,
|
382
|
-
:boolean_literal
|
411
|
+
:boolean_literal]
|
383
412
|
|
384
413
|
BOOL_LITERALS = {
|
385
|
-
:
|
386
|
-
:
|
414
|
+
false: false,
|
415
|
+
true: true
|
387
416
|
}
|
388
417
|
|
389
418
|
def is_literal?(o)
|
@@ -408,7 +437,7 @@ module IDL
|
|
408
437
|
# determin vaue type; if it has a body it is an annotation instance
|
409
438
|
annotation_value = if member_annotation_body
|
410
439
|
{ member_annotation_id => member_annotation_body }
|
411
|
-
else
|
440
|
+
else # otherwise it is a symbolic value
|
412
441
|
member_annotation_id.to_sym
|
413
442
|
end
|
414
443
|
# get next token if needed
|
@@ -439,7 +468,7 @@ module IDL
|
|
439
468
|
token = next_token # ')' (in case of single value annotation) or '='
|
440
469
|
if token.first == ')'
|
441
470
|
parse_error 'invalid annotation member' if annotation_body
|
442
|
-
annotation_body = { :
|
471
|
+
annotation_body = { value: s1 }
|
443
472
|
else
|
444
473
|
parse_error 'invalid annotation member' unless token.first == '='
|
445
474
|
token, annotation_value = extract_annotation_value
|
@@ -479,9 +508,9 @@ module IDL
|
|
479
508
|
if token&.first == :identifier
|
480
509
|
# keyword check
|
481
510
|
if (a = KEYWORDS.assoc(token.last.to_s)).nil?
|
482
|
-
token = [
|
511
|
+
token = [:identifier, Identifier.new(token.last.to_s, chk_identifier(token.last.to_s), token.last.unescaped_name)]
|
483
512
|
elsif token.last == a[1]
|
484
|
-
token = [
|
513
|
+
token = [a[1], nil]
|
485
514
|
else
|
486
515
|
parse_error "'#{token.last}' collides with a keyword '#{a[1]}'"
|
487
516
|
end
|
@@ -494,7 +523,7 @@ module IDL
|
|
494
523
|
end
|
495
524
|
|
496
525
|
def skip_spaces
|
497
|
-
@in.skipwhile {|c| SPACES.include?(c) }
|
526
|
+
@in.skipwhile { |c| SPACES.include?(c) }
|
498
527
|
end
|
499
528
|
|
500
529
|
def next_identifier(first = nil)
|
@@ -511,10 +540,10 @@ module IDL
|
|
511
540
|
s2 = s0.dup # (to be) unescaped id
|
512
541
|
|
513
542
|
# simple check
|
514
|
-
if s2.
|
543
|
+
if s2.empty?
|
515
544
|
parse_error 'identifier expected!'
|
516
545
|
else
|
517
|
-
if s2[0] ==
|
546
|
+
if s2[0] == '_'
|
518
547
|
s2.slice!(0) ## if starts with CORBA IDL escape => remove
|
519
548
|
end
|
520
549
|
parse_error "identifier must begin with alphabet character: #{s2}" unless ALPHA_LC.include?(s2[0]) || ALPHA_UC.include?(s2[0])
|
@@ -529,15 +558,15 @@ module IDL
|
|
529
558
|
# keyword check
|
530
559
|
elsif @in_annotation
|
531
560
|
if BOOL_LITERALS.has_key?(s1)
|
532
|
-
[
|
561
|
+
[:boolean_literal, BOOL_LITERALS[s1]]
|
533
562
|
else
|
534
|
-
[
|
563
|
+
[:identifier, Identifier.new(s2, s2, s0)]
|
535
564
|
end
|
536
565
|
elsif (a = KEYWORDS.assoc(s1)).nil?
|
537
566
|
# check for language mapping keyword
|
538
|
-
[
|
567
|
+
[:identifier, Identifier.new(s2, chk_identifier(s2), s0)]
|
539
568
|
elsif s0 == a[1]
|
540
|
-
[
|
569
|
+
[a[1], nil]
|
541
570
|
else
|
542
571
|
parse_error "'#{s0}' collides with IDL keyword '#{a[1]}'"
|
543
572
|
end
|
@@ -548,12 +577,12 @@ module IDL
|
|
548
577
|
case (ch = @in.getc)
|
549
578
|
when nil
|
550
579
|
parse_error 'illegal escape sequence'
|
551
|
-
when
|
580
|
+
when '0'..'7'
|
552
581
|
ret = ''
|
553
582
|
ret << ch
|
554
583
|
1.upto(2) {
|
555
584
|
ch = @in.lookc
|
556
|
-
if (
|
585
|
+
if ('0'..'7').include? ch
|
557
586
|
ret << ch
|
558
587
|
else
|
559
588
|
break
|
@@ -561,7 +590,7 @@ module IDL
|
|
561
590
|
@in.skipc
|
562
591
|
}
|
563
592
|
ret = ret.oct
|
564
|
-
when
|
593
|
+
when 'x' # i'm not sure '\x' should be 0 or 'x'. currently returns 0.
|
565
594
|
ret = ''
|
566
595
|
1.upto(2) {
|
567
596
|
ch = @in.lookc
|
@@ -573,7 +602,7 @@ module IDL
|
|
573
602
|
@in.skipc
|
574
603
|
}
|
575
604
|
ret = ret.hex
|
576
|
-
when
|
605
|
+
when 'u'
|
577
606
|
ret = ''
|
578
607
|
1.upto(4) {
|
579
608
|
ch = @in.lookc
|
@@ -585,7 +614,7 @@ module IDL
|
|
585
614
|
@in.skipc
|
586
615
|
}
|
587
616
|
ret = ret.hex
|
588
|
-
when
|
617
|
+
when 'n', 't', 'v', 'b', 'r', 'f', 'a'
|
589
618
|
ret = ESCTBL[ch]
|
590
619
|
else
|
591
620
|
ret = ('' << ch).unpack('C').first
|
@@ -598,12 +627,12 @@ module IDL
|
|
598
627
|
case (ch = @in.getc)
|
599
628
|
when nil
|
600
629
|
parse_error 'illegal escape sequence'
|
601
|
-
when
|
630
|
+
when '0'..'7'
|
602
631
|
ret = ''
|
603
632
|
ret << ch
|
604
633
|
1.upto(2) {
|
605
634
|
ch = @in.lookc
|
606
|
-
if (
|
635
|
+
if ('0'..'7').include? ch
|
607
636
|
ret << ch
|
608
637
|
else
|
609
638
|
break
|
@@ -611,7 +640,7 @@ module IDL
|
|
611
640
|
@in.skipc
|
612
641
|
}
|
613
642
|
ret = [ :oct, ret ]
|
614
|
-
when
|
643
|
+
when 'x' # i'm not sure '\x' should be 0 or 'x'. currently returns 0.
|
615
644
|
ret = ''
|
616
645
|
ret << ch if keep_type_ch
|
617
646
|
1.upto(2) {
|
@@ -624,7 +653,7 @@ module IDL
|
|
624
653
|
@in.skipc
|
625
654
|
}
|
626
655
|
ret = [ :hex2, ret ]
|
627
|
-
when
|
656
|
+
when 'u'
|
628
657
|
ret = ''
|
629
658
|
ret << ch if keep_type_ch
|
630
659
|
1.upto(4) {
|
@@ -637,14 +666,14 @@ module IDL
|
|
637
666
|
@in.skipc
|
638
667
|
}
|
639
668
|
ret = [ :hex4, ret ]
|
640
|
-
when
|
669
|
+
when 'n', 't', 'v', 'b', 'r', 'f', 'a'
|
641
670
|
ret = ''
|
642
671
|
ret << ch
|
643
|
-
ret = [
|
672
|
+
ret = [:esc, ret]
|
644
673
|
else
|
645
674
|
ret = ''
|
646
675
|
ret << ch
|
647
|
-
ret = [
|
676
|
+
ret = [:esc_ch, ch]
|
648
677
|
end
|
649
678
|
ret
|
650
679
|
end
|
@@ -652,17 +681,17 @@ module IDL
|
|
652
681
|
def skipfloat_or_fixed
|
653
682
|
if @in.lookc == DOT
|
654
683
|
@in.skipc
|
655
|
-
@in.skipwhile {|c| DIGITS.include?(c) }
|
684
|
+
@in.skipwhile { |c| DIGITS.include?(c) }
|
656
685
|
end
|
657
|
-
if [
|
686
|
+
if ['e', 'E'].include? @in.lookc
|
658
687
|
@in.skipc
|
659
688
|
@in.skipc if SIGNS.include? @in.lookc
|
660
|
-
@in.skipwhile {|c| DIGITS.include?(c) }
|
689
|
+
@in.skipwhile { |c| DIGITS.include?(c) }
|
661
690
|
return :floating_pt_literal
|
662
|
-
elsif [
|
691
|
+
elsif ['d', 'D'].include? @in.lookc
|
663
692
|
@in.skipc
|
664
693
|
@in.skipc if SIGNS.include? @in.lookc
|
665
|
-
@in.skipwhile {|c| DIGITS.include?(c) }
|
694
|
+
@in.skipwhile { |c| DIGITS.include?(c) }
|
666
695
|
return :fixed_pt_literal
|
667
696
|
end
|
668
697
|
:floating_pt_literal
|
@@ -672,7 +701,7 @@ module IDL
|
|
672
701
|
while true
|
673
702
|
s = @in.gets
|
674
703
|
until s.chomp!.nil?; end
|
675
|
-
break unless s[s.length - 1] ==
|
704
|
+
break unless s[s.length - 1] == "\\"
|
676
705
|
end
|
677
706
|
end
|
678
707
|
|
@@ -681,16 +710,17 @@ module IDL
|
|
681
710
|
while true
|
682
711
|
ch = @in.lookc
|
683
712
|
break if ch.nil?
|
713
|
+
|
684
714
|
case
|
685
|
-
when (ch ==
|
715
|
+
when (ch == "\"") # "
|
686
716
|
s << @in.getc # opening quote
|
687
717
|
while true
|
688
|
-
if @in.lookc ==
|
718
|
+
if @in.lookc == "\\"
|
689
719
|
# escape sequence
|
690
720
|
s << @in.getc
|
691
721
|
_, escstr = next_escape_str(true)
|
692
722
|
s << escstr
|
693
|
-
elsif @in.lookc ==
|
723
|
+
elsif @in.lookc == "\"" # "
|
694
724
|
break
|
695
725
|
elsif @in.lookc
|
696
726
|
# normal character
|
@@ -700,36 +730,36 @@ module IDL
|
|
700
730
|
end
|
701
731
|
end
|
702
732
|
s << @in.getc # closing quote
|
703
|
-
when (ch ==
|
733
|
+
when (ch == "\'") # ' # quoted character
|
704
734
|
s << @in.getc # opening quote
|
705
|
-
if @in.lookc ==
|
735
|
+
if @in.lookc == "\\"
|
706
736
|
# escape sequence
|
707
737
|
s << @in.getc
|
708
738
|
_, escstr = next_escape_str(true)
|
709
739
|
s << escstr
|
710
|
-
elsif @in.lookc && @in.lookc !=
|
740
|
+
elsif @in.lookc && @in.lookc != "\'" # '
|
711
741
|
# normal character
|
712
742
|
s << @in.getc
|
713
743
|
end
|
714
|
-
if @in.lookc !=
|
744
|
+
if @in.lookc != "\'" # '
|
715
745
|
parse_error "character literal must be single character enclosed in \"'\""
|
716
746
|
end
|
717
747
|
s << @in.getc # closing quote
|
718
748
|
when LFCR.include?(ch)
|
719
749
|
@in.skipwhile { |ch_| LFCR.include? ch_ }
|
720
750
|
break
|
721
|
-
when ch ==
|
751
|
+
when ch == '/'
|
722
752
|
@in.skipc
|
723
|
-
if @in.lookc ==
|
753
|
+
if @in.lookc == '/'
|
724
754
|
# //-style comment; skip till eol
|
725
755
|
@in.gets
|
726
756
|
break
|
727
|
-
elsif @in.lookc ==
|
757
|
+
elsif @in.lookc == '*'
|
728
758
|
# /*...*/ style comment; skip comment
|
729
759
|
ch1 = nil
|
730
760
|
@in.skipuntil { |ch_|
|
731
761
|
ch0 = ch1; ch1 = ch_
|
732
|
-
ch0 ==
|
762
|
+
ch0 == '*' and ch1 == '/' #
|
733
763
|
}
|
734
764
|
if @in.lookc.nil?
|
735
765
|
parse_error "cannot find comment closing brace (\'*/\'). "
|
@@ -738,7 +768,7 @@ module IDL
|
|
738
768
|
else
|
739
769
|
s << ch
|
740
770
|
end
|
741
|
-
when ch ==
|
771
|
+
when ch == "\\"
|
742
772
|
@in.skipc
|
743
773
|
if LFCR.include?(@in.lookc)
|
744
774
|
# line continuation
|
@@ -759,6 +789,7 @@ module IDL
|
|
759
789
|
|
760
790
|
def resolve_define(id, stack = [])
|
761
791
|
return id if %w(true false).include?(id)
|
792
|
+
|
762
793
|
IDL.log(3, "*** RIDL - resolve_define(#{id})")
|
763
794
|
if @defined.has_key?(id)
|
764
795
|
define_ = @defined[id]
|
@@ -785,10 +816,11 @@ module IDL
|
|
785
816
|
end
|
786
817
|
|
787
818
|
def parse_directive
|
788
|
-
@in.skipwhile {|c| SPACES.include?(c) }
|
819
|
+
@in.skipwhile { |c| SPACES.include?(c) }
|
789
820
|
s = getline
|
790
821
|
/^(\w*)\s*/ === s
|
791
|
-
s1
|
822
|
+
s1 = $1
|
823
|
+
s2 = $' # '
|
792
824
|
|
793
825
|
if /(else|endif|elif)/ === s1
|
794
826
|
|
@@ -797,7 +829,7 @@ module IDL
|
|
797
829
|
end
|
798
830
|
case s1
|
799
831
|
when 'else'
|
800
|
-
if @ifnest
|
832
|
+
if @ifnest.zero?
|
801
833
|
if @ifskip # true branch has already been parsed
|
802
834
|
@ifdef[@ifdef.size - 1] = false
|
803
835
|
else
|
@@ -806,14 +838,14 @@ module IDL
|
|
806
838
|
end
|
807
839
|
end
|
808
840
|
when 'endif'
|
809
|
-
if @ifnest
|
841
|
+
if @ifnest.zero?
|
810
842
|
@ifdef.pop
|
811
843
|
@ifskip = @ifdef.last
|
812
844
|
else
|
813
845
|
@ifnest -= 1
|
814
846
|
end
|
815
847
|
else
|
816
|
-
if @ifnest
|
848
|
+
if @ifnest.zero?
|
817
849
|
if @ifskip || @ifdef[@ifdef.size - 1]
|
818
850
|
# true branch has already been parsed so skip from now on
|
819
851
|
@ifdef[@ifdef.size - 1] = false
|
@@ -829,9 +861,9 @@ module IDL
|
|
829
861
|
@ifskip = @ifdef[@ifdef.size - 1]
|
830
862
|
rescue IDL::ParseError
|
831
863
|
raise
|
832
|
-
rescue =>
|
833
|
-
p
|
834
|
-
puts
|
864
|
+
rescue => e
|
865
|
+
p e
|
866
|
+
puts e.backtrace.join("\n")
|
835
867
|
parse_error 'error evaluating #elif'
|
836
868
|
end
|
837
869
|
end
|
@@ -865,9 +897,9 @@ module IDL
|
|
865
897
|
@ifskip = @ifdef.last
|
866
898
|
rescue IDL::ParseError
|
867
899
|
raise
|
868
|
-
rescue =>
|
869
|
-
p
|
870
|
-
puts
|
900
|
+
rescue => e
|
901
|
+
p e
|
902
|
+
puts e.backtrace.join("\n")
|
871
903
|
parse_error 'error evaluating #if'
|
872
904
|
end
|
873
905
|
else
|
@@ -930,17 +962,17 @@ module IDL
|
|
930
962
|
end
|
931
963
|
|
932
964
|
def next_token_before_eol
|
933
|
-
@in.skipwhile {|c| SPACES.include?(c)}
|
965
|
+
@in.skipwhile { |c| SPACES.include?(c) }
|
934
966
|
LFCR.include?(@in.lookc) ? nil : next_token
|
935
967
|
end
|
936
968
|
|
937
969
|
def next_token
|
938
970
|
sign = nil
|
939
|
-
str = '' #initialize empty string
|
971
|
+
str = '' # initialize empty string
|
940
972
|
while true
|
941
973
|
ch = @in.getc
|
942
974
|
if ch.nil?
|
943
|
-
if
|
975
|
+
if !@ifdef.empty? and !in_expansion?
|
944
976
|
parse_error 'mismatched #if/#endif'
|
945
977
|
end
|
946
978
|
if more_source?
|
@@ -952,11 +984,11 @@ module IDL
|
|
952
984
|
end
|
953
985
|
|
954
986
|
if WHITESPACE.include? ch
|
955
|
-
@in.skipwhile {|c| WHITESPACE.include?(c) }
|
987
|
+
@in.skipwhile { |c| WHITESPACE.include?(c) }
|
956
988
|
next
|
957
989
|
end
|
958
990
|
|
959
|
-
if str.empty? && ch ==
|
991
|
+
if str.empty? && ch == "\#"
|
960
992
|
parse_directive
|
961
993
|
next
|
962
994
|
end
|
@@ -982,50 +1014,50 @@ module IDL
|
|
982
1014
|
return parse_annotation || next_token
|
983
1015
|
end
|
984
1016
|
|
985
|
-
when ch ==
|
986
|
-
if @in.lookc ==
|
1017
|
+
when ch == ':' #
|
1018
|
+
if @in.lookc == ':' #
|
987
1019
|
@in.skipc
|
988
1020
|
return %w(:: ::)
|
989
1021
|
else
|
990
1022
|
return %w(: :)
|
991
1023
|
end
|
992
1024
|
|
993
|
-
when ch ==
|
1025
|
+
when ch == 'L'
|
994
1026
|
_nxtc = @in.lookc
|
995
|
-
if _nxtc ==
|
1027
|
+
if _nxtc == "\'" # ' #single quote, for a character literal.
|
996
1028
|
@in.skipc # skip 'L'
|
997
1029
|
_nxtc = @in.lookc
|
998
|
-
ret = if _nxtc ==
|
1030
|
+
ret = if _nxtc == "\\"
|
999
1031
|
@in.skipc
|
1000
1032
|
next_escape_str
|
1001
|
-
elsif _nxtc ==
|
1033
|
+
elsif _nxtc == "\'" # '
|
1002
1034
|
[ nil, nil ]
|
1003
1035
|
else
|
1004
|
-
[
|
1036
|
+
[:char, '' << @in.getc]
|
1005
1037
|
end
|
1006
1038
|
|
1007
|
-
if @in.lookc !=
|
1039
|
+
if @in.lookc != "\'" # '
|
1008
1040
|
parse_error "wide character literal must be single wide character enclosed in \"'\""
|
1009
1041
|
end
|
1010
1042
|
|
1011
1043
|
@in.skipc
|
1012
|
-
return [
|
1044
|
+
return [:wide_character_literal, ret]
|
1013
1045
|
|
1014
|
-
elsif _nxtc ==
|
1046
|
+
elsif _nxtc == "\"" # " #double quote, for a string literal.
|
1015
1047
|
ret = []
|
1016
1048
|
chs = ''
|
1017
1049
|
@in.skipc # skip 'L'
|
1018
1050
|
while true
|
1019
1051
|
_nxtc = @in.lookc
|
1020
|
-
if _nxtc ==
|
1052
|
+
if _nxtc == "\\"
|
1021
1053
|
@in.skipc
|
1022
1054
|
ret << [:char, chs] unless chs.empty?
|
1023
1055
|
chs = ''
|
1024
1056
|
ret << next_escape_str
|
1025
|
-
elsif _nxtc ==
|
1057
|
+
elsif _nxtc == "\"" # "
|
1026
1058
|
@in.skipc
|
1027
1059
|
ret << [:char, chs] unless chs.empty?
|
1028
|
-
return [
|
1060
|
+
return [:wide_string_literal, ret]
|
1029
1061
|
else
|
1030
1062
|
chs << @in.getc
|
1031
1063
|
end
|
@@ -1038,15 +1070,15 @@ module IDL
|
|
1038
1070
|
when IDCHARS.include?(ch)
|
1039
1071
|
return next_identifier(ch)
|
1040
1072
|
|
1041
|
-
when ch ==
|
1073
|
+
when ch == '/' #
|
1042
1074
|
_nxtc = @in.lookc
|
1043
|
-
if _nxtc ==
|
1075
|
+
if _nxtc == '*'
|
1044
1076
|
# skip comment like a `/* ... */'
|
1045
1077
|
@in.skipc # forward stream beyond `/*'
|
1046
1078
|
ch1 = nil
|
1047
1079
|
@in.skipuntil { |ch_|
|
1048
1080
|
ch0 = ch1; ch1 = ch_
|
1049
|
-
ch0 ==
|
1081
|
+
ch0 == '*' and ch1 == '/' #
|
1050
1082
|
}
|
1051
1083
|
if @in.lookc.nil?
|
1052
1084
|
parse_error "cannot find comment closing brace (\'*/\'). "
|
@@ -1055,17 +1087,17 @@ module IDL
|
|
1055
1087
|
str = '' # reset
|
1056
1088
|
next
|
1057
1089
|
|
1058
|
-
elsif _nxtc ==
|
1090
|
+
elsif _nxtc == '/'
|
1059
1091
|
# skip comment like a `// ...\n'
|
1060
1092
|
@in.skipc
|
1061
|
-
unless @scan_comment
|
1093
|
+
unless @scan_comment # scan_comment will be true when parsing commented annotations
|
1062
1094
|
_nxtc = @in.lookc
|
1063
1095
|
if _nxtc == ANNOTATION
|
1064
1096
|
@in.skipc
|
1065
1097
|
# return token returned by parse_annotation or parse next token recursively
|
1066
1098
|
return parse_annotation(true) || next_token
|
1067
1099
|
else
|
1068
|
-
@in.skipuntil {|c| LFCR.include?(c) }
|
1100
|
+
@in.skipuntil { |c| LFCR.include?(c) }
|
1069
1101
|
end
|
1070
1102
|
end
|
1071
1103
|
str = '' # reset
|
@@ -1085,10 +1117,10 @@ module IDL
|
|
1085
1117
|
return [str, str]
|
1086
1118
|
end
|
1087
1119
|
|
1088
|
-
when (
|
1120
|
+
when ('1'..'9').include?(ch)
|
1089
1121
|
@in.mark(sign, ch)
|
1090
|
-
@in.skipwhile {|c| DIGITS.include?(c) }
|
1091
|
-
num_type = ([
|
1122
|
+
@in.skipwhile { |c| DIGITS.include?(c) }
|
1123
|
+
num_type = (['.', 'e', 'E', 'd', 'D'].include?(@in.lookc)) ? skipfloat_or_fixed : :integer_literal
|
1092
1124
|
|
1093
1125
|
r = @in.getregion
|
1094
1126
|
|
@@ -1102,7 +1134,7 @@ module IDL
|
|
1102
1134
|
|
1103
1135
|
when ch == DOT #
|
1104
1136
|
@in.mark(ch)
|
1105
|
-
@in.skipwhile {|c| DIGITS.include?(c) }
|
1137
|
+
@in.skipwhile { |c| DIGITS.include?(c) }
|
1106
1138
|
num_type = (DOT != @in.lookc) ? skipfloat_or_fixed : nil
|
1107
1139
|
s = @in.getregion
|
1108
1140
|
if s == '.'
|
@@ -1116,24 +1148,24 @@ module IDL
|
|
1116
1148
|
parse_error 'invalid floating point constant.'
|
1117
1149
|
end
|
1118
1150
|
|
1119
|
-
when ch ==
|
1151
|
+
when ch == '0'
|
1120
1152
|
@in.mark(sign, ch)
|
1121
1153
|
|
1122
1154
|
_nxtc = @in.lookc
|
1123
|
-
if _nxtc ==
|
1155
|
+
if _nxtc == 'x' || _nxtc == 'X'
|
1124
1156
|
@in.skipc
|
1125
1157
|
@in.skipwhile { |ch_| HEXCHARS.include? ch_ }
|
1126
1158
|
s = @in.getregion
|
1127
1159
|
return [:integer_literal, s.hex]
|
1128
1160
|
else
|
1129
1161
|
dec = false
|
1130
|
-
@in.skipwhile {|c| OCTALS.include?(c) }
|
1131
|
-
if (
|
1162
|
+
@in.skipwhile { |c| OCTALS.include?(c) }
|
1163
|
+
if ('8'..'9').include? @in.lookc
|
1132
1164
|
dec = TRUE
|
1133
|
-
@in.skipwhile {|c| DIGITS.include?(c) }
|
1165
|
+
@in.skipwhile { |c| DIGITS.include?(c) }
|
1134
1166
|
end
|
1135
1167
|
|
1136
|
-
num_type = ([
|
1168
|
+
num_type = (['.', 'e', 'E', 'd', 'D'].include?(@in.lookc)) ? skipfloat_or_fixed : :integer_literal
|
1137
1169
|
|
1138
1170
|
s = @in.getregion
|
1139
1171
|
ret = if num_type == :floating_pt_literal
|
@@ -1148,34 +1180,34 @@ module IDL
|
|
1148
1180
|
return ret
|
1149
1181
|
end
|
1150
1182
|
|
1151
|
-
when ch ==
|
1183
|
+
when ch == "\'" # ' #single quote, for a character literal.
|
1152
1184
|
_nxtc = @in.lookc
|
1153
|
-
ret = if _nxtc ==
|
1185
|
+
ret = if _nxtc == "\\"
|
1154
1186
|
@in.skipc
|
1155
1187
|
next_escape
|
1156
|
-
elsif _nxtc ==
|
1188
|
+
elsif _nxtc == "\'" # '
|
1157
1189
|
0
|
1158
1190
|
elsif _nxtc
|
1159
1191
|
('' << @in.getc).unpack('C').first
|
1160
1192
|
end
|
1161
1193
|
|
1162
|
-
if @in.lookc !=
|
1194
|
+
if @in.lookc != "\'" # '
|
1163
1195
|
parse_error "character literal must be single character enclosed in \"'\""
|
1164
1196
|
end
|
1165
1197
|
|
1166
1198
|
@in.skipc
|
1167
|
-
return [
|
1199
|
+
return [:character_literal, ret]
|
1168
1200
|
|
1169
|
-
when ch ==
|
1201
|
+
when ch == "\"" # " #double quote, for a string literal.
|
1170
1202
|
ret = ''
|
1171
1203
|
while true
|
1172
1204
|
_nxtc = @in.lookc
|
1173
|
-
if _nxtc ==
|
1205
|
+
if _nxtc == "\\"
|
1174
1206
|
@in.skipc
|
1175
1207
|
ret << next_escape
|
1176
|
-
elsif _nxtc ==
|
1208
|
+
elsif _nxtc == "\"" # "
|
1177
1209
|
@in.skipc
|
1178
|
-
return [
|
1210
|
+
return [:string_literal, ret]
|
1179
1211
|
elsif _nxtc
|
1180
1212
|
ret << @in.getc
|
1181
1213
|
else
|
@@ -1186,11 +1218,10 @@ module IDL
|
|
1186
1218
|
else
|
1187
1219
|
parse_error 'illegal character [' << ch << ']'
|
1188
1220
|
|
1189
|
-
end #of case
|
1221
|
+
end # of case
|
1190
1222
|
|
1191
|
-
end #of while
|
1223
|
+
end # of while
|
1192
1224
|
parse_error 'unexcepted error'
|
1193
|
-
end #of method next_token
|
1225
|
+
end # of method next_token
|
1194
1226
|
end
|
1195
|
-
|
1196
1227
|
end
|