cddlc 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a38ea6117afabc57b950af7598c2d497bb00f587ec937cbe41b45b33f3775dfe
4
- data.tar.gz: f726477776dee7586f5f85909473cfb22acc38630cf45995c732d2df7a842ebf
3
+ metadata.gz: 87f4f966e5f0937e393d3157c80d345295bd672d088ccc4587c04223c7ec5f94
4
+ data.tar.gz: 5be056668436fff6ab9835487326956461a98f748107fd7e0b8c4c7c6cd2dc7b
5
5
  SHA512:
6
- metadata.gz: 332fcf064ebfc558cc82908832575a3fd4f77219f6f1ceb46ffab2270ee4f9273ecc7d83edcc5dc6dc574ef4ccefdbf9fd7c25d10a9f88466dc4e0ca7ae3dc32
7
- data.tar.gz: 3bbb56ffb6853eaab2792e5518914128ecf734bff0db4651861227bd77eaf4241e29b11306e04937855e46d67c05f3dd55cdde91e86da5ef2d5cc9f7fd4edb96
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])
@@ -95,7 +95,7 @@ end
95
95
 
96
96
  cddl_file = ""
97
97
  if $options.start
98
- cddl_file << "$.start.$ = #{$options.start}\n"
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.2"
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
@@ -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
- return old # error
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
- RULE_OP_TO_CHOICE = {"/=" => ["tcho", "tadd"], "//=" => ["gcho", "gadd"]}
231
- CHOICERULES = RULE_OP_TO_CHOICE.values.flatten
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
- @rules[name] = nv =
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 ["tcho", *prods]
31
- ["tcho", *visit_all(prods, &block)]
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]
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cddlc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann