cddlc 0.3.1 → 0.3.2

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: 9ac6c49d6e3aae903f307b8ca75486ec8a0654bbf9bcb8ce77cfbc32d58b97a2
4
- data.tar.gz: 04c26c80b59ca309c68d0a1ff7e1236f50ddcc10f2aab7d6eddc0c09d5a3f698
3
+ metadata.gz: a38ea6117afabc57b950af7598c2d497bb00f587ec937cbe41b45b33f3775dfe
4
+ data.tar.gz: f726477776dee7586f5f85909473cfb22acc38630cf45995c732d2df7a842ebf
5
5
  SHA512:
6
- metadata.gz: e99d700012b8c6211ee051e20399271ee9e765f92c835eb0c567880b3cf05f343f26c8ab4b28535641f98020916a2ea6b4ccb73f55c61375771f7fc68cbd69f9
7
- data.tar.gz: fd110edebea03f2ebd07e3e670e2861c24caeff9758ecf40edefc4a73034933f22c17b183eff86babb2421472fe9fa10938710ac6965e36a9a1efa36dd7f30a9
6
+ metadata.gz: 332fcf064ebfc558cc82908832575a3fd4f77219f6f1ceb46ffab2270ee4f9273ecc7d83edcc5dc6dc574ef4ccefdbf9fd7c25d10a9f88466dc4e0ca7ae3dc32
7
+ data.tar.gz: 3bbb56ffb6853eaab2792e5518914128ecf734bff0db4651861227bd77eaf4241e29b11306e04937855e46d67c05f3dd55cdde91e86da5ef2d5cc9f7fd4edb96
data/bin/cddlc CHANGED
@@ -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
@@ -94,6 +97,9 @@ cddl_file = ""
94
97
  if $options.start
95
98
  cddl_file << "$.start.$ = #{$options.start}\n"
96
99
  end
100
+ if m = $options.model
101
+ cddl_file << m << "\n"
102
+ end
97
103
 
98
104
  [[$options.include, "include"], [$options.import, "import"]].each do |arr, directive|
99
105
  if arr
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.1"
3
+ s.version = "0.3.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"
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
@@ -226,7 +227,8 @@ class CDDL
226
227
  end
227
228
 
228
229
 
229
- RULE_OP_TO_CHOICE = {"/=" => "tcho", "//=" => "gcho"}
230
+ RULE_OP_TO_CHOICE = {"/=" => ["tcho", "tadd"], "//=" => ["gcho", "gadd"]}
231
+ CHOICERULES = RULE_OP_TO_CHOICE.values.flatten
230
232
 
231
233
  def rules
232
234
  if @rules.nil? # memoize
@@ -258,27 +260,56 @@ class CDDL
258
260
  else
259
261
  fail name
260
262
  end
261
- @rules[name] =
263
+ @rules[name] = nv =
262
264
  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
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
266
272
  else
267
- [cho, old, val]
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
268
276
  end
269
277
  else
270
- val
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
271
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
272
293
  end
273
294
  # warn "** rules #{rules.inspect}"
274
295
  end
275
296
  @rules
276
297
  end
277
298
 
299
+ def check_socket(name, nv, right, wrong, wrong_plain, wrong_kind, kind)
300
+ unless nv[0] == right
301
+ if nv[0] == wrong
302
+ flaw = "#{wrong_kind} choice #{write_rhs([wrong_plain, *nv[1..-1]], 2.1)} in"
303
+ else
304
+ flaw = "plain assignment of #{write_rhs(nv, 2.1)} to"
305
+ end
306
+ warn "** warning: #{flaw} #{kind} socket #{name}"
307
+ end
308
+ end
309
+
278
310
  def prelude
279
311
  if @prelude.nil?
280
312
  @prelude = CDDL.from_cddl(File.read(DATA_DIR + "prelude.cddl"))
281
-
282
313
  end
283
314
  @prelude
284
315
  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 ["tcho", *prods]
31
+ ["tcho", *visit_all(prods, &block)]
28
32
  in ["seq", *prods]
29
33
  ["seq", *visit_all(prods, &block)]
30
34
  in ["enum", prod]
@@ -111,15 +111,24 @@ class CDDL
111
111
  prec_check(ret, targetprec, prec, indent_s)
112
112
  end
113
113
 
114
- def to_s
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
+ v = ["tcho", *rest]
121
+ in ["gadd", *rest]
122
+ assign = "//="
123
+ v = ["gcho", *rest]
118
124
  in ["parm", parmnames, _type]
119
125
  else
120
126
  end
121
- "#{write_lhs(k, parmnames)} = #{write_rhs(v, 2.1)}" # 2: parenthesize groups
122
- }.join("\n")
127
+ "#{write_lhs(k, parmnames)} #{assign} #{write_rhs(v, 2.1)}" # 2: parenthesize groups
128
+ end
129
+
130
+ def to_s
131
+ rules.map {|k, v| write_rule(k, v) }.join("\n")
123
132
  end
124
133
 
125
134
  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.1
4
+ version: 0.3.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: 2024-03-02 00:00:00.000000000 Z
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler