cddlc 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/cddlc.gemspec +1 -1
  3. data/lib/cddlc.rb +37 -8
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed5e9bd6c8caace67d29c6549fd30d59fc2c17c06b671f63868d2ecb6ea0031b
4
- data.tar.gz: 03d6d40e1ebf19da17117ca725ba09c60c33867606953d2566fd86ace2805e9a
3
+ metadata.gz: c0fb30da3097b44521e7c3fe12d6e061f7d4f64d9faa3c1239c22a8e76b629e5
4
+ data.tar.gz: 7cc5c141bd3833d11efb95ab25dd7649666ee6398efb3c01d95dc7cd8a220802
5
5
  SHA512:
6
- metadata.gz: 2b1790d8845935f61f7c12070dbb95f223a6e1914c813dbf85e4ae3979b1fbcbf37abd5730a3a471c1a5777464a8fc966d36835e20df41d3e19a17203e0969f8
7
- data.tar.gz: f0884c20358c0a7edaf9df050c79d93f3df7dfb42ceb44ee59b3cc0cb8f318a5ad5efa08964dd259d3a211dd6bcc8a1b2eed5f636cae4ca5a80b524c3a40fdab
6
+ metadata.gz: d119b506cf51407c66e882df9bcc59e2019926c3843d8ad5acb0a5dede020f6ecb099284eded1a6cae912db42347edafabb3be79a789d4afd2153015258abe6c
7
+ data.tar.gz: b30fb2251c6daaba6fe3c20a85800b64af61a1908a4ab80596891bf88687f7ec2e441649d9f05d4268e24c9a77c0818cd188a8deada0642ba20fc75961445abd
data/cddlc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cddlc"
3
- s.version = "0.1.2"
3
+ s.version = "0.1.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,4 +1,6 @@
1
1
  require_relative "parser/cddl-util.rb"
2
+ require_relative "processor/cddl-visitor.rb"
3
+ require_relative 'processor/cddl-undefined.rb'
2
4
 
3
5
  class CDDL
4
6
  @@parser = CDDLGRAMMARParser.new
@@ -22,6 +24,21 @@ class CDDL
22
24
  reason.join("\n")
23
25
  end
24
26
 
27
+ # (keeps only renamed rules)
28
+ def rename(rename_map)
29
+ rules.replace(
30
+ Hash[rename_map.map do |o, n|
31
+ [n, visit(rules[o]) do |prod|
32
+ case prod
33
+ in ["name", *] | ["gen", *]
34
+ prod[1] = rename_map[prod[1]] || prod[1]
35
+ else
36
+ end
37
+ false
38
+ end]
39
+ end])
40
+ end
41
+
25
42
  SAFE_FN = /\A[-._a-zA-Z0-9]+\z/
26
43
 
27
44
  def self.from_cddl(s)
@@ -41,8 +58,8 @@ class CDDL
41
58
  case di
42
59
  in ["include" => dir, docref]
43
60
  in ["include" => dir, docref, "as", preferred_tag]
44
- warn "** Ignoring namespace tag #{preferred_tag} for now"
45
61
  in ["import" => dir, docref]
62
+ in ["import" => dir, docref, "as", preferred_tag]
46
63
  else
47
64
  warn "** Can't parse include directive #{di.inspect}"
48
65
  next
@@ -71,26 +88,39 @@ class CDDL
71
88
 
72
89
  include_file = io.read
73
90
  included_cddl = CDDL.from_cddl(include_file)
74
- # XXX: Should namespace that thing now! all names -> preferred_tag.name
75
- # p included_cddl.rules.keys
76
- # XXX: do once, first, to rename COSE_Key to RFC9052.COSE_Key
91
+ if preferred_tag
92
+ included_cddl = included_cddl.deep_clone # needed?
93
+ renamed_names = included_cddl.rules.keys
94
+ name_rename = Hash[
95
+ renamed_names.map { |o|
96
+ n = "#{preferred_tag}.#{o}"
97
+ warn "** Warning: renamed name #{n} already in #{fn}" if included_cddl.rules[n]
98
+ [o, n]}]
99
+ included_cddl.rename(name_rename)
100
+ end
101
+
77
102
  case dir
78
103
  in "import"
79
104
  warn "** IMPORTING #{fn}" if $options.verbose
80
- require_relative '../lib/processor/cddl-undefined.rb'
105
+ undef_rule = nil
81
106
  loop do
82
107
  undef_rule = ret.cddl_undefined # XXX square...
83
108
  # p undef_rule
84
109
  got_more = false
85
110
  undef_rule.each do |name|
86
111
  if rule = included_cddl.rules[name]
87
- ret.rules[name] = rule # XXX must be namespaced!
88
- warn "IMPORTED #{name} from #{fn}" if $options.verbose # ...: #{rule}...
112
+ ret.rules[name] = rule
113
+ warn "IMPORTED #{name} from #{fn}" if $options.verbose
89
114
  got_more = true
90
115
  end
91
116
  end
92
117
  break unless got_more
93
118
  end
119
+ if preferred_tag
120
+ undef_rule.each do |name|
121
+ warn "** Warning: undefined reference #{name} without namespace prefix is defined in namespaced imported module #{fn}" if name_rename[name]
122
+ end
123
+ end
94
124
  in "include"
95
125
  warn "** INCLUDING #{fn}" if $options.verbose
96
126
  included_cddl.rules.each do |k, v|
@@ -137,7 +167,6 @@ class CDDL
137
167
  fail unless name.size == 2
138
168
  name = name[1]
139
169
  when "gen"
140
- require_relative "processor/cddl-visitor.rb"
141
170
  parmnames = name[2..-1]
142
171
  name = name[1] # XXX update val with parm/arg
143
172
  val = ["parm", parmnames,
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann