cddlc 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee5782e163037658b00ecdca15da1a80d779406426f98a25e2d88888f713fd3b
4
- data.tar.gz: fa784df9fbf17c6ed73108f6dc139771edb46d21fae1276d935deba15580a2dc
3
+ metadata.gz: d9a2b5efd82c91f2fc158bfffdb79adc0c2cd31def11dccb6ec986c61985556f
4
+ data.tar.gz: 8c663966329be0e8b0648c794c9be4e9af773ed2072dae35080c0182db9957ad
5
5
  SHA512:
6
- metadata.gz: d146016f0cc89d76678b737920898f599346bfe342b01e42af79f6a2f20c7dd986ed22b4239097f54f80e685e60de1d4735342315b99fbd014a632af82ff70e4
7
- data.tar.gz: 05cfab1f81f76fda3882ec8b10d2952df94c41bba86de4f9fbc3285b20a2bf01a45dc6a6641c478a8dbcf91a0c2d90adee2669fa7717469e42318ce380e320c7
6
+ metadata.gz: 45eb92c7c2f2185cabcdbf49d869ea31dceef60f45fbafb3bccc2c31a57cde096e62a10542b8e389618c4db31d33734201075fc9ec7235b21ced54e0823ea855
7
+ data.tar.gz: 2e1d13a69f257316054ac9866082d12f39289c587ec0049a7be5ccc89abba187ae64012e2e14a0a0d62473e92a2681dd5109105c8bd8e3e8a6f502dfaab2b634
data/bin/cddlc CHANGED
@@ -64,7 +64,7 @@ begin
64
64
  opts.on("-2", "--[no-]cddl2", "Perform some CDDL 2.0 processing") do |v|
65
65
  $options.cddl2 = v
66
66
  end
67
- opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :enum, :cddl], "Target format") do |v|
67
+ opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :const, :enum, :cddl], "Target format") do |v|
68
68
  $options.target = v
69
69
  end
70
70
  opts.on("-sRULE", "--start=RULE", String, "Start rule name") do |v|
@@ -152,6 +152,9 @@ when :neat, :json
152
152
  puts JSON.neat_generate(result, after_comma: 1, after_colon: 1)
153
153
  when :yaml
154
154
  puts result.to_yaml
155
+ when :const
156
+ require_relative "../lib/processor/cddl-constants.rb"
157
+ puts cddl.extract_constants.to_yaml
155
158
  when :enum
156
159
  rules = cddl.rules
157
160
  rules.each do |k, v|
data/cddlc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cddlc"
3
- s.version = "0.2.4"
3
+ s.version = "0.2.6"
4
4
  s.summary = "CDDL (Concise Data Definition Language) converters and miscellaneous tools"
5
5
  s.description = %q{cddlc implements converters and miscellaneous tools for CDDL, RFC 8610}
6
6
  s.author = "Carsten Bormann"
@@ -3185,7 +3185,14 @@ module CDDLGRAMMAR
3185
3185
  end
3186
3186
 
3187
3187
  module SESC2
3188
- def ast() JSON.load("\"\\#{elements[1].text_value}\"") end
3188
+ def ast
3189
+ tv = elements[1].text_value
3190
+ if /\Au\{(\h+)\}/ =~ tv
3191
+ $1.hex.chr(Encoding::UTF_8)
3192
+ else
3193
+ JSON.load("\"\\#{tv}\"")
3194
+ end
3195
+ end
3189
3196
  end
3190
3197
 
3191
3198
  def _nt_SESC
@@ -3350,6 +3357,12 @@ module CDDLGRAMMAR
3350
3357
  end
3351
3358
 
3352
3359
  module Hexchar0
3360
+ end
3361
+
3362
+ module Hexchar1
3363
+ end
3364
+
3365
+ module Hexchar2
3353
3366
  def high_surrogate
3354
3367
  elements[0]
3355
3368
  end
@@ -3371,51 +3384,138 @@ module CDDLGRAMMAR
3371
3384
  end
3372
3385
 
3373
3386
  i0 = index
3374
- r1 = _nt_non_surrogate
3375
- if r1
3376
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
3377
- r0 = r1
3387
+ i1, s1 = index, []
3388
+ if (match_len = has_terminal?("{", false, index))
3389
+ r2 = true
3390
+ @index += match_len
3378
3391
  else
