cddl 0.8.10 → 0.8.15
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/bin/cddl +10 -2
- data/cddl.gemspec +1 -1
- data/data/cddl.abnf +1 -0
- data/lib/cddl.rb +110 -11
- data/test-data/feat1.cddl +4 -0
- data/test-data/feature-detail.cddl +5 -0
- data/test-data/sequence.cddl +1 -0
- data/test-data/test-gen.cddl +3 -0
- metadata +10 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e7b1df5544e11b299155468f15b649f61bf3d281644a0917be5eec9aa099f8bd
|
|
4
|
+
data.tar.gz: c29c65aec8cec554d0ca3e837dafd2cbb18bdec41552666c6f81db52f189e491
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ba99f5a974fb235e2dfeea4fd55dd8feb2fa15a558e5fe77c1c8a921ccacd83c7f292bb767bda835616cb484d86015cd8c2d6a81a675f889c7f751079d62a54
|
|
7
|
+
data.tar.gz: b5b18dada347123ed8d7b664987a441820ff73c8ead7146b00b310249f54ef8a6f6ed156c90cf32dd92ad682f9c974664e3986066240ecc7ae996520ae37b231
|
data/bin/cddl
CHANGED
|
@@ -50,11 +50,15 @@ end
|
|
|
50
50
|
|
|
51
51
|
begin
|
|
52
52
|
case ARGV[1]
|
|
53
|
-
when /\A
|
|
53
|
+
when /\A..*p/
|
|
54
54
|
$annotate = true
|
|
55
55
|
require_relative '../lib/cbor-pp'
|
|
56
56
|
end
|
|
57
57
|
case ARGV[1]
|
|
58
|
+
when /\A..*s/
|
|
59
|
+
$sequence = true
|
|
60
|
+
end
|
|
61
|
+
case ARGV[1]
|
|
58
62
|
when /\Ar/ # secret
|
|
59
63
|
$advanced = true
|
|
60
64
|
my_pp parser.rules
|
|
@@ -83,7 +87,11 @@ begin
|
|
|
83
87
|
end
|
|
84
88
|
when /\Av/
|
|
85
89
|
instance = read_arg(ARGV[2])
|
|
86
|
-
instance =
|
|
90
|
+
instance = if $sequence
|
|
91
|
+
CBOR.decode("\x9f".b << instance.b << "\xff".b)
|
|
92
|
+
else
|
|
93
|
+
CBOR.decode(instance.b) rescue JSON.load(instance)
|
|
94
|
+
end
|
|
87
95
|
instance = instance.cbor_clone if $annotate && ENV["EXPERIMENTAL_ANNOTATE"]
|
|
88
96
|
ann = parser.validate(instance)
|
|
89
97
|
# my_pp ann
|
data/cddl.gemspec
CHANGED
data/data/cddl.abnf
CHANGED
|
@@ -16,6 +16,7 @@ type1 = type2 [S (rangeop / annotator) S type2]
|
|
|
16
16
|
/ "#" "6" ["." uint] "(" S type S ")" ; note no space!
|
|
17
17
|
/ "#" DIGIT ["." uint] ; major/ai
|
|
18
18
|
/ "#" ; any
|
|
19
|
+
/ "~" S typename [genericarg]
|
|
19
20
|
/ "{" S group S "}"
|
|
20
21
|
/ "[" S group S "]"
|
|
21
22
|
/ "&" S "(" S group S ")"
|
data/lib/cddl.rb
CHANGED
|
@@ -439,6 +439,31 @@ module CDDL
|
|
|
439
439
|
$default_warned = true
|
|
440
440
|
end
|
|
441
441
|
generate1(target, inmap)
|
|
442
|
+
when :feature
|
|
443
|
+
generate1(target, inmap)
|
|
444
|
+
when :cat
|
|
445
|
+
lhs = generate1(target, inmap)
|
|
446
|
+
rhs = generate1(control)
|
|
447
|
+
begin
|
|
448
|
+
lhs + rhs
|
|
449
|
+
rescue Exception => e
|
|
450
|
+
fail "Can't #{lhs.inspect} .cat #{rhs.inspect}: #{e.message}"
|
|
451
|
+
end
|
|
452
|
+
when :plus
|
|
453
|
+
lhs = generate1(target, inmap)
|
|
454
|
+
rhs = generate1(control)
|
|
455
|
+
begin
|
|
456
|
+
case lhs
|
|
457
|
+
when Integer
|
|
458
|
+
lhs + Integer(rhs)
|
|
459
|
+
when Numeric
|
|
460
|
+
lhs + rhs
|
|
461
|
+
else
|
|
462
|
+
fail "#{lhs.inspect}: Not a number"
|
|
463
|
+
end
|
|
464
|
+
rescue Exception => e
|
|
465
|
+
fail "Can't #{lhs.inspect} .plus #{rhs.inspect}: #{e.message}"
|
|
466
|
+
end
|
|
442
467
|
when :eq
|
|
443
468
|
content = generate1(control)
|
|
444
469
|
if validate1(content, where)
|
|
@@ -540,9 +565,34 @@ module CDDL
|
|
|
540
565
|
[true, t[1], vt]
|
|
541
566
|
elsif v = SIMPLE_VALUE[t]
|
|
542
567
|
v
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
568
|
+
elsif t[0] == :anno
|
|
569
|
+
_, conop, target, control = t
|
|
570
|
+
# warn ["EXV0", conop, target, control].inspect
|
|
571
|
+
if conop == :cat || conop == :plus
|
|
572
|
+
ok1, v1, vt1 = extract_value(target)
|
|
573
|
+
ok2, v2, vt2 = extract_value(control)
|
|
574
|
+
# warn ["EXV", ok1, v1, vt1, ok2, v2, vt2].inspect
|
|
575
|
+
if ok1 && ok2
|
|
576
|
+
if vt1 == Integer
|
|
577
|
+
[true, v1 + Integer(v2), Integer] if vt2 == Integer || vt2 == Float
|
|
578
|
+
elsif vt1 == Float
|
|
579
|
+
[true, v1 + v2, vt1] if vt2 == Integer || vt2 == Float
|
|
580
|
+
else
|
|
581
|
+
[true, v1 + v2, vt1] if vt1 == vt2
|
|
582
|
+
end
|
|
583
|
+
end rescue nil
|
|
584
|
+
end
|
|
585
|
+
end || [false]
|
|
586
|
+
end
|
|
587
|
+
|
|
588
|
+
def extract_array(t)
|
|
589
|
+
return [false] unless t[0] == :array
|
|
590
|
+
[true, *t[1..-1].map { |el|
|
|
591
|
+
return [false] unless el[0..3] == [:member, 1, 1, nil]
|
|
592
|
+
ok, v, vt = extract_value(el[4])
|
|
593
|
+
return [false] unless ok
|
|
594
|
+
[v, vt]
|
|
595
|
+
}]
|
|
546
596
|
end
|
|
547
597
|
|
|
548
598
|
def validate_diag
|
|
@@ -551,9 +601,14 @@ module CDDL
|
|
|
551
601
|
|
|
552
602
|
def validate(d, warn=true)
|
|
553
603
|
@recursion = 0
|
|
604
|
+
$features = Hash.new {|h, k| h[k] = {}}
|
|
554
605
|
result = validate1a(d, rules)
|
|
555
|
-
|
|
556
|
-
if
|
|
606
|
+
if warn
|
|
607
|
+
if result
|
|
608
|
+
if $features != {}
|
|
609
|
+
warn "** Features potentially used: #{$features.map {|k, v| "#{k}: #{v.keys}"}.join(", ")}"
|
|
610
|
+
end
|
|
611
|
+
else
|
|
557
612
|
warn "CDDL validation failure (#{result.inspect} for #{d.inspect}):"
|
|
558
613
|
PP::pp(validate_diag, STDERR)
|
|
559
614
|
puts(validate_diag.cbor_diagnostic)
|
|
@@ -755,10 +810,18 @@ module CDDL
|
|
|
755
810
|
when :range
|
|
756
811
|
[] if where[2] === d && where[1].include?(d)
|
|
757
812
|
when :anno
|
|
758
|
-
target = where
|
|
759
|
-
if
|
|
760
|
-
|
|
761
|
-
|
|
813
|
+
_, conop, target, control = where
|
|
814
|
+
if conop == :cat || conop == :plus
|
|
815
|
+
ok1, v1, vt1 = extract_value(target)
|
|
816
|
+
ok2, v2, vt2 = extract_value(control)
|
|
817
|
+
# warn ["ANNO0", ok1, v1, vt1, ok2, v2, vt2, d].inspect
|
|
818
|
+
if ok1 && ok2
|
|
819
|
+
v2 = Integer(v2) if vt1 == Integer
|
|
820
|
+
# warn ["ANNO", ok1, v1, vt1, ok2, v2, vt2, d].inspect
|
|
821
|
+
[] if d == v1 + v2 # XXX Focus ArgumentError
|
|
822
|
+
end
|
|
823
|
+
elsif ann = validate1a(d, target)
|
|
824
|
+
case conop
|
|
762
825
|
when :size
|
|
763
826
|
case d
|
|
764
827
|
when Integer
|
|
@@ -797,8 +860,24 @@ module CDDL
|
|
|
797
860
|
$default_warned = true
|
|
798
861
|
end
|
|
799
862
|
ann
|
|
863
|
+
when :feature
|
|
864
|
+
ok, v, vt = extract_value(control)
|
|
865
|
+
if ok
|
|
866
|
+
nm = v
|
|
867
|
+
det = d
|
|
868
|
+
else
|
|
869
|
+
ok, *v = extract_array(control)
|
|
870
|
+
if ok && v.size == 2
|
|
871
|
+
nm = v[0][0]
|
|
872
|
+
det = v[1][0]
|
|
873
|
+
else
|
|
874
|
+
warn "*** feature controller not implemented: #{control.inspect}"
|
|
875
|
+
end
|
|
876
|
+
end
|
|
877
|
+
$features[nm][det] = true
|
|
878
|
+
ann
|
|
800
879
|
when :lt, :le, :gt, :ge, :eq, :ne
|
|
801
|
-
op = OPERATORS[
|
|
880
|
+
op = OPERATORS[conop]
|
|
802
881
|
ok, v, _vt = extract_value(control)
|
|
803
882
|
if ok
|
|
804
883
|
ann if d.send(op, v) rescue nil # XXX Focus ArgumentError
|
|
@@ -1168,7 +1247,7 @@ module CDDL
|
|
|
1168
1247
|
BRACE = {"{" => :map, "[" => :array}
|
|
1169
1248
|
RANGE_EXCLUDE_END = {".." => false, "..." => true}
|
|
1170
1249
|
SUPPORTED_ANNOTATIONS = [:bits, :size, :regexp, :cbor, :cborseq, :within, :and,
|
|
1171
|
-
:default, :lt, :le, :gt, :ge, :eq, :ne]
|
|
1250
|
+
:default, :lt, :le, :gt, :ge, :eq, :ne, :feature, :cat, :plus]
|
|
1172
1251
|
|
|
1173
1252
|
def type1(n, canbegroup = false)
|
|
1174
1253
|
# puts "NVALUE #{n.value.inspect}"
|
|
@@ -1230,6 +1309,26 @@ module CDDL
|
|
|
1230
1309
|
v
|
|
1231
1310
|
}
|
|
1232
1311
|
]
|
|
1312
|
+
when /\A~/
|
|
1313
|
+
if tn = n.typename
|
|
1314
|
+
s = type_recall(tn.to_s, false, n.genericarg).flatten(1)
|
|
1315
|
+
else
|
|
1316
|
+
fail "No typename in unwrap #{n}"
|
|
1317
|
+
end
|
|
1318
|
+
if s[0] != :type1
|
|
1319
|
+
fail [:UNWRAPs0, s].inspect
|
|
1320
|
+
end
|
|
1321
|
+
case s[1]
|
|
1322
|
+
when :map, :array
|
|
1323
|
+
[:grpent, s[2..-1]]
|
|
1324
|
+
when :prim
|
|
1325
|
+
if s[2] != 6
|
|
1326
|
+
fail [:UNWRAPs2, s].inspect
|
|
1327
|
+
end
|
|
1328
|
+
s[4] # check :type1?
|
|
1329
|
+
else
|
|
1330
|
+
fail [:UNWRAPs1, s].inspect
|
|
1331
|
+
end
|
|
1233
1332
|
else
|
|
1234
1333
|
"unimplemented #{n}"
|
|
1235
1334
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
a = [tstr, tstr, tstr]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cddl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carsten Bormann
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cbor-diag
|
|
@@ -117,6 +117,8 @@ files:
|
|
|
117
117
|
- test-data/dcaf1.cddl
|
|
118
118
|
- test-data/dotsize.cddl
|
|
119
119
|
- test-data/extractor-demo.cddl
|
|
120
|
+
- test-data/feat1.cddl
|
|
121
|
+
- test-data/feature-detail.cddl
|
|
120
122
|
- test-data/foo.cddl
|
|
121
123
|
- test-data/grasp-01-extract.cddl
|
|
122
124
|
- test-data/grasp-01-test.cddl
|
|
@@ -148,7 +150,9 @@ files:
|
|
|
148
150
|
- test-data/named-group.cddl
|
|
149
151
|
- test-data/patch1.cddl
|
|
150
152
|
- test-data/reused_named_group.cddl
|
|
153
|
+
- test-data/sequence.cddl
|
|
151
154
|
- test-data/structure.cddl
|
|
155
|
+
- test-data/test-gen.cddl
|
|
152
156
|
- test-data/toerless0.cddl
|
|
153
157
|
- test-data/toerless1.cddl
|
|
154
158
|
- test-data/two_anonymous_groups.cddl
|
|
@@ -162,7 +166,7 @@ homepage: http://github.com/cabo/cddl
|
|
|
162
166
|
licenses:
|
|
163
167
|
- MIT
|
|
164
168
|
metadata: {}
|
|
165
|
-
post_install_message:
|
|
169
|
+
post_install_message:
|
|
166
170
|
rdoc_options: []
|
|
167
171
|
require_paths:
|
|
168
172
|
- lib
|
|
@@ -177,8 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
177
181
|
- !ruby/object:Gem::Version
|
|
178
182
|
version: '0'
|
|
179
183
|
requirements: []
|
|
180
|
-
rubygems_version: 3.
|
|
181
|
-
signing_key:
|
|
184
|
+
rubygems_version: 3.1.2
|
|
185
|
+
signing_key:
|
|
182
186
|
specification_version: 4
|
|
183
187
|
summary: CDDL generator and validator.
|
|
184
188
|
test_files: []
|