cddlc 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cddlc.gemspec +1 -1
- data/lib/cddlc.rb +37 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0fb30da3097b44521e7c3fe12d6e061f7d4f64d9faa3c1239c22a8e76b629e5
|
4
|
+
data.tar.gz: 7cc5c141bd3833d11efb95ab25dd7649666ee6398efb3c01d95dc7cd8a220802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
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
|
88
|
-
warn "IMPORTED #{name} from #{fn}" if $options.verbose
|
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,
|