cddl 0.8.18 → 0.8.19
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/cddl.gemspec +1 -1
- data/lib/cddl.rb +26 -9
- data/test-data/abnf3.cddl +32 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e344aa8fcd67bc17cbeaba6c564ab2c3b6b9ce63b5df9acdffe060ac32628d3
|
4
|
+
data.tar.gz: 32410cfe8d62729a6f05e1174871746af3be5998cc2a56fe50bdfc139b53252d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fad1d715e3acbd3062c8aeb49518148de9a61c6385a09bd3baa7b384e398ce52bce13afa268209ff2fc0763ef1e07aea932857e0489a0c1e94d79429346418c
|
7
|
+
data.tar.gz: ef603bb0dca1beceb0767e87210b4e3819533924c64014392b694e36a2cc9e41b00f1618484226c950aa804e5690e7c5e7451f527b9ad0379ecc5fda5bed389e
|
data/cddl.gemspec
CHANGED
data/lib/cddl.rb
CHANGED
@@ -255,6 +255,11 @@ module CDDL
|
|
255
255
|
h[k] = ABNF.from_abnf(grammar)
|
256
256
|
}
|
257
257
|
|
258
|
+
ABNF_ENCODING_FOR_CONOP = {
|
259
|
+
abnf: Encoding::UTF_8,
|
260
|
+
abnfb: Encoding::BINARY
|
261
|
+
}
|
262
|
+
|
258
263
|
def generate
|
259
264
|
@recursion = 0
|
260
265
|
generate1(rules)
|
@@ -510,12 +515,19 @@ module CDDL
|
|
510
515
|
fail "Don't know yet how to generate #{where}"
|
511
516
|
end
|
512
517
|
REGEXP_FOR_STRING[regexp].random_example(max_repeater_variance: 5)
|
513
|
-
when :abnf
|
518
|
+
when :abnf, :abnfb
|
514
519
|
grammar = generate1(control)
|
515
|
-
|
520
|
+
bytes = true if target == [:prim, 2]
|
521
|
+
bytes = false if target == [:prim, 3]
|
522
|
+
unless !bytes.nil? && String === grammar
|
516
523
|
fail "Don't know yet how to generate #{where}"
|
517
524
|
end
|
518
|
-
ABNF_PARSER_FOR_STRING[grammar].generate
|
525
|
+
out = ABNF_PARSER_FOR_STRING[grammar].generate
|
526
|
+
if where[1] == :abnfb
|
527
|
+
out = out.codepoints.pack("C*")
|
528
|
+
end
|
529
|
+
enc = bytes ? Encoding::BINARY : Encoding::UTF_8
|
530
|
+
out.force_encoding(enc)
|
519
531
|
when :cbor, :cborseq
|
520
532
|
unless target == [:prim, 2]
|
521
533
|
fail "Don't know yet how to generate #{where}"
|
@@ -634,7 +646,7 @@ module CDDL
|
|
634
646
|
|
635
647
|
def validate_result(check)
|
636
648
|
check || (
|
637
|
-
@last_message
|
649
|
+
@last_message << yield
|
638
650
|
false
|
639
651
|
)
|
640
652
|
end
|
@@ -667,7 +679,9 @@ module CDDL
|
|
667
679
|
ann.concat(ann2)
|
668
680
|
end
|
669
681
|
if occ < s
|
670
|
-
|
682
|
+
# warn "*** lme #{@last_message.encoding} #{@last_message}"
|
683
|
+
# warn "*** #{"\noccur #{occ} < #{s}, not reached at #{i} in array #{d} for #{where}".encoding}"
|
684
|
+
@last_message << "\noccur #{occ} < #{s}, not reached at #{i} in array #{d} for #{where}"
|
671
685
|
return [false, ann]
|
672
686
|
end
|
673
687
|
end
|
@@ -908,17 +922,19 @@ module CDDL
|
|
908
922
|
end
|
909
923
|
end
|
910
924
|
)
|
911
|
-
when :abnf
|
925
|
+
when :abnf, :abnfb
|
912
926
|
ann if (
|
913
927
|
if String === d
|
914
928
|
ok, v, vt = extract_value(control)
|
915
929
|
if ok && vt == String
|
916
930
|
begin
|
917
|
-
ABNF_PARSER_FOR_STRING[v].validate(
|
931
|
+
ABNF_PARSER_FOR_STRING[v].validate(
|
932
|
+
d.dup.force_encoding(ABNF_ENCODING_FOR_CONOP[conop]).codepoints.pack("U*")
|
933
|
+
)
|
918
934
|
true
|
919
935
|
rescue => e
|
920
936
|
# warn "*** #{e}" # XXX
|
921
|
-
@last_message = e
|
937
|
+
@last_message = e.to_s.force_encoding(Encoding::UTF_8)
|
922
938
|
nil
|
923
939
|
end
|
924
940
|
end
|
@@ -1278,7 +1294,8 @@ module CDDL
|
|
1278
1294
|
BRACE = {"{" => :map, "[" => :array}
|
1279
1295
|
RANGE_EXCLUDE_END = {".." => false, "..." => true}
|
1280
1296
|
SUPPORTED_ANNOTATIONS = [:bits, :size, :regexp, :cbor, :cborseq, :within, :and,
|
1281
|
-
:default, :lt, :le, :gt, :ge, :eq, :ne,
|
1297
|
+
:default, :lt, :le, :gt, :ge, :eq, :ne,
|
1298
|
+
:feature, :abnf, :abnfb, :cat, :plus]
|
1282
1299
|
|
1283
1300
|
def type1(n, canbegroup = false)
|
1284
1301
|
# puts "NVALUE #{n.value.inspect}"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
start = [tt, tb, bt, bb]
|
2
|
+
|
3
|
+
|
4
|
+
tt = text .abnf '4DIGIT 1FOO
|
5
|
+
DIGIT = %x30-39 ; 0-9
|
6
|
+
FOO = %xc0-cf
|
7
|
+
'
|
8
|
+
tb = text .abnfb '4DIGIT 1FOO
|
9
|
+
DIGIT = %x30-39 ; 0-9
|
10
|
+
FOO = %xc0-cf
|
11
|
+
'
|
12
|
+
bt = bytes .abnf '4DIGIT 1FOO
|
13
|
+
DIGIT = %x30-39 ; 0-9
|
14
|
+
FOO = %xc0-cf
|
15
|
+
'
|
16
|
+
bb = bytes .abnfb '4DIGIT 1FOO
|
17
|
+
DIGIT = %x30-39 ; 0-9
|
18
|
+
FOO = %xc0-cf
|
19
|
+
'
|
20
|
+
|
21
|
+
; ["7408\xC6", "7073\xC3", h'30383131CD', h'32363738CD']
|
22
|
+
; ["5892\u00ca", "2145\u00c6", h'33333338C38B', h'31343033C388']
|
23
|
+
|
24
|
+
|
25
|
+
; ** ENCOED UTF-8
|
26
|
+
; ** ENCOED UTF-8
|
27
|
+
; ** ENCOED UTF-8
|
28
|
+
; ** ENCOED UTF-8
|
29
|
+
; ["5845\u00c6", "9329\u00cb", h'38393538C389', h'33343230C386']
|
30
|
+
|
31
|
+
|
32
|
+
; ["1066\u00cc", "9253\xC9", h'38333533C38A', h'32373337C4']
|
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.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- test-data/abignum.cddl
|
117
117
|
- test-data/abnf1.cddl
|
118
118
|
- test-data/abnf2.cddl
|
119
|
+
- test-data/abnf3.cddl
|
119
120
|
- test-data/ambig.cddl
|
120
121
|
- test-data/b.cddl
|
121
122
|
- test-data/badaddr.cddl
|