cddlc 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cddlc +9 -3
- data/cddlc.gemspec +1 -1
- data/lib/cddlc.rb +54 -15
- data/lib/processor/cddl-visitor.rb +4 -0
- data/lib/writer/cddl-writer.rb +13 -6
- 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: 87f4f966e5f0937e393d3157c80d345295bd672d088ccc4587c04223c7ec5f94
|
4
|
+
data.tar.gz: 5be056668436fff6ab9835487326956461a98f748107fd7e0b8c4c7c6cd2dc7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46d27fe85391c66e58d9006391993eb44d14b828fe1254a1d9911d015a1ed0cd7675e5239cde4f9c90a11adfef78b97ca331d2b50eb1e53ba35808bc5f034164
|
7
|
+
data.tar.gz: 27be4a4c43b65d7a6e764fc9c66eff853b3b4d37a99dff56c3fc8a5fbe975c341d2709704d82ec03cf4525b1c5a8621ea5e082e412e2d5d432cbf7a8b50e090a
|
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])
|
@@ -44,7 +44,7 @@ require 'ostruct'
|
|
44
44
|
$options = OpenStruct.new
|
45
45
|
begin
|
46
46
|
op = OptionParser.new do |opts|
|
47
|
-
opts.banner = "Usage: cddlc.rb [options] [file.cddl... | -]"
|
47
|
+
opts.banner = "Usage: cddlc.rb [options] [-e cddl | file.cddl... | -]"
|
48
48
|
|
49
49
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
50
50
|
$options.verbose = v
|
@@ -70,6 +70,9 @@ begin
|
|
70
70
|
opts.on("-sRULE", "--start=RULE", String, "Start rule name") do |v|
|
71
71
|
$options.start = v
|
72
72
|
end
|
73
|
+
opts.on("-eCDDL", "CDDL model on command line") do |v|
|
74
|
+
$options.model = v
|
75
|
+
end
|
73
76
|
opts.on("-iIMPORT", "--import=IMPORT", String, "Import [namespace=]reference") do |v|
|
74
77
|
$options.import ||= []
|
75
78
|
$options.import << v
|
@@ -92,7 +95,10 @@ end
|
|
92
95
|
|
93
96
|
cddl_file = ""
|
94
97
|
if $options.start
|
95
|
-
cddl_file << "
|
98
|
+
cddl_file << "@.start.@ = #{$options.start}\n"
|
99
|
+
end
|
100
|
+
if m = $options.model
|
101
|
+
cddl_file << m << "\n"
|
96
102
|
end
|
97
103
|
|
98
104
|
[[$options.include, "include"], [$options.import, "import"]].each do |arr, directive|
|
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.3"
|
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"
|
data/lib/cddlc.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "parser/cddl-util.rb"
|
2
2
|
require_relative "processor/cddl-visitor.rb"
|
3
3
|
require_relative 'processor/cddl-undefined.rb'
|
4
|
+
require_relative 'writer/cddl-writer.rb'
|
4
5
|
|
5
6
|
class CDDL
|
6
7
|
@@parser = CDDLGRAMMARParser.new
|
@@ -197,10 +198,18 @@ class CDDL
|
|
197
198
|
end
|
198
199
|
end
|
199
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
|
+
|
200
205
|
def store_rule(k, v)
|
201
206
|
if old = rules[k]
|
202
207
|
if old != v
|
203
|
-
|
208
|
+
if cho = RULE_OUTER_TO_CHOICE[v[0]]
|
209
|
+
merge_to_rule(k, v, cho)
|
210
|
+
else
|
211
|
+
return old # error
|
212
|
+
end
|
204
213
|
end
|
205
214
|
else
|
206
215
|
rules[k] = v
|
@@ -225,8 +234,38 @@ class CDDL
|
|
225
234
|
Marshal.load(Marshal.dump(self))
|
226
235
|
end
|
227
236
|
|
228
|
-
|
229
|
-
|
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
|
230
269
|
|
231
270
|
def rules
|
232
271
|
if @rules.nil? # memoize
|
@@ -258,27 +297,27 @@ class CDDL
|
|
258
297
|
else
|
259
298
|
fail name
|
260
299
|
end
|
261
|
-
|
262
|
-
if (old = @rules[name]) && old != val
|
263
|
-
fail "duplicate rule for name #{name} #{old.inspect} #{val.inspect}" unless cho
|
264
|
-
if Array === old && old[0] == cho
|
265
|
-
old.dup << val
|
266
|
-
else
|
267
|
-
[cho, old, val]
|
268
|
-
end
|
269
|
-
else
|
270
|
-
val
|
271
|
-
end
|
300
|
+
merge_to_rule(name, val, cho)
|
272
301
|
end
|
273
302
|
# warn "** rules #{rules.inspect}"
|
274
303
|
end
|
275
304
|
@rules
|
276
305
|
end
|
277
306
|
|
307
|
+
def check_socket(name, nv, right, wrong, wrong_plain, wrong_kind, kind)
|
308
|
+
unless nv[0] == right
|
309
|
+
if nv[0] == wrong
|
310
|
+
flaw = "#{wrong_kind} choice #{write_rhs([wrong_plain, *nv[1..-1]], 2.1)} in"
|
311
|
+
else
|
312
|
+
flaw = "plain assignment of #{write_rhs(nv, 2.1)} to"
|
313
|
+
end
|
314
|
+
warn "** warning: #{flaw} #{kind} socket #{name}"
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
278
318
|
def prelude
|
279
319
|
if @prelude.nil?
|
280
320
|
@prelude = CDDL.from_cddl(File.read(DATA_DIR + "prelude.cddl"))
|
281
|
-
|
282
321
|
end
|
283
322
|
@prelude
|
284
323
|
end
|
@@ -25,6 +25,10 @@ class CDDL
|
|
25
25
|
["gcho", *visit_all(prods, &block)]
|
26
26
|
in ["tcho", *prods]
|
27
27
|
["tcho", *visit_all(prods, &block)]
|
28
|
+
in ["gadd", *prods]
|
29
|
+
["gadd", *visit_all(prods, &block)]
|
30
|
+
in ["tadd", *prods]
|
31
|
+
["tadd", *visit_all(prods, &block)]
|
28
32
|
in ["seq", *prods]
|
29
33
|
["seq", *visit_all(prods, &block)]
|
30
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)}"]
|
@@ -111,15 +111,22 @@ class CDDL
|
|
111
111
|
prec_check(ret, targetprec, prec, indent_s)
|
112
112
|
end
|
113
113
|
|
114
|
-
def
|
115
|
-
rules.map {|k, v|
|
114
|
+
def write_rule(k, v)
|
116
115
|
parmnames = false
|
116
|
+
assign = "="
|
117
117
|
case v
|
118
|
+
in ["tadd", *rest]
|
119
|
+
assign = "/="
|
120
|
+
in ["gadd", *rest]
|
121
|
+
assign = "//="
|
118
122
|
in ["parm", parmnames, _type]
|
119
123
|
else
|
120
124
|
end
|
121
|
-
"#{write_lhs(k, parmnames)}
|
122
|
-
|
125
|
+
"#{write_lhs(k, parmnames)} #{assign} #{write_rhs(v, 2.1)}" # 2: parenthesize groups
|
126
|
+
end
|
127
|
+
|
128
|
+
def to_s
|
129
|
+
rules.map {|k, v| write_rule(k, v) }.join("\n")
|
123
130
|
end
|
124
131
|
|
125
132
|
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.3
|
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-03-
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|