3379
- i2, s2 = index, []
3380
- r3 = _nt_high_surrogate
3381
- s2 << r3
3392
+ terminal_parse_failure('"{"')
3393
+ r2 = nil
3394
+ end
3395
+ s1 << r2
3396
+ if r2
3397
+ i3 = index
3398
+ i4, s4 = index, []
3399
+ s5, i5 = [], index
3400
+ loop do
3401
+ if (match_len = has_terminal?("0", false, index))
3402
+ r6 = true
3403
+ @index += match_len
3404
+ else
3405
+ terminal_parse_failure('"0"')
3406
+ r6 = nil
3407
+ end
3408
+ if r6
3409
+ s5 << r6
3410
+ else
3411
+ break
3412
+ end
3413
+ end
3414
+ if s5.empty?
3415
+ @index = i5
3416
+ r5 = nil
3417
+ else
3418
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
3419
+ end
3420
+ s4 << r5
3421
+ if r5
3422
+ r8 = _nt_hexscalar
3423
+ if r8
3424
+ r7 = r8
3425
+ else
3426
+ r7 = instantiate_node(SyntaxNode,input, index...index)
3427
+ end
3428
+ s4 << r7
3429
+ end
3430
+ if s4.last
3431
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
3432
+ r4.extend(Hexchar0)
3433
+ else
3434
+ @index = i4
3435
+ r4 = nil
3436
+ end
3437
+ if r4
3438
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
3439
+ r3 = r4
3440
+ else
3441
+ r9 = _nt_hexscalar
3442
+ if r9
3443
+ r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
3444
+ r3 = r9
3445
+ else
3446
+ @index = i3
3447
+ r3 = nil
3448
+ end
3449
+ end
3450
+ s1 << r3
3382
3451
  if r3
3383
- if (match_len = has_terminal?("\\", false, index))
3384
- r4 = true
3452
+ if (match_len = has_terminal?("}", false, index))
3453
+ r10 = true
3385
3454
  @index += match_len
3386
3455
  else
3387
- terminal_parse_failure('"\\\\"')
3388
- r4 = nil
3456
+ terminal_parse_failure('"}"')
3457
+ r10 = nil
3389
3458
  end
3390
- s2 << r4
3391
- if r4
3392
- if (match_len = has_terminal?("u", false, index))
3393
- r5 = true
3459
+ s1 << r10
3460
+ end
3461
+ end
3462
+ if s1.last
3463
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
3464
+ r1.extend(Hexchar1)
3465
+ else
3466
+ @index = i1
3467
+ r1 = nil
3468
+ end
3469
+ if r1
3470
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
3471
+ r0 = r1
3472
+ else
3473
+ r11 = _nt_non_surrogate
3474
+ if r11
3475
+ r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
3476
+ r0 = r11
3477
+ else
3478
+ i12, s12 = index, []
3479
+ r13 = _nt_high_surrogate
3480
+ s12 << r13
3481
+ if r13
3482
+ if (match_len = has_terminal?("\\", false, index))
3483
+ r14 = true
3394
3484
  @index += match_len
3395
3485
  else
3396
- terminal_parse_failure('"u"')
3397
- r5 = nil
3486
+ terminal_parse_failure('"\\\\"')
3487
+ r14 = nil
3398
3488
  end
3399
- s2 << r5
3400
- if r5
3401
- r6 = _nt_low_surrogate
3402
- s2 << r6
3489
+ s12 << r14
3490
+ if r14
3491
+ if (match_len = has_terminal?("u", false, index))
3492
+ r15 = true
3493
+ @index += match_len
3494
+ else
3495
+ terminal_parse_failure('"u"')
3496
+ r15 = nil
3497
+ end
3498
+ s12 << r15
3499
+ if r15
3500
+ r16 = _nt_low_surrogate
3501
+ s12 << r16
3502
+ end
3403
3503
  end
3404
3504
  end
3405
- end
3406
- if s2.last
3407
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
3408
- r2.extend(Hexchar0)
3409
- else
3410
- @index = i2
3411
- r2 = nil
3412
- end
3413
- if r2
3414
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
3415
- r0 = r2
3416
- else
3417
- @index = i0
3418
- r0 = nil
3505
+ if s12.last
3506
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
3507
+ r12.extend(Hexchar2)
3508
+ else
3509
+ @index = i12
3510
+ r12 = nil
3511
+ end
3512
+ if r12
3513
+ r12 = SyntaxNode.new(input, (index-1)...index) if r12 == true
3514
+ r0 = r12
3515
+ else
3516
+ @index = i0
3517
+ r0 = nil
3518
+ end
3419
3519
  end
3420
3520
  end
3421
3521
 
@@ -3840,6 +3940,152 @@ module CDDLGRAMMAR
3840
3940
  r0
3841
3941
  end
3842
3942
 
