cddl 0.9.2 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cddl.gemspec +1 -1
- data/lib/cddl.rb +45 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce024a0c0c43374c481b2f099e23dfd2d5da6cda62791111cf767bc12684bd92
|
4
|
+
data.tar.gz: b7bea63f7fb1bc927f3ffad3d602b6544719a7bd9657e7836faae0edd2355bfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59344f19904e61edaecb196d0ba9106a97e5d9cbcb6b77bb3abd8f0a41fc72f0a30e51325253fb718e4f8f928ad979da968b48206c0594e80a6f82e2315252aa
|
7
|
+
data.tar.gz: 17415dd68f227a7c642369563bb38923adc54706b104468aa05c40d322697db1fa9cf22be2c5bc18d1036835f9cf588fc8eb4c514512b4e4b9dd459d8aaf95ce
|
data/cddl.gemspec
CHANGED
data/lib/cddl.rb
CHANGED
@@ -22,6 +22,20 @@ module CDDL
|
|
22
22
|
|
23
23
|
class Parser
|
24
24
|
|
25
|
+
FEATURE_REJECT_RE = /\A\^/
|
26
|
+
# CDDL_FEATURE_OK=cbor,^json
|
27
|
+
CDDL_FEATURE_OK, CDDL_FEATURE_REJECT =
|
28
|
+
if ok = ENV["CDDL_FEATURE_OK"]
|
29
|
+
ok.split(/,\s*/)
|
30
|
+
.partition{|s| s[0] !~ FEATURE_REJECT_RE}
|
31
|
+
.map {|l| Hash[l.map {|feature|
|
32
|
+
[feature.sub(FEATURE_REJECT_RE, ''),
|
33
|
+
true]}]}
|
34
|
+
else
|
35
|
+
[{}, {}]
|
36
|
+
end
|
37
|
+
|
38
|
+
|
25
39
|
class BackTrack < Exception; end
|
26
40
|
|
27
41
|
def initialize(source_text)
|
@@ -130,7 +144,7 @@ module CDDL
|
|
130
144
|
if subtree[0] == :type1 && subtree[1..-1].all? {|x| x[0] == :int}
|
131
145
|
if enumname = subtree.cbor_annotations rescue nil
|
132
146
|
enumname = cname(enumname.first)
|
133
|
-
subtree[1..-1].each do |x|
|
147
|
+
subtree[1..-1].each do |x|
|
134
148
|
if memname = x.cbor_annotations
|
135
149
|
memname = "#{enumname}_#{cname(memname.first)}"
|
136
150
|
add.(memname, x[1].to_s)
|
@@ -255,7 +269,7 @@ module CDDL
|
|
255
269
|
# Memoize a bit here
|
256
270
|
|
257
271
|
REGEXP_FOR_STRING = Hash.new {|h, k|
|
258
|
-
h[k] = Regexp.new("\\A
|
272
|
+
h[k] = Regexp.new("\\A(?:#{k})\\z")
|
259
273
|
}
|
260
274
|
|
261
275
|
ABNF_PARSER_FOR_STRING = Hash.new {|h, k|
|
@@ -459,6 +473,11 @@ module CDDL
|
|
459
473
|
end
|
460
474
|
generate1(target, inmap)
|
461
475
|
when :feature
|
476
|
+
feature, = extract_feature(control, nil)
|
477
|
+
# warn "@@@ GENFEAT #{feature.inspect} #{CDDL_FEATURE_REJECT[feature].inspect}"
|
478
|
+
if CDDL_FEATURE_REJECT[feature]
|
479
|
+
fail BackTrack.new("Feature '#{feature}' rejected")
|
480
|
+
end
|
462
481
|
generate1(target, inmap)
|
463
482
|
when :cat, :det
|
464
483
|
lhs = generate1(target, inmap)
|
@@ -636,6 +655,25 @@ module CDDL
|
|
636
655
|
}]
|
637
656
|
end
|
638
657
|
|
658
|
+
def extract_feature(control, d)
|
659
|
+
ok, v, vt = extract_value(control)
|
660
|
+
if ok
|
661
|
+
nm = v
|
662
|
+
det = d
|
663
|
+
warn "*** feature controller should be a string: #{control.inspect}" unless String == vt
|
664
|
+
else
|
665
|
+
ok, *v = extract_array(control)
|
666
|
+
if ok && v.size == 2
|
667
|
+
nm = v[0][0]
|
668
|
+
det = v[1][0]
|
669
|
+
warn "*** first element of feature controller should be a string: #{control.inspect}" unless String === nm
|
670
|
+
else
|
671
|
+
warn "*** feature controller not implemented: #{control.inspect}"
|
672
|
+
end
|
673
|
+
end
|
674
|
+
[nm, det]
|
675
|
+
end
|
676
|
+
|
639
677
|
def validate_diag
|
640
678
|
[@last_data, @last_rule, @last_message]
|
641
679
|
end
|
@@ -647,9 +685,8 @@ module CDDL
|
|
647
685
|
if warn
|
648
686
|
if result
|
649
687
|
if $features != {}
|
650
|
-
|
651
|
-
# warn
|
652
|
-
features = $features.reject {|k, v| ok.include? k.to_s }
|
688
|
+
features = $features.reject {|k, v| CDDL_FEATURE_OK[k.to_s] }
|
689
|
+
# warn "@@@ FEAT #{CDDL_FEATURE_OK.inspect} #{CDDL_FEATURE_REJECT.inspect}"
|
653
690
|
warn "** Features potentially used (#$fn): #{features.map {|k, v| "#{k}: #{v.keys}"}.join(", ")}" if features != {}
|
654
691
|
end
|
655
692
|
else
|
@@ -915,23 +952,9 @@ module CDDL
|
|
915
952
|
end
|
916
953
|
ann
|
917
954
|
when :feature
|
918
|
-
|
919
|
-
if ok
|
920
|
-
nm = v
|
921
|
-
det = d
|
922
|
-
warn "*** feature controller should be a string: #{control.inspect}" unless String == vt
|
923
|
-
else
|
924
|
-
ok, *v = extract_array(control)
|
925
|
-
if ok && v.size == 2
|
926
|
-
nm = v[0][0]
|
927
|
-
det = v[1][0]
|
928
|
-
warn "*** first element of feature controller should be a string: #{control.inspect}" unless String === nm
|
929
|
-
else
|
930
|
-
warn "*** feature controller not implemented: #{control.inspect}"
|
931
|
-
end
|
932
|
-
end
|
955
|
+
nm, det = extract_feature(control, d)
|
933
956
|
$features[nm][det] = true
|
934
|
-
ann
|
957
|
+
ann if !CDDL_FEATURE_REJECT[nm]
|
935
958
|
when :lt, :le, :gt, :ge, :eq, :ne
|
936
959
|
op = OPERATORS[conop]
|
937
960
|
ok, v, _vt = extract_value(control)
|
@@ -1120,7 +1143,7 @@ module CDDL
|
|
1120
1143
|
s = n.to_s
|
1121
1144
|
if s[-1] == "'"
|
1122
1145
|
bsqual, *parts = s.split("'", -1)
|
1123
|
-
if parts[-1] != ""
|
1146
|
+
if parts[-1] != ""
|
1124
1147
|
warn "*** Problem decoding byte string #{s.inspect}"
|
1125
1148
|
end
|
1126
1149
|
bsval = parts[0...-1].join("'").gsub(/\\(.)/){$1}
|
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.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|