cddlc 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cddlc +2 -2
- data/cddlc.gemspec +2 -2
- data/data/rfc9581.cddl +118 -0
- data/lib/cddlc.rb +42 -34
- data/lib/processor/cddl-visitor.rb +2 -2
- data/lib/writer/cddl-writer.rb +2 -4
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3ebce64393cf5518aaaf97d1257771e4b0a7e0f3318f0c1ba7a2c0a3342de9f
|
4
|
+
data.tar.gz: 6dd472b20440724ce78aa6bc87a858b29d8b81b8137b7f583afed016285e0e2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31b74e7d6fc4fce123d2289c7323d8dcbc91704f16851c509938bc89d786a4850c8abd373247c931c1a5a078e310ab0b539900b514626d8dcaa24e5c33fb3067
|
7
|
+
data.tar.gz: a3c9e1683b8bf909cd4c946b2396794172fd1c6f8d66814af36bb209ab65524da4c5f61b920d0836b91d39d53bd7c784156b22989e99946c166b34c6b3dca0f3
|
data/bin/cddlc
CHANGED
@@ -10,7 +10,7 @@ def named_keys(tree)
|
|
10
10
|
# warn [:T, tree].inspect
|
11
11
|
fail unless Array === tree
|
12
12
|
case tree[0]
|
13
|
-
when "seq", "gcho", "tcho"
|
13
|
+
when "seq", "gcho", "gadd", "tcho", "tadd"
|
14
14
|
tree[1..-1].flat_map {|x| named_keys(x)}
|
15
15
|
when "rep"
|
16
16
|
named_keys(tree[3])
|
@@ -95,7 +95,7 @@ end
|
|
95
95
|
|
96
96
|
cddl_file = ""
|
97
97
|
if $options.start
|
98
|
-
cddl_file << "
|
98
|
+
cddl_file << "@.start.@ = #{$options.start}\n"
|
99
99
|
end
|
100
100
|
if m = $options.model
|
101
101
|
cddl_file << m << "\n"
|
data/cddlc.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cddlc"
|
3
|
-
s.version = "0.3.
|
3
|
+
s.version = "0.3.4"
|
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"
|
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.add_development_dependency 'bundler', '~>1'
|
17
17
|
s.add_dependency 'treetop', '~>1'
|
18
|
-
s.add_dependency 'json', '~>2'
|
18
|
+
# s.add_dependency 'json', '~>2'
|
19
19
|
s.add_dependency 'neatjson', '~>0.10'
|
20
20
|
end
|
data/data/rfc9581.cddl
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
Etime = #6.1001(etime-detailed)
|
2
|
+
|
3
|
+
etime-framework = {
|
4
|
+
uint => any ; at least one base time
|
5
|
+
* (nint/text) => any ; elective supplementary information
|
6
|
+
* uint => any ; critical supplementary information
|
7
|
+
}
|
8
|
+
|
9
|
+
etime-detailed = ({
|
10
|
+
$$ETIME-BASETIME
|
11
|
+
ClockQuality-group
|
12
|
+
* $$ETIME-ELECTIVE
|
13
|
+
* $$ETIME-CRITICAL
|
14
|
+
* ((nint/text) .feature "etime-elective-extension") => any
|
15
|
+
* (uint .feature "etime-critical-extension") => any
|
16
|
+
}) .within etime-framework
|
17
|
+
|
18
|
+
|
19
|
+
$$ETIME-BASETIME //= (1: ~time)
|
20
|
+
|
21
|
+
|
22
|
+
$$ETIME-BASETIME //= (4: ~decfrac)
|
23
|
+
$$ETIME-BASETIME //= (5: ~bigfloat)
|
24
|
+
|
25
|
+
|
26
|
+
$$ETIME-ELECTIVE //= (-3: uint)
|
27
|
+
$$ETIME-ELECTIVE //= (-6: uint)
|
28
|
+
$$ETIME-ELECTIVE //= (-9: uint)
|
29
|
+
$$ETIME-ELECTIVE //= (-12: uint)
|
30
|
+
$$ETIME-ELECTIVE //= (-15: uint)
|
31
|
+
$$ETIME-ELECTIVE //= (-18: uint)
|
32
|
+
|
33
|
+
|
34
|
+
$$ETIME-ELECTIVE //= (-1 => $ETIME-TIMESCALE)
|
35
|
+
$$ETIME-ELECTIVE //= (-13 => $ETIME-TIMESCALE)
|
36
|
+
$$ETIME-CRITICAL //= (13 => $ETIME-TIMESCALE)
|
37
|
+
|
38
|
+
$ETIME-TIMESCALE /= &(etime-utc: 0)
|
39
|
+
$ETIME-TIMESCALE /= &(etime-tai: 1)
|
40
|
+
|
41
|
+
|
42
|
+
ClockQuality-group = (
|
43
|
+
? &(ClockClass: -2) => uint .size 1 ; PTP/RFC8575
|
44
|
+
? &(ClockAccuracy: -4) => uint .size 1 ; PTP/RFC8575
|
45
|
+
? &(OffsetScaledLogVariance: -5) => uint .size 2 ; PTP/RFC8575
|
46
|
+
? &(Uncertainty: -7) => ~time/~duration
|
47
|
+
? &(Guarantee: -8) => ~time/~duration
|
48
|
+
)
|
49
|
+
|
50
|
+
|
51
|
+
$$ETIME-ELECTIVE //= (-10: time-zone-info)
|
52
|
+
$$ETIME-CRITICAL //= (10: time-zone-info)
|
53
|
+
|
54
|
+
time-zone-info = tstr .abnf
|
55
|
+
("time-zone-name / time-numoffset" .det IXDTFtz)
|
56
|
+
IXDTFtz = '
|
57
|
+
time-hour = 2DIGIT ; 00-23
|
58
|
+
time-minute = 2DIGIT ; 00-59
|
59
|
+
time-numoffset = ("+" / "-") time-hour ":" time-minute
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
time-zone-initial = ALPHA / "." / "_"
|
64
|
+
time-zone-char = time-zone-initial / DIGIT / "-" / "+"
|
65
|
+
time-zone-part = time-zone-initial *time-zone-char
|
66
|
+
; but not "." or ".."
|
67
|
+
time-zone-name = time-zone-part *("/" time-zone-part)
|
68
|
+
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
|
69
|
+
DIGIT = %x30-39 ; 0-9
|
70
|
+
' ; extracted from [RFC9557] and [RFC3339]
|
71
|
+
|
72
|
+
|
73
|
+
$$ETIME-ELECTIVE //= (-11: suffix-info-map)
|
74
|
+
$$ETIME-CRITICAL //= (11: suffix-info-map)
|
75
|
+
|
76
|
+
suffix-info-map = { * suffix-key => suffix-values }
|
77
|
+
suffix-key = tstr .abnf ("suffix-key" .det IXDTF)
|
78
|
+
suffix-values = one-or-more<suffix-value>
|
79
|
+
one-or-more<T> = T / [ 2* T ]
|
80
|
+
suffix-value = tstr .abnf ("suffix-value" .det IXDTF)
|
81
|
+
|
82
|
+
IXDTF = '
|
83
|
+
key-initial = lcalpha / "_"
|
84
|
+
key-char = key-initial / DIGIT / "-"
|
85
|
+
suffix-key = key-initial *key-char
|
86
|
+
|
87
|
+
suffix-value = 1*alphanum
|
88
|
+
alphanum = ALPHA / DIGIT
|
89
|
+
lcalpha = %x61-7A
|
90
|
+
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
|
91
|
+
DIGIT = %x30-39 ; 0-9
|
92
|
+
' ; extracted from [RFC9557]
|
93
|
+
|
94
|
+
|
95
|
+
Duration = #6.1002(etime-detailed)
|
96
|
+
|
97
|
+
|
98
|
+
simple-Period = #6.1003([
|
99
|
+
start: ~Etime / null
|
100
|
+
end: ~Etime / null
|
101
|
+
? duration: ~Duration
|
102
|
+
])
|
103
|
+
|
104
|
+
|
105
|
+
Period = #6.1003([
|
106
|
+
(start: ~Etime,
|
107
|
+
((end: ~Etime) //
|
108
|
+
(end: null,
|
109
|
+
duration: ~Duration))) //
|
110
|
+
(start: null,
|
111
|
+
end: ~Etime,
|
112
|
+
duration: ~Duration)
|
113
|
+
])
|
114
|
+
|
115
|
+
|
116
|
+
etime = #6.1001({* (int/tstr) => any})
|
117
|
+
duration = #6.1002({* (int/tstr) => any})
|
118
|
+
period = #6.1003([~etime/null, ~etime/null, ?~duration])
|
data/lib/cddlc.rb
CHANGED
@@ -198,10 +198,18 @@ class CDDL
|
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
+
RULE_OP_TO_CHOICE = {"/=" => ["tcho", "tadd"], "//=" => ["gcho", "gadd"]}
|
202
|
+
CHOICERULES = RULE_OP_TO_CHOICE.values.flatten
|
203
|
+
RULE_OUTER_TO_CHOICE = {"tadd" => ["tcho", "tadd"], "gadd" => ["gcho", "gadd"]}
|
204
|
+
|
201
205
|
def store_rule(k, v)
|
202
206
|
if old = rules[k]
|
203
207
|
if old != v
|
204
|
-
|
208
|
+
if cho = RULE_OUTER_TO_CHOICE[v[0]]
|
209
|
+
merge_to_rule(k, v, cho)
|
210
|
+
else
|
211
|
+
return old # error
|
212
|
+
end
|
205
213
|
end
|
206
214
|
else
|
207
215
|
rules[k] = v
|
@@ -226,9 +234,38 @@ class CDDL
|
|
226
234
|
Marshal.load(Marshal.dump(self))
|
227
235
|
end
|
228
236
|
|
229
|
-
|
230
|
-
|
231
|
-
|
237
|
+
def merge_to_rule(name, val, cho)
|
238
|
+
@rules[name] = nv =
|
239
|
+
if (old = @rules[name]) && old != val
|
240
|
+
fail "overwriting #{write_rule(name, old)} ...with... #{write_rule(name, val)}" unless cho
|
241
|
+
if Array === old && cho.include?(old[0])
|
242
|
+
if cho.include?(val[0])
|
243
|
+
old.dup.append(*val[1..-1])
|
244
|
+
else
|
245
|
+
old.dup << val
|
246
|
+
end
|
247
|
+
else
|
248
|
+
# can't put an old "g/tadd" into a new "t/gcho"
|
249
|
+
fail "can't add #{write_rule(name, [cho[1], val])} ...to... #{write_rule(name, old)}" if CHOICERULES.include?(old[0])
|
250
|
+
[cho[0], old, val] # old might need to be packaged for gcho
|
251
|
+
end
|
252
|
+
else
|
253
|
+
if cho
|
254
|
+
if val[0] == cho[0]
|
255
|
+
[cho[1], *val[1..-1]]
|
256
|
+
else
|
257
|
+
[cho[1], val]
|
258
|
+
end
|
259
|
+
else
|
260
|
+
val
|
261
|
+
end
|
262
|
+
end
|
263
|
+
if name[0..1] == "$$"
|
264
|
+
check_socket(name, nv, "gadd", "tadd", "tcho", "type", "group")
|
265
|
+
elsif name[0] == "$"
|
266
|
+
check_socket(name, nv, "tadd", "gadd", "gcho", "group", "type")
|
267
|
+
end
|
268
|
+
end
|
232
269
|
|
233
270
|
def rules
|
234
271
|
if @rules.nil? # memoize
|
@@ -260,36 +297,7 @@ class CDDL
|
|
260
297
|
else
|
261
298
|
fail name
|
262
299
|
end
|
263
|
-
|
264
|
-
if (old = @rules[name]) && old != val
|
265
|
-
fail "overwriting #{write_rule(name, old)} ...with... #{write_rule(name, val)}" unless cho
|
266
|
-
if Array === old && cho.include?(old[0])
|
267
|
-
if cho.include?(val[0])
|
268
|
-
old.dup.append(*val[1..-1])
|
269
|
-
else
|
270
|
-
old.dup << val
|
271
|
-
end
|
272
|
-
else
|
273
|
-
# can't put an old "g/tadd" into a new "t/gcho"
|
274
|
-
fail "can't add #{write_rule(name, [cho[1], val])} ...to... #{write_rule(name, old)}" if CHOICERULES.include?(old[0])
|
275
|
-
[cho[0], old, val] # old might need to be packaged for gcho
|
276
|
-
end
|
277
|
-
else
|
278
|
-
if cho
|
279
|
-
if val[0] == cho[0]
|
280
|
-
[cho[1], *val[1..-1]]
|
281
|
-
else
|
282
|
-
[cho[1], val]
|
283
|
-
end
|
284
|
-
else
|
285
|
-
val
|
286
|
-
end
|
287
|
-
end
|
288
|
-
if name[0..1] == "$$"
|
289
|
-
check_socket(name, nv, "gadd", "tadd", "tcho", "type", "group")
|
290
|
-
elsif name[0] == "$"
|
291
|
-
check_socket(name, nv, "tadd", "gadd", "gcho", "group", "type")
|
292
|
-
end
|
300
|
+
merge_to_rule(name, val, cho)
|
293
301
|
end
|
294
302
|
# warn "** rules #{rules.inspect}"
|
295
303
|
end
|
@@ -27,8 +27,8 @@ class CDDL
|
|
27
27
|
["tcho", *visit_all(prods, &block)]
|
28
28
|
in ["gadd", *prods]
|
29
29
|
["gadd", *visit_all(prods, &block)]
|
30
|
-
in ["
|
31
|
-
["
|
30
|
+
in ["tadd", *prods]
|
31
|
+
["tadd", *visit_all(prods, &block)]
|
32
32
|
in ["seq", *prods]
|
33
33
|
["seq", *visit_all(prods, &block)]
|
34
34
|
in ["enum", prod]
|
data/lib/writer/cddl-writer.rb
CHANGED
@@ -41,9 +41,9 @@ class CDDL
|
|
41
41
|
[4, id]
|
42
42
|
in ["gen", id, *parms] # oops -- namep vs. namea; ouch
|
43
43
|
[4, "#{id}<#{parms.map{write_rhs(_1, 2, indent, pn)}.join(", ")}>"]
|
44
|
-
in ["tcho", *types]
|
44
|
+
in ["tcho" | "tadd", *types]
|
45
45
|
[2.1, types.map{write_rhs(_1, 3, indent, pn)}.join(" / ")]
|
46
|
-
in ["gcho", *groups]
|
46
|
+
in ["gcho" | "gadd", *groups]
|
47
47
|
[0, groups.map{write_rhs(_1, 2, indent, pn)}.join(" // ")]
|
48
48
|
in ["op", op, l, r]
|
49
49
|
[3, "#{write_rhs(l, 4, indent, pn)} #{op} #{write_rhs(r, 4, indent, pn)}"]
|
@@ -117,10 +117,8 @@ class CDDL
|
|
117
117
|
case v
|
118
118
|
in ["tadd", *rest]
|
119
119
|
assign = "/="
|
120
|
-
v = ["tcho", *rest]
|
121
120
|
in ["gadd", *rest]
|
122
121
|
assign = "//="
|
123
|
-
v = ["gcho", *rest]
|
124
122
|
in ["parm", parmnames, _type]
|
125
123
|
else
|
126
124
|
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.3.
|
4
|
+
version: 0.3.4
|
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-
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: json
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: neatjson
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,6 +88,7 @@ files:
|
|
102
88
|
- data/rfc9393-sign1.cddl
|
103
89
|
- data/rfc9393-tags.cddl
|
104
90
|
- data/rfc9393.cddl
|
91
|
+
- data/rfc9581.cddl
|
105
92
|
- lib/cddlc.rb
|
106
93
|
- lib/parser/cddl-util.rb
|
107
94
|
- lib/parser/cddlgrammar.rb
|
@@ -130,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
117
|
- !ruby/object:Gem::Version
|
131
118
|
version: '0'
|
132
119
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.5.14
|
134
121
|
signing_key:
|
135
122
|
specification_version: 4
|
136
123
|
summary: CDDL (Concise Data Definition Language) converters and miscellaneous tools
|