3943
+ module Hexscalar0
3944
+ end
3945
+
3946
+ module Hexscalar1
3947
+ def HEXDIG1
3948
+ elements[0]
3949
+ end
3950
+
3951
+ end
3952
+
3953
+ def _nt_hexscalar
3954
+ start_index = index
3955
+ if node_cache[:hexscalar].has_key?(index)
3956
+ cached = node_cache[:hexscalar][index]
3957
+ if cached
3958
+ node_cache[:hexscalar][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
3959
+ @index = cached.interval.end
3960
+ end
3961
+ return cached
3962
+ end
3963
+
3964
+ i0 = index
3965
+ i1, s1 = index, []
3966
+ if (match_len = has_terminal?("10", false, index))
3967
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
3968
+ @index += match_len
3969
+ else
3970
+ terminal_parse_failure('"10"')
3971
+ r2 = nil
3972
+ end
3973
+ s1 << r2
3974
+ if r2
3975
+ s3, i3 = [], index
3976
+ loop do
3977
+ r4 = _nt_HEXDIG
3978
+ if r4
3979
+ s3 << r4
3980
+ else
3981
+ break
3982
+ end
3983
+ if s3.size == 4
3984
+ break
3985
+ end
3986
+ end
3987
+ if s3.size < 4
3988
+ @index = i3
3989
+ r3 = nil
3990
+ else
3991
+ if s3.size < 4
3992
+ @terminal_failures.pop
3993
+ end
3994
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
3995
+ end
3996
+ s1 << r3
3997
+ end
3998
+ if s1.last
3999
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
4000
+ r1.extend(Hexscalar0)
4001
+ else
4002
+ @index = i1
4003
+ r1 = nil
4004
+ end
4005
+ if r1
4006
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
4007
+ r0 = r1
4008
+ else
4009
+ i5, s5 = index, []
4010
+ r6 = _nt_HEXDIG1
4011
+ s5 << r6
4012
+ if r6
4013
+ s7, i7 = [], index
4014
+ loop do
4015
+ r8 = _nt_HEXDIG
4016
+ if r8
4017
+ s7 << r8
4018
+ else
4019
+ break
4020
+ end
4021
+ if s7.size == 4
4022
+ break
4023
+ end
4024
+ end
4025
+ if s7.size < 4
4026
+ @index = i7
4027
+ r7 = nil
4028
+ else
4029
+ if s7.size < 4
4030
+ @terminal_failures.pop
4031
+ end
4032
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
4033
+ end
4034
+ s5 << r7
4035
+ end
4036
+ if s5.last
4037
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
4038
+ r5.extend(Hexscalar1)
4039
+ else
4040
+ @index = i5
4041
+ r5 = nil
4042
+ end
4043
+ if r5
4044
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
4045
+ r0 = r5
4046
+ else
4047
+ r9 = _nt_non_surrogate
4048
+ if r9
4049
+ r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
4050
+ r0 = r9
4051
+ else
4052
+ s10, i10 = [], index
4053
+ loop do
4054
+ r11 = _nt_HEXDIG
4055
+ if r11
4056
+ s10 << r11
4057
+ else
4058
+ break
4059
+ end
4060
+ if s10.size == 3
4061
+ break
4062
+ end
4063
+ end
4064
+ if s10.size < 1
4065
+ @index = i10
4066
+ r10 = nil
4067
+ else
4068
+ if s10.size < 3
4069
+ @terminal_failures.pop
4070
+ end
4071
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
4072
+ end
4073
+ if r10
4074
+ r10 = SyntaxNode.new(input, (index-1)...index) if r10 == true
4075
+ r0 = r10
4076
+ else
4077
+ @index = i0
4078
+ r0 = nil
4079
+ end
4080
+ end
4081
+ end
4082
+ end
4083
+
4084
+ node_cache[:hexscalar][start_index] = r0
4085
+
4086
+ r0
4087
+ end
4088
+
3843
4089
  module Bytes0
3844
4090
  end
3845
4091
 
@@ -4407,6 +4653,104 @@ module CDDLGRAMMAR
4407
4653
  r0
4408
4654
  end
4409
4655
 
4656
+ def _nt_HEXDIG1
4657
+ start_index = index
4658
+ if node_cache[:HEXDIG1].has_key?(index)
4659
+ cached = node_cache[:HEXDIG1][index]
4660
+ if cached
4661
+ node_cache[:HEXDIG1][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
4662
+ @index = cached.interval.end
4663
+ end
4664
+ return cached
4665
+ end
4666
+
4667
+ i0 = index
4668
+ r1 = _nt_DIGIT1
4669
+ if r1
4670
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
4671
+ r0 = r1
4672
+ else
4673
+ if (match_len = has_terminal?("a", :insens, index))
4674
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
4675
+ @index += match_len
4676
+ else
4677
+ terminal_parse_failure('"A"')
4678
+ r2 = nil
4679
+ end
4680
+ if r2
4681
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
4682
+ r0 = r2
4683
+ else
4684
+ if (match_len = has_terminal?("b", :insens, index))
4685
+ r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
4686
+ @index += match_len
4687
+ else
4688
+ terminal_parse_failure('"B"')
4689
+ r3 = nil
4690
+ end
4691
+ if r3
4692
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
4693
+ r0 = r3
4694
+ else
4695
+ if (match_len = has_terminal?("c", :insens, index))
4696
+ r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
4697
+ @index += match_len
4698
+ else
4699
+ terminal_parse_failure('"C"')
4700
+ r4 = nil
4701
+ end
4702
+ if r4
4703
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
4704
+ r0 = r4
4705
+ else
4706
+ if (match_len = has_terminal?("d", :insens, index))
4707
+ r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
4708
+ @index += match_len
4709
+ else
4710
+ terminal_parse_failure('"D"')
4711
+ r5 = nil
4712
+ end
4713
+ if r5
4714
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
4715
+ r0 = r5
4716
+ else
4717
+ if (match_len = has_terminal?("e", :insens, index))
4718
+ r6 = instantiate_node(SyntaxNode,input, index...(index + match_len))
4719
+ @index += match_len
4720
+ else
4721
+ terminal_parse_failure('"E"')
4722
+ r6 = nil
4723
+ end
4724
+ if r6
4725
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
4726
+ r0 = r6
4727
+ else
4728
+ if (match_len = has_terminal?("f", :insens, index))
4729
+ r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
4730
+ @index += match_len
4731
+ else
4732
+ terminal_parse_failure('"F"')
4733
+ r7 = nil
4734
+ end
4735
+ if r7
4736
+ r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
4737
+ r0 = r7
4738
+ else
4739
+ @index = i0
4740
+ r0 = nil
4741
+ end
4742
+ end
4743
+ end
4744
+ end
4745
+ end
4746
+ end
4747
+ end
4748
+
4749
+ node_cache[:HEXDIG1][start_index] = r0
4750
+
4751
+ r0
4752
+ end
4753
+
4410
4754
  def _nt_BINDIG
4411
4755
  start_index = index
4412
4756
  if node_cache[:BINDIG].has_key?(index)
@@ -0,0 +1,27 @@
1
+ require_relative "../cddlc.rb"
2
+ require_relative "./cddl-visitor.rb"
3
+
4
+ class CDDL
5
+ def constant_evaluate(rhs)
6
+ case rhs
7
+ in ["number", n]
8
+ [true, eval(n)]
9
+ in ["text", n]
10
+ [true, n]
11
+ in ["name", n]
12
+ if nv = rules[n]
13
+ constant_evaluate(nv)
14
+ end
15
+ else
16
+ [false]
17
+ end
18
+ end
19
+ def extract_constants
20
+ nr = {}
21
+ rules.each do |k, v|
22
+ isconstant, value = constant_evaluate(v)
23
+ nr[k] = value if isconstant
24
+ end
25
+ nr
26
+ end
27
+ end
@@ -61,12 +61,14 @@ class CDDL
61
61
  keyname
62
62
  end
63
63
  new_value2 = flattening_mogrify(new_name, value, symtab, alias_rules)
64
- if ar = alias_rules[new_name]
65
- fail [:ALIAS_RULES, ar, new_value].inspect if ar != new_value2
66
- else
67
- alias_rules[new_name] = new_value2
64
+ new_name2 = new_name
65
+ n = 0
66
+ while ar = alias_rules[new_name2] and ar != new_value2
67
+ n += 1
68
+ new_name2 = new_name << "@" << n.to_s
68
69
  end
69
- [true, ["mem", cut, key, ["name", new_name]]]
70
+ alias_rules[new_name2] = new_value2
71
+ [true, ["mem", cut, key, ["name", new_name2]]]
70
72
  end
71
73
  else
72
74
  false
@@ -74,8 +76,8 @@ class CDDL
74
76
  end
75
77
  step2 = visit(step1) do |here|
76
78
  case here
77
- in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE], ["name", MOGRIFIED_ID_RE => new_name]]]
78
- [true, ["name", new_name]]
79
+ in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE], ["name", MOGRIFIED_ID_RE => new_name2]]]
80
+ [true, ["name", new_name2]]
79
81
  else
80
82
  false
81
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cddlc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-14 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,6 +105,7 @@ files:
105
105
  - lib/cddlc.rb
106
106
  - lib/parser/cddl-util.rb
107
107
  - lib/parser/cddlgrammar.rb
108
+ - lib/processor/cddl-constants.rb
108
109
  - lib/processor/cddl-expander.rb
109
110
  - lib/processor/cddl-flattening.rb
110
111
  - lib/processor/cddl-undefined.rb