cddlc 0.1.7 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cddlc +1 -1
- data/cddlc.gemspec +1 -1
- data/data/rfc9393-concise-swid-tag.cddl +279 -0
- data/data/rfc9393-sign.cddl +26 -0
- data/data/rfc9393-sign1.cddl +19 -0
- data/data/rfc9393-tags.cddl +9 -0
- data/data/rfc9393.cddl +1 -0
- data/lib/cddlc.rb +1 -0
- data/lib/parser/cddlgrammar.rb +69 -29
- data/lib/processor/cddl-flattening.rb +7 -8
- data/lib/processor/cddl-visitor.rb +2 -2
- data/lib/writer/cddl-writer.rb +9 -5
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2ac8a4458103e760994cda656a70d934555d3b3a5f86416c53b6c3be353fd38
|
4
|
+
data.tar.gz: 7f8d5cd6a43fb98f3d201fb218d30b865f47cc0b8b0714db6ce68e2770b130bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82ef745cc5ccae3bfb100227f9713bc923b535d9f7c6087c7b091a0570be012236f2756280319163574d145745370f8193467c0824e2a66b3e48cf67621c69c6
|
7
|
+
data.tar.gz: 369473fb2b9ed8b88c6f42f627af9fa41a5a0fe3c0600a0574bd7a2815284b4c68fc9d33cfcd8a1f8fad107c7aba0282063d8a2e34be6677fc2b1d9bc9f78885
|
data/bin/cddlc
CHANGED
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
|
+
s.version = "0.2.2"
|
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"
|
@@ -0,0 +1,279 @@
|
|
1
|
+
concise-swid-tag = {
|
2
|
+
tag-id => text / bstr .size 16,
|
3
|
+
tag-version => integer,
|
4
|
+
? corpus => bool,
|
5
|
+
? patch => bool,
|
6
|
+
? supplemental => bool,
|
7
|
+
software-name => text,
|
8
|
+
? software-version => text,
|
9
|
+
? version-scheme => $version-scheme,
|
10
|
+
? media => text,
|
11
|
+
? software-meta => one-or-more<software-meta-entry>,
|
12
|
+
entity => one-or-more<entity-entry>,
|
13
|
+
? link => one-or-more<link-entry>,
|
14
|
+
? payload-or-evidence,
|
15
|
+
* $$coswid-extension,
|
16
|
+
global-attributes,
|
17
|
+
}
|
18
|
+
|
19
|
+
payload-or-evidence //= ( payload => payload-entry )
|
20
|
+
payload-or-evidence //= ( evidence => evidence-entry )
|
21
|
+
|
22
|
+
any-uri = uri
|
23
|
+
label = text / int
|
24
|
+
|
25
|
+
$version-scheme /= multipartnumeric
|
26
|
+
$version-scheme /= multipartnumeric-suffix
|
27
|
+
$version-scheme /= alphanumeric
|
28
|
+
$version-scheme /= decimal
|
29
|
+
$version-scheme /= semver
|
30
|
+
$version-scheme /= int / text
|
31
|
+
|
32
|
+
any-attribute = (
|
33
|
+
label => one-or-more<text> / one-or-more<int>
|
34
|
+
)
|
35
|
+
|
36
|
+
one-or-more<T> = T / [ 2* T ]
|
37
|
+
|
38
|
+
global-attributes = (
|
39
|
+
? lang => text,
|
40
|
+
* any-attribute,
|
41
|
+
)
|
42
|
+
|
43
|
+
hash-entry = [
|
44
|
+
hash-alg-id: int,
|
45
|
+
hash-value: bytes,
|
46
|
+
]
|
47
|
+
|
48
|
+
entity-entry = {
|
49
|
+
entity-name => text,
|
50
|
+
? reg-id => any-uri,
|
51
|
+
role => one-or-more<$role>,
|
52
|
+
? thumbprint => hash-entry,
|
53
|
+
* $$entity-extension,
|
54
|
+
global-attributes,
|
55
|
+
}
|
56
|
+
|
57
|
+
$role /= tag-creator
|
58
|
+
$role /= software-creator
|
59
|
+
$role /= aggregator
|
60
|
+
$role /= distributor
|
61
|
+
$role /= licensor
|
62
|
+
$role /= maintainer
|
63
|
+
$role /= int / text
|
64
|
+
|
65
|
+
link-entry = {
|
66
|
+
? artifact => text,
|
67
|
+
href => any-uri,
|
68
|
+
? media => text,
|
69
|
+
? ownership => $ownership,
|
70
|
+
rel => $rel,
|
71
|
+
? media-type => text,
|
72
|
+
? use => $use,
|
73
|
+
* $$link-extension,
|
74
|
+
global-attributes,
|
75
|
+
}
|
76
|
+
|
77
|
+
$ownership /= shared
|
78
|
+
$ownership /= private
|
79
|
+
$ownership /= abandon
|
80
|
+
$ownership /= int / text
|
81
|
+
|
82
|
+
$rel /= ancestor
|
83
|
+
$rel /= component
|
84
|
+
$rel /= feature
|
85
|
+
$rel /= installationmedia
|
86
|
+
$rel /= packageinstaller
|
87
|
+
$rel /= parent
|
88
|
+
$rel /= patches
|
89
|
+
$rel /= requires
|
90
|
+
$rel /= see-also
|
91
|
+
$rel /= supersedes
|
92
|
+
$rel /= supplemental
|
93
|
+
$rel /= -256..65536 / text
|
94
|
+
|
95
|
+
$use /= optional
|
96
|
+
$use /= required
|
97
|
+
$use /= recommended
|
98
|
+
$use /= int / text
|
99
|
+
|
100
|
+
software-meta-entry = {
|
101
|
+
? activation-status => text,
|
102
|
+
? channel-type => text,
|
103
|
+
? colloquial-version => text,
|
104
|
+
? description => text,
|
105
|
+
? edition => text,
|
106
|
+
? entitlement-data-required => bool,
|
107
|
+
? entitlement-key => text,
|
108
|
+
? generator => text / bstr .size 16,
|
109
|
+
? persistent-id => text,
|
110
|
+
? product => text,
|
111
|
+
? product-family => text,
|
112
|
+
? revision => text,
|
113
|
+
? summary => text,
|
114
|
+
? unspsc-code => text,
|
115
|
+
? unspsc-version => text,
|
116
|
+
* $$software-meta-extension,
|
117
|
+
global-attributes,
|
118
|
+
}
|
119
|
+
|
120
|
+
path-elements-group = ( ? directory => one-or-more<directory-entry>,
|
121
|
+
? file => one-or-more<file-entry>,
|
122
|
+
)
|
123
|
+
|
124
|
+
resource-collection = (
|
125
|
+
path-elements-group,
|
126
|
+
? process => one-or-more<process-entry>,
|
127
|
+
? resource => one-or-more<resource-entry>,
|
128
|
+
* $$resource-collection-extension,
|
129
|
+
)
|
130
|
+
|
131
|
+
file-entry = {
|
132
|
+
filesystem-item,
|
133
|
+
? size => uint,
|
134
|
+
? file-version => text,
|
135
|
+
? hash => hash-entry,
|
136
|
+
* $$file-extension,
|
137
|
+
global-attributes,
|
138
|
+
}
|
139
|
+
|
140
|
+
directory-entry = {
|
141
|
+
filesystem-item,
|
142
|
+
? path-elements => { path-elements-group },
|
143
|
+
* $$directory-extension,
|
144
|
+
global-attributes,
|
145
|
+
}
|
146
|
+
|
147
|
+
process-entry = {
|
148
|
+
process-name => text,
|
149
|
+
? pid => integer,
|
150
|
+
* $$process-extension,
|
151
|
+
global-attributes,
|
152
|
+
}
|
153
|
+
|
154
|
+
resource-entry = {
|
155
|
+
type => text,
|
156
|
+
* $$resource-extension,
|
157
|
+
global-attributes,
|
158
|
+
}
|
159
|
+
|
160
|
+
filesystem-item = (
|
161
|
+
? key => bool,
|
162
|
+
? location => text,
|
163
|
+
fs-name => text,
|
164
|
+
? root => text,
|
165
|
+
)
|
166
|
+
|
167
|
+
payload-entry = {
|
168
|
+
resource-collection,
|
169
|
+
* $$payload-extension,
|
170
|
+
global-attributes,
|
171
|
+
}
|
172
|
+
|
173
|
+
evidence-entry = {
|
174
|
+
resource-collection,
|
175
|
+
? date => integer-time,
|
176
|
+
? device-id => text,
|
177
|
+
? location => text,
|
178
|
+
* $$evidence-extension,
|
179
|
+
global-attributes,
|
180
|
+
}
|
181
|
+
|
182
|
+
integer-time = #6.1(int)
|
183
|
+
|
184
|
+
; "global map member" integer indices
|
185
|
+
tag-id = 0
|
186
|
+
software-name = 1
|
187
|
+
entity = 2
|
188
|
+
evidence = 3
|
189
|
+
link = 4
|
190
|
+
software-meta = 5
|
191
|
+
payload = 6
|
192
|
+
hash = 7
|
193
|
+
corpus = 8
|
194
|
+
patch = 9
|
195
|
+
media = 10
|
196
|
+
supplemental = 11
|
197
|
+
tag-version = 12
|
198
|
+
software-version = 13
|
199
|
+
version-scheme = 14
|
200
|
+
lang = 15
|
201
|
+
directory = 16
|
202
|
+
file = 17
|
203
|
+
process = 18
|
204
|
+
resource = 19
|
205
|
+
size = 20
|
206
|
+
file-version = 21
|
207
|
+
key = 22
|
208
|
+
location = 23
|
209
|
+
fs-name = 24
|
210
|
+
root = 25
|
211
|
+
path-elements = 26
|
212
|
+
process-name = 27
|
213
|
+
pid = 28
|
214
|
+
type = 29
|
215
|
+
entity-name = 31
|
216
|
+
reg-id = 32
|
217
|
+
role = 33
|
218
|
+
thumbprint = 34
|
219
|
+
date = 35
|
220
|
+
device-id = 36
|
221
|
+
artifact = 37
|
222
|
+
href = 38
|
223
|
+
ownership = 39
|
224
|
+
rel = 40
|
225
|
+
media-type = 41
|
226
|
+
use = 42
|
227
|
+
activation-status = 43
|
228
|
+
channel-type = 44
|
229
|
+
colloquial-version = 45
|
230
|
+
description = 46
|
231
|
+
edition = 47
|
232
|
+
entitlement-data-required = 48
|
233
|
+
entitlement-key = 49
|
234
|
+
generator = 50
|
235
|
+
persistent-id = 51
|
236
|
+
product = 52
|
237
|
+
product-family = 53
|
238
|
+
revision = 54
|
239
|
+
summary = 55
|
240
|
+
unspsc-code = 56
|
241
|
+
unspsc-version = 57
|
242
|
+
|
243
|
+
; "version-scheme" integer indices
|
244
|
+
multipartnumeric = 1
|
245
|
+
multipartnumeric-suffix = 2
|
246
|
+
alphanumeric = 3
|
247
|
+
decimal = 4
|
248
|
+
semver = 16384
|
249
|
+
|
250
|
+
; "role" integer indices
|
251
|
+
tag-creator=1
|
252
|
+
software-creator=2
|
253
|
+
aggregator=3
|
254
|
+
distributor=4
|
255
|
+
licensor=5
|
256
|
+
maintainer=6
|
257
|
+
|
258
|
+
; "ownership" integer indices
|
259
|
+
abandon=1
|
260
|
+
private=2
|
261
|
+
shared=3
|
262
|
+
|
263
|
+
; "rel" integer indices
|
264
|
+
ancestor=1
|
265
|
+
component=2
|
266
|
+
feature=3
|
267
|
+
installationmedia=4
|
268
|
+
packageinstaller=5
|
269
|
+
parent=6
|
270
|
+
patches=7
|
271
|
+
requires=8
|
272
|
+
see-also=9
|
273
|
+
supersedes=10
|
274
|
+
; supplemental=11 ; already defined
|
275
|
+
|
276
|
+
; "use" integer indices
|
277
|
+
optional=1
|
278
|
+
required=2
|
279
|
+
recommended=3
|
@@ -0,0 +1,26 @@
|
|
1
|
+
COSE_Sign-coswid<payload> = [
|
2
|
+
protected: bstr .cbor protected-signed-coswid-header1,
|
3
|
+
unprotected: unprotected-signed-coswid-header,
|
4
|
+
payload: bstr .cbor payload,
|
5
|
+
signature: [ * COSE_Signature ],
|
6
|
+
]
|
7
|
+
|
8
|
+
protected-signed-coswid-header1 = {
|
9
|
+
3 => "application/swid+cbor",
|
10
|
+
* cose-label => cose-values,
|
11
|
+
}
|
12
|
+
|
13
|
+
protected-signature-coswid-header = {
|
14
|
+
1 => int, ; algorithm identifier
|
15
|
+
* cose-label => cose-values,
|
16
|
+
}
|
17
|
+
|
18
|
+
unprotected-signed-coswid-header = {
|
19
|
+
* cose-label => cose-values,
|
20
|
+
}
|
21
|
+
|
22
|
+
COSE_Signature = [
|
23
|
+
protected: bstr .cbor protected-signature-coswid-header,
|
24
|
+
unprotected: unprotected-signed-coswid-header,
|
25
|
+
signature: bstr
|
26
|
+
]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
COSE_Sign1-coswid<payload> = [
|
2
|
+
protected: bstr .cbor protected-signed-coswid-header,
|
3
|
+
unprotected: unprotected-signed-coswid-header,
|
4
|
+
payload: bstr .cbor payload,
|
5
|
+
signature: bstr,
|
6
|
+
]
|
7
|
+
|
8
|
+
cose-label = int / tstr
|
9
|
+
cose-values = any
|
10
|
+
|
11
|
+
protected-signed-coswid-header = {
|
12
|
+
1 => int, ; algorithm identifier
|
13
|
+
3 => "application/swid+cbor",
|
14
|
+
* cose-label => cose-values,
|
15
|
+
}
|
16
|
+
|
17
|
+
unprotected-signed-coswid-header = {
|
18
|
+
* cose-label => cose-values,
|
19
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
coswid = unsigned-coswid / signed-coswid
|
2
|
+
unsigned-coswid = concise-swid-tag / tagged-coswid<concise-swid-tag>
|
3
|
+
signed-coswid1 = signed-coswid-for<unsigned-coswid>
|
4
|
+
signed-coswid = signed-coswid1 / tagged-coswid<signed-coswid1>
|
5
|
+
|
6
|
+
tagged-coswid<T> = #6.1398229316(T)
|
7
|
+
|
8
|
+
signed-coswid-for<payload> = #6.18(COSE_Sign1-coswid<payload>)
|
9
|
+
/ #6.98(COSE_Sign-coswid<payload>)
|
data/data/rfc9393.cddl
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rfc9393-concise-swid-tag.cddl
|
data/lib/cddlc.rb
CHANGED
data/lib/parser/cddlgrammar.rb
CHANGED
@@ -1812,7 +1812,9 @@ module CDDLGRAMMAR
|
|
1812
1812
|
end
|
1813
1813
|
|
1814
1814
|
module Grpent2
|
1815
|
-
def ast()
|
1815
|
+
def ast()
|
1816
|
+
repwrap(elements[0], ["mem", *elements[1].elements ? elements[1].memberkey.ast : [false, nil],
|
1817
|
+
elements[2].ast]) end
|
1816
1818
|
end
|
1817
1819
|
|
1818
1820
|
module Grpent3
|
@@ -2012,7 +2014,7 @@ module CDDLGRAMMAR
|
|
2012
2014
|
end
|
2013
2015
|
|
2014
2016
|
module Memberkey2
|
2015
|
-
def ast() type1.ast end
|
2017
|
+
def ast() [!!elements[2].elements, type1.ast] end
|
2016
2018
|
end
|
2017
2019
|
|
2018
2020
|
module Memberkey3
|
@@ -2027,7 +2029,7 @@ module CDDLGRAMMAR
|
|
2027
2029
|
end
|
2028
2030
|
|
2029
2031
|
module Memberkey4
|
2030
|
-
def ast() ["text", bareword.text_value] end
|
2032
|
+
def ast() [true, ["text", bareword.text_value]] end
|
2031
2033
|
end
|
2032
2034
|
|
2033
2035
|
module Memberkey5
|
@@ -2042,7 +2044,7 @@ module CDDLGRAMMAR
|
|
2042
2044
|
end
|
2043
2045
|
|
2044
2046
|
module Memberkey6
|
2045
|
-
def ast() value.ast end
|
2047
|
+
def ast() [true, value.ast] end
|
2046
2048
|
end
|
2047
2049
|
|
2048
2050
|
def _nt_memberkey
|
@@ -3148,15 +3150,9 @@ module CDDLGRAMMAR
|
|
3148
3150
|
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
3149
3151
|
r0 = r3
|
3150
3152
|
else
|
3151
|
-
|
3152
|
-
|
3153
|
-
|
3154
|
-
r4.extend(SCHAR3)
|
3155
|
-
@index += 1
|
3156
|
-
else
|
3157
|
-
terminal_parse_failure('[-]')
|
3158
|
-
r4 = nil
|
3159
|
-
end
|
3153
|
+
r4 = _nt_NONASCII
|
3154
|
+
r4.extend(SCHAR3)
|
3155
|
+
r4.extend(SCHAR3)
|
3160
3156
|
if r4
|
3161
3157
|
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
3162
3158
|
r0 = r4
|
@@ -3951,40 +3947,46 @@ module CDDLGRAMMAR
|
|
3951
3947
|
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
3952
3948
|
r0 = r2
|
3953
3949
|
else
|
3954
|
-
if has_terminal?(@regexps[gr = '\A[\\]
|
3950
|
+
if has_terminal?(@regexps[gr = '\A[\\]-~]'] ||= Regexp.new(gr), :regexp, index)
|
3955
3951
|
r3 = true
|
3956
3952
|
@index += 1
|
3957
3953
|
else
|
3958
|
-
terminal_parse_failure('[\\]
|
3954
|
+
terminal_parse_failure('[\\]-~]')
|
3959
3955
|
r3 = nil
|
3960
3956
|
end
|
3961
3957
|
if r3
|
3962
3958
|
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
3963
3959
|
r0 = r3
|
3964
3960
|
else
|
3965
|
-
r4 =
|
3961
|
+
r4 = _nt_NONASCII
|
3966
3962
|
if r4
|
3967
3963
|
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
3968
3964
|
r0 = r4
|
3969
3965
|
else
|
3970
|
-
|
3971
|
-
r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3972
|
-
@index += match_len
|
3973
|
-
else
|
3974
|
-
terminal_parse_failure('"\\\\\'"')
|
3975
|
-
r5 = nil
|
3976
|
-
end
|
3966
|
+
r5 = _nt_SESC
|
3977
3967
|
if r5
|
3978
3968
|
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
3979
3969
|
r0 = r5
|
3980
3970
|
else
|
3981
|
-
|
3971
|
+
if (match_len = has_terminal?("\\'", false, index))
|
3972
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
3973
|
+
@index += match_len
|
3974
|
+
else
|
3975
|
+
terminal_parse_failure('"\\\\\'"')
|
3976
|
+
r6 = nil
|
3977
|
+
end
|
3982
3978
|
if r6
|
3983
3979
|
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
3984
3980
|
r0 = r6
|
3985
3981
|
else
|
3986
|
-
|
3987
|
-
|
3982
|
+
r7 = _nt_CRLF
|
3983
|
+
if r7
|
3984
|
+
r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
|
3985
|
+
r0 = r7
|
3986
|
+
else
|
3987
|
+
@index = i0
|
3988
|
+
r0 = nil
|
3989
|
+
end
|
3988
3990
|
end
|
3989
3991
|
end
|
3990
3992
|
end
|
@@ -4623,11 +4625,49 @@ module CDDLGRAMMAR
|
|
4623
4625
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
4624
4626
|
r0 = r1
|
4625
4627
|
else
|
4626
|
-
|
4628
|
+
r2 = _nt_NONASCII
|
4629
|
+
if r2
|
4630
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
4631
|
+
r0 = r2
|
4632
|
+
else
|
4633
|
+
@index = i0
|
4634
|
+
r0 = nil
|
4635
|
+
end
|
4636
|
+
end
|
4637
|
+
|
4638
|
+
node_cache[:PCHAR][start_index] = r0
|
4639
|
+
|
4640
|
+
r0
|
4641
|
+
end
|
4642
|
+
|
4643
|
+
def _nt_NONASCII
|
4644
|
+
start_index = index
|
4645
|
+
if node_cache[:NONASCII].has_key?(index)
|
4646
|
+
cached = node_cache[:NONASCII][index]
|
4647
|
+
if cached
|
4648
|
+
node_cache[:NONASCII][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
4649
|
+
@index = cached.interval.end
|
4650
|
+
end
|
4651
|
+
return cached
|
4652
|
+
end
|
4653
|
+
|
4654
|
+
i0 = index
|
4655
|
+
if has_terminal?(@regexps[gr = '\A[ -]'] ||= Regexp.new(gr), :regexp, index)
|
4656
|
+
r1 = true
|
4657
|
+
@index += 1
|
4658
|
+
else
|
4659
|
+
terminal_parse_failure('[ -]')
|
4660
|
+
r1 = nil
|
4661
|
+
end
|
4662
|
+
if r1
|
4663
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
4664
|
+
r0 = r1
|
4665
|
+
else
|
4666
|
+
if has_terminal?(@regexps[gr = '\A[-]'] ||= Regexp.new(gr), :regexp, index)
|
4627
4667
|
r2 = true
|
4628
4668
|
@index += 1
|
4629
4669
|
else
|
4630
|
-
terminal_parse_failure('[
|
4670
|
+
terminal_parse_failure('[-]')
|
4631
4671
|
r2 = nil
|
4632
4672
|
end
|
4633
4673
|
if r2
|
@@ -4639,7 +4679,7 @@ module CDDLGRAMMAR
|
|
4639
4679
|
end
|
4640
4680
|
end
|
4641
4681
|
|
4642
|
-
node_cache[:
|
4682
|
+
node_cache[:NONASCII][start_index] = r0
|
4643
4683
|
|
4644
4684
|
r0
|
4645
4685
|
end
|
@@ -2,15 +2,14 @@ require_relative "../cddlc.rb"
|
|
2
2
|
require_relative "./cddl-visitor.rb"
|
3
3
|
|
4
4
|
class CDDL
|
5
|
-
ID_RE = /\A[A-Za-z@_$]([-.]*[A-Za-z@_$0-9])*\z/
|
6
5
|
MOGRIFIED_ID_RE = /\A\$\.[A-Za-z@_$]([-.]*[A-Za-z@_$0-9])*\z/
|
7
6
|
def flattening_key_name(key, value, env = nil)
|
8
7
|
case key
|
9
|
-
in ["enum", ["mem", ["text",
|
8
|
+
in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE => text], _]]
|
10
9
|
[false, text]
|
11
|
-
in ["text",
|
10
|
+
in ["text", IDENTIFIER_RE => text]
|
12
11
|
[false, text]
|
13
|
-
in ["number",
|
12
|
+
in ["number", INT_RE => intval] if env
|
14
13
|
[true, "$.#{env}$#{intval}"]
|
15
14
|
else
|
16
15
|
[false]
|
@@ -21,7 +20,7 @@ class CDDL
|
|
21
20
|
rules.each do |name, prod|
|
22
21
|
visit(prod) do |here|
|
23
22
|
case here
|
24
|
-
in ["mem", key, value]
|
23
|
+
in ["mem", _cut, key, value]
|
25
24
|
_labeled, keyname = flattening_key_name(key, value, false)
|
26
25
|
if keyname
|
27
26
|
symtab[keyname] << [name, value]
|
@@ -45,7 +44,7 @@ class CDDL
|
|
45
44
|
def flattening_mogrify(name, prod, symtab, alias_rules)
|
46
45
|
step1 = visit(prod) do |here|
|
47
46
|
case here
|
48
|
-
in ["mem", key, value]
|
47
|
+
in ["mem", cut, key, value]
|
49
48
|
### mogrify
|
50
49
|
labeled, keyname = flattening_key_name(key, value, name)
|
51
50
|
if keyname
|
@@ -67,7 +66,7 @@ class CDDL
|
|
67
66
|
else
|
68
67
|
alias_rules[new_name] = new_value2
|
69
68
|
end
|
70
|
-
[true, ["mem", key, ["name", new_name]]]
|
69
|
+
[true, ["mem", cut, key, ["name", new_name]]]
|
71
70
|
end
|
72
71
|
else
|
73
72
|
false
|
@@ -75,7 +74,7 @@ class CDDL
|
|
75
74
|
end
|
76
75
|
step2 = visit(step1) do |here|
|
77
76
|
case here
|
78
|
-
in ["enum", ["mem", ["text",
|
77
|
+
in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE], ["name", MOGRIFIED_ID_RE => new_name]]]
|
79
78
|
[true, ["name", new_name]]
|
80
79
|
else
|
81
80
|
false
|
@@ -33,8 +33,8 @@ class CDDL
|
|
33
33
|
["unwrap", visit(prod, &block)] # XXX, this may need to be bottled in a rule
|
34
34
|
in ["prim", prod, *prods]
|
35
35
|
["prim", visit(prod, &block), *visit_all(prods, &block)]
|
36
|
-
in ["mem", *prods]
|
37
|
-
["mem", *visit_all(prods, &block)]
|
36
|
+
in ["mem", cut, *prods]
|
37
|
+
["mem", cut, *visit_all(prods, &block)]
|
38
38
|
in ["rep", s, e, prod]
|
39
39
|
["rep", s, e, visit(prod, &block)]
|
40
40
|
else
|
data/lib/writer/cddl-writer.rb
CHANGED
@@ -42,7 +42,7 @@ class CDDL
|
|
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
44
|
in ["tcho", *types]
|
45
|
-
[2, types.map{write_rhs(_1, 3, indent, pn)}.join(" / ")]
|
45
|
+
[2.1, types.map{write_rhs(_1, 3, indent, pn)}.join(" / ")]
|
46
46
|
in ["gcho", *groups]
|
47
47
|
[0, groups.map{write_rhs(_1, 2, indent, pn)}.join(" // ")]
|
48
48
|
in ["op", op, l, r]
|
@@ -90,10 +90,14 @@ class CDDL
|
|
90
90
|
"#{s}*#{e || ""}"
|
91
91
|
end
|
92
92
|
[1, "#{occur}#{write_rhs(group, 2, indent, pn)}"]
|
93
|
-
in ["mem", nil, t2]
|
93
|
+
in ["mem", false, nil, t2]
|
94
94
|
[2, write_rhs(t2, 2, indent, pn)]
|
95
|
-
in ["mem",
|
96
|
-
[2, "#{
|
95
|
+
in ["mem", true, ["text", IDENTIFIER_RE => bareword], t2]
|
96
|
+
[2, "#{bareword}: #{write_rhs(t2, 2, indent, pn)}"]
|
97
|
+
in ["mem", true, ["number", INT_RE => bareword], t2]
|
98
|
+
[2, "#{bareword}: #{write_rhs(t2, 2, indent, pn)}"]
|
99
|
+
in ["mem", cut, t1, t2]
|
100
|
+
[2, "#{write_rhs(t1, 3, indent, pn)} #{cut ? "^" : ""}=> #{write_rhs(t2, 2, indent, pn)}"]
|
97
101
|
# 2->3: work around cddl tool limitation
|
98
102
|
in ["bytes", t]
|
99
103
|
[4, t] # XXX not very clean
|
@@ -112,7 +116,7 @@ class CDDL
|
|
112
116
|
in ["parm", parmnames, _type]
|
113
117
|
else
|
114
118
|
end
|
115
|
-
"#{write_lhs(k, parmnames)} = #{write_rhs(v, 2)}" # 2: parenthesize groups
|
119
|
+
"#{write_lhs(k, parmnames)} = #{write_rhs(v, 2.1)}" # 2: parenthesize groups
|
116
120
|
}.join("\n")
|
117
121
|
end
|
118
122
|
|
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,6 +97,11 @@ files:
|
|
97
97
|
- data/rfc9290.cddl
|
98
98
|
- data/rfc9321.cddl
|
99
99
|
- data/rfc9338.cddl
|
100
|
+
- data/rfc9393-concise-swid-tag.cddl
|
101
|
+
- data/rfc9393-sign.cddl
|
102
|
+
- data/rfc9393-sign1.cddl
|
103
|
+
- data/rfc9393-tags.cddl
|
104
|
+
- data/rfc9393.cddl
|
100
105
|
- lib/cddlc.rb
|
101
106
|
- lib/parser/cddl-util.rb
|
102
107
|
- lib/parser/cddlgrammar.rb
|
@@ -124,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
129
|
- !ruby/object:Gem::Version
|
125
130
|
version: '0'
|
126
131
|
requirements: []
|
127
|
-
rubygems_version: 3.4.
|
132
|
+
rubygems_version: 3.4.10
|
128
133
|
signing_key:
|
129
134
|
specification_version: 4
|
130
135
|
summary: CDDL (Concise Data Definition Language) converters and miscellaneous tools
|