cddlc 0.0.5 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cddlc +70 -1
- data/cddlc.gemspec +2 -2
- data/data/prelude.cddl +45 -0
- data/data/rfc9052.cddl +154 -0
- data/lib/cddlc.rb +11 -2
- data/lib/processor/cddl-expander.rb +56 -0
- data/lib/processor/cddl-undefined.rb +29 -0
- data/lib/processor/cddl-visitor.rb +42 -0
- data/lib/writer/cddl-writer.rb +104 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 446e27ac8733454e0a3a9a9e2f24a43f600f60a414400419287fe147649a7a1f
|
4
|
+
data.tar.gz: 1a4e7b41949419befd15479d0373bf3c316e22c62a6796c6453db6c3467f2b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fce60c859d8b361973c52a9e4d0a4e18908a7978d938a91c0e50125d64db3a5d704a9cc7f6ad8d17fb7f242bed3f31bb5df2107459d9fdacc57afae9f8df53e
|
7
|
+
data.tar.gz: 2c8a8e5f3653125cb719d6aeb7f46642643b561702824a4fcdd404dd40bcdf3ae362ca5cda5323b97f6da521dc555677d8f5139774a12ef9b2f599539b08850e
|
data/bin/cddlc
CHANGED
@@ -52,7 +52,16 @@ begin
|
|
52
52
|
opts.on("-r", "--[no-]rules", "Process rules") do |v|
|
53
53
|
$options.rules = v
|
54
54
|
end
|
55
|
-
opts.on("-
|
55
|
+
opts.on("-x", "--[no-]expand", "Expand generics") do |v|
|
56
|
+
$options.expand_generics = v
|
57
|
+
end
|
58
|
+
opts.on("-u", "--[no-]undefined", "Note undefined names") do |v|
|
59
|
+
$options.note_undefined = v
|
60
|
+
end
|
61
|
+
opts.on("-2", "--[no-]cddl2", "Perform some CDDL 2.0 processing") do |v|
|
62
|
+
$options.cddl2 = v
|
63
|
+
end
|
64
|
+
opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :enum, :cddl], "Target format") do |v|
|
56
65
|
$options.target = v
|
57
66
|
end
|
58
67
|
end
|
@@ -70,11 +79,58 @@ cddl_file = ARGF.read
|
|
70
79
|
|
71
80
|
cddl = CDDL.from_cddl(cddl_file)
|
72
81
|
result = if $options.rules
|
82
|
+
if $options.expand_generics
|
83
|
+
require_relative "../lib/processor/cddl-expander.rb"
|
84
|
+
cddl.expand_generics
|
85
|
+
end
|
73
86
|
cddl.rules
|
74
87
|
else
|
88
|
+
warn "** can't expand in tree; use -r flag as well" if $options.expand_generics
|
75
89
|
cddl.tree
|
76
90
|
end
|
77
91
|
|
92
|
+
warn "** can't note undefined for target != cddl" if $options.note_undefined && $options.target != :cddl
|
93
|
+
|
94
|
+
if $options.cddl2
|
95
|
+
require_relative '../lib/processor/cddl-undefined.rb'
|
96
|
+
directives = cddl_file.lines.grep(/^;# /).map(&:chomp).map{|l| l.sub(/^;#\s+/, '')}
|
97
|
+
# puts "** Directives: <<"
|
98
|
+
# puts directives
|
99
|
+
directives.each do |di|
|
100
|
+
case di
|
101
|
+
when /\Ainclude\s+([-._a-zA-Z0-9]+)(?:\s+as\s+([-._a-zA-Z0-9]+))?\s*\z/
|
102
|
+
docref = $1
|
103
|
+
explicit_preferred_tag = $2
|
104
|
+
preferred_tag = explicit_preferred_tag || docref
|
105
|
+
puts "PREFERRED_TAG #{preferred_tag}" if $options.verbose
|
106
|
+
puts "DOCREF #{docref}" if $options.verbose
|
107
|
+
fn = docref.downcase << ".cddl"
|
108
|
+
io = File.open(fn) rescue File.open(CDDL::DATA_DIR + fn) # XXX CDDL_PATH
|
109
|
+
include_file = io.read
|
110
|
+
# XXX: processing directives recursively!
|
111
|
+
included_cddl = CDDL.from_cddl(include_file)
|
112
|
+
# XXX: Should namespace that thing now! all names -> preferred_tag.name
|
113
|
+
p included_cddl.rules.keys
|
114
|
+
# XXX: do once, first, to rename COSE_Key to RFC9052.COSE_Key
|
115
|
+
loop do
|
116
|
+
undef_rule, _undef_gen = cddl.cddl_undefined # ignore undef_gen for now
|
117
|
+
# p undef_rule
|
118
|
+
got_more = false
|
119
|
+
undef_rule.each do |name|
|
120
|
+
if rule = included_cddl.rules[name]
|
121
|
+
cddl.rules[name] = rule # XXX must be namespaced!
|
122
|
+
puts "IMPORTED #{name} from #{fn}" # ...: #{rule}... if $options.verbose
|
123
|
+
got_more = true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
break unless got_more
|
127
|
+
end
|
128
|
+
else
|
129
|
+
warn "** unknown directive '#{di}' ignored"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
78
134
|
case $options.target
|
79
135
|
when :basic, nil
|
80
136
|
pp result
|
@@ -100,6 +156,19 @@ when :enum
|
|
100
156
|
end
|
101
157
|
end
|
102
158
|
end
|
159
|
+
when :cddl
|
160
|
+
require_relative '../lib/writer/cddl-writer.rb'
|
161
|
+
if $options.note_undefined
|
162
|
+
require_relative '../lib/processor/cddl-undefined.rb'
|
163
|
+
undef_rule, undef_gen = cddl.cddl_undefined
|
164
|
+
undef_rule.each do |k|
|
165
|
+
puts ";;; *** undefined: #{k}"
|
166
|
+
end
|
167
|
+
undef_gen.each do |k|
|
168
|
+
puts ";;; *** undefined: #{k}<>"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
puts cddl.to_s
|
103
172
|
else
|
104
173
|
warn ["Unknown target format: ", $options.target].inspect
|
105
174
|
end
|
data/cddlc.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cddlc"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.1.1"
|
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"
|
7
7
|
s.email = "cabo@tzi.org"
|
8
8
|
s.license = "MIT"
|
9
9
|
s.homepage = "http://github.com/cabo/cddlc"
|
10
|
-
s.files = Dir['lib/**/*.rb'] + %w(cddlc.gemspec) + Dir['bin/**/*.rb']
|
10
|
+
s.files = Dir['lib/**/*.rb'] + %w(cddlc.gemspec) + Dir['data/*.cddl'] + Dir['bin/**/*.rb']
|
11
11
|
s.executables = Dir['bin/*'].map {|x| File.basename(x)}
|
12
12
|
s.required_ruby_version = '>= 1.9.2'
|
13
13
|
|
data/data/prelude.cddl
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
any = #
|
2
|
+
|
3
|
+
uint = #0
|
4
|
+
nint = #1
|
5
|
+
int = uint / nint
|
6
|
+
|
7
|
+
bstr = #2
|
8
|
+
bytes = bstr
|
9
|
+
tstr = #3
|
10
|
+
text = tstr
|
11
|
+
|
12
|
+
tdate = #6.0(tstr)
|
13
|
+
time = #6.1(number)
|
14
|
+
number = int / float
|
15
|
+
biguint = #6.2(bstr)
|
16
|
+
bignint = #6.3(bstr)
|
17
|
+
bigint = biguint / bignint
|
18
|
+
integer = int / bigint
|
19
|
+
unsigned = uint / biguint
|
20
|
+
decfrac = #6.4([e10: int, m: integer])
|
21
|
+
bigfloat = #6.5([e2: int, m: integer])
|
22
|
+
eb64url = #6.21(any)
|
23
|
+
eb64legacy = #6.22(any)
|
24
|
+
eb16 = #6.23(any)
|
25
|
+
encoded-cbor = #6.24(bstr)
|
26
|
+
uri = #6.32(tstr)
|
27
|
+
b64url = #6.33(tstr)
|
28
|
+
b64legacy = #6.34(tstr)
|
29
|
+
regexp = #6.35(tstr)
|
30
|
+
mime-message = #6.36(tstr)
|
31
|
+
cbor-any = #6.55799(any)
|
32
|
+
|
33
|
+
float16 = #7.25
|
34
|
+
float32 = #7.26
|
35
|
+
float64 = #7.27
|
36
|
+
float16-32 = float16 / float32
|
37
|
+
float32-64 = float32 / float64
|
38
|
+
float = float16-32 / float64
|
39
|
+
|
40
|
+
false = #7.20
|
41
|
+
true = #7.21
|
42
|
+
bool = false / true
|
43
|
+
nil = #7.22
|
44
|
+
null = nil
|
45
|
+
undefined = #7.23
|
data/data/rfc9052.cddl
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
|
2
|
+
start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types
|
3
|
+
|
4
|
+
; This is defined to make the tool quieter:
|
5
|
+
Internal_Types = Sig_structure / Enc_structure / MAC_structure
|
6
|
+
|
7
|
+
|
8
|
+
label = int / tstr
|
9
|
+
values = any
|
10
|
+
|
11
|
+
|
12
|
+
COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message
|
13
|
+
|
14
|
+
COSE_Untagged_Message = COSE_Sign / COSE_Sign1 /
|
15
|
+
COSE_Encrypt / COSE_Encrypt0 /
|
16
|
+
COSE_Mac / COSE_Mac0
|
17
|
+
|
18
|
+
COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged /
|
19
|
+
COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged /
|
20
|
+
COSE_Mac_Tagged / COSE_Mac0_Tagged
|
21
|
+
|
22
|
+
|
23
|
+
Headers = (
|
24
|
+
protected : empty_or_serialized_map,
|
25
|
+
unprotected : header_map
|
26
|
+
)
|
27
|
+
|
28
|
+
header_map = {
|
29
|
+
Generic_Headers,
|
30
|
+
* label => values
|
31
|
+
}
|
32
|
+
|
33
|
+
empty_or_serialized_map = bstr .cbor header_map / bstr .size 0
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
Generic_Headers = (
|
38
|
+
? 1 => int / tstr, ; algorithm identifier
|
39
|
+
? 2 => [+label], ; criticality
|
40
|
+
? 3 => tstr / int, ; content type
|
41
|
+
? 4 => bstr, ; key identifier
|
42
|
+
? ( 5 => bstr // ; IV
|
43
|
+
6 => bstr ) ; Partial IV
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
COSE_Sign_Tagged = #6.98(COSE_Sign)
|
48
|
+
|
49
|
+
|
50
|
+
COSE_Sign = [
|
51
|
+
Headers,
|
52
|
+
payload : bstr / nil,
|
53
|
+
signatures : [+ COSE_Signature]
|
54
|
+
]
|
55
|
+
|
56
|
+
|
57
|
+
COSE_Signature = [
|
58
|
+
Headers,
|
59
|
+
signature : bstr
|
60
|
+
]
|
61
|
+
|
62
|
+
|
63
|
+
COSE_Sign1_Tagged = #6.18(COSE_Sign1)
|
64
|
+
|
65
|
+
|
66
|
+
COSE_Sign1 = [
|
67
|
+
Headers,
|
68
|
+
payload : bstr / nil,
|
69
|
+
signature : bstr
|
70
|
+
]
|
71
|
+
|
72
|
+
|
73
|
+
Sig_structure = [
|
74
|
+
context : "Signature" / "Signature1",
|
75
|
+
body_protected : empty_or_serialized_map,
|
76
|
+
? sign_protected : empty_or_serialized_map,
|
77
|
+
external_aad : bstr,
|
78
|
+
payload : bstr
|
79
|
+
]
|
80
|
+
|
81
|
+
|
82
|
+
COSE_Encrypt_Tagged = #6.96(COSE_Encrypt)
|
83
|
+
|
84
|
+
|
85
|
+
COSE_Encrypt = [
|
86
|
+
Headers,
|
87
|
+
ciphertext : bstr / nil,
|
88
|
+
recipients : [+COSE_recipient]
|
89
|
+
]
|
90
|
+
|
91
|
+
|
92
|
+
COSE_recipient = [
|
93
|
+
Headers,
|
94
|
+
ciphertext : bstr / nil,
|
95
|
+
? recipients : [+COSE_recipient]
|
96
|
+
]
|
97
|
+
|
98
|
+
|
99
|
+
COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0)
|
100
|
+
|
101
|
+
|
102
|
+
COSE_Encrypt0 = [
|
103
|
+
Headers,
|
104
|
+
ciphertext : bstr / nil,
|
105
|
+
]
|
106
|
+
|
107
|
+
|
108
|
+
Enc_structure = [
|
109
|
+
context : "Encrypt" / "Encrypt0" / "Enc_Recipient" /
|
110
|
+
"Mac_Recipient" / "Rec_Recipient",
|
111
|
+
protected : empty_or_serialized_map,
|
112
|
+
external_aad : bstr
|
113
|
+
]
|
114
|
+
|
115
|
+
|
116
|
+
COSE_Mac_Tagged = #6.97(COSE_Mac)
|
117
|
+
|
118
|
+
|
119
|
+
COSE_Mac = [
|
120
|
+
Headers,
|
121
|
+
payload : bstr / nil,
|
122
|
+
tag : bstr,
|
123
|
+
recipients : [+COSE_recipient]
|
124
|
+
]
|
125
|
+
|
126
|
+
|
127
|
+
COSE_Mac0_Tagged = #6.17(COSE_Mac0)
|
128
|
+
|
129
|
+
|
130
|
+
COSE_Mac0 = [
|
131
|
+
Headers,
|
132
|
+
payload : bstr / nil,
|
133
|
+
tag : bstr,
|
134
|
+
]
|
135
|
+
|
136
|
+
|
137
|
+
MAC_structure = [
|
138
|
+
context : "MAC" / "MAC0",
|
139
|
+
protected : empty_or_serialized_map,
|
140
|
+
external_aad : bstr,
|
141
|
+
payload : bstr
|
142
|
+
]
|
143
|
+
|
144
|
+
|
145
|
+
COSE_Key = {
|
146
|
+
1 => tstr / int, ; kty
|
147
|
+
? 2 => bstr, ; kid
|
148
|
+
? 3 => tstr / int, ; alg
|
149
|
+
? 4 => [+ (tstr / int) ], ; key_ops
|
150
|
+
? 5 => bstr, ; Base IV
|
151
|
+
* label => values
|
152
|
+
}
|
153
|
+
|
154
|
+
COSE_KeySet = [+COSE_Key]
|
data/lib/cddlc.rb
CHANGED
@@ -50,8 +50,8 @@ class CDDL
|
|
50
50
|
fail name
|
51
51
|
end
|
52
52
|
@rules[name] =
|
53
|
-
if old = @rules[name]
|
54
|
-
fail "duplicate rule for name #{name}" unless cho
|
53
|
+
if (old = @rules[name]) && old != val
|
54
|
+
fail "duplicate rule for name #{name} #{old.inspect} #{val.inspect}" unless cho
|
55
55
|
if Array === old && old[0] == cho
|
56
56
|
old.dup << val
|
57
57
|
else
|
@@ -66,4 +66,13 @@ class CDDL
|
|
66
66
|
@rules
|
67
67
|
end
|
68
68
|
|
69
|
+
DATA_DIR = Pathname.new(__FILE__) + "../../data/"
|
70
|
+
|
71
|
+
def prelude
|
72
|
+
if @prelude.nil?
|
73
|
+
@prelude = CDDL.from_cddl(File.read(DATA_DIR + "prelude.cddl"))
|
74
|
+
|
75
|
+
end
|
76
|
+
@prelude
|
77
|
+
end
|
69
78
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "../cddlc.rb"
|
2
|
+
require_relative "./cddl-visitor.rb"
|
3
|
+
|
4
|
+
class CDDL
|
5
|
+
def substitute(prod, parms, args, &block)
|
6
|
+
subs = Hash[parms.zip(args)]
|
7
|
+
visit(prod) do |p, &block1|
|
8
|
+
case p
|
9
|
+
in ["gen", name, *gen_args]
|
10
|
+
[true, gen_apply(name, gen_args, &block1)]
|
11
|
+
in ["name", name]
|
12
|
+
if replacement = subs[name]
|
13
|
+
[true, visit(expand_prod(replacement), &block)]
|
14
|
+
end
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def gen_apply(gen_name, gen_args, &block)
|
21
|
+
gen_parms, gen_prod = @gen[gen_name]
|
22
|
+
fail "** no generic for #{gen_name}<#{gen_args}>" unless gen_parms
|
23
|
+
substitute(gen_prod, gen_parms, gen_args, &block)
|
24
|
+
end
|
25
|
+
def expand_prod(prod)
|
26
|
+
visit(prod) do |p, &block|
|
27
|
+
case p
|
28
|
+
in ["gen", name, *gen_args]
|
29
|
+
[true, gen_apply(name, gen_args, &block)]
|
30
|
+
else
|
31
|
+
[false]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def expand_generics
|
36
|
+
@gen = {}
|
37
|
+
rules.each do |name, prod|
|
38
|
+
if Array === name
|
39
|
+
@gen[name[0]] = [name[1..-1], prod]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
p @gen if $options.verbose
|
43
|
+
@gen.each do |k, v|
|
44
|
+
namep = v[0]
|
45
|
+
fail unless rules[[k, *namep]] == v[1]
|
46
|
+
rules.delete([k, *namep])
|
47
|
+
end
|
48
|
+
@new_rules = {}
|
49
|
+
rules.each do |name, prod|
|
50
|
+
fail if Array === name
|
51
|
+
@new_rules[name] = expand_prod(prod)
|
52
|
+
end
|
53
|
+
p @new_rules if $options.verbose
|
54
|
+
@rules = @new_rules
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "../cddlc.rb"
|
2
|
+
require_relative "./cddl-visitor.rb"
|
3
|
+
require_relative "./cddl-expander.rb"
|
4
|
+
|
5
|
+
class CDDL
|
6
|
+
def cddl_undefined
|
7
|
+
# currently only works on expanded...
|
8
|
+
cddl2 = self
|
9
|
+
cddl2.expand_generics
|
10
|
+
used = {}
|
11
|
+
gen_used = {}
|
12
|
+
def_gen = {}
|
13
|
+
cddl2.rules.each do |k, v|
|
14
|
+
def_gen[k[0]] = true if Array === k
|
15
|
+
cddl2.visit(v) do |p, &block|
|
16
|
+
case p
|
17
|
+
in ["gen", name, *_gen_args]
|
18
|
+
gen_used[name] = true
|
19
|
+
in ["name", name]
|
20
|
+
used[name] = true
|
21
|
+
else
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
[used.keys.reject {|name| cddl2.rules[name] || prelude.rules[name]},
|
27
|
+
gen_used.keys.reject {|name| def_gen[name] }]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative "../cddlc.rb"
|
2
|
+
|
3
|
+
class CDDL
|
4
|
+
def visit_all(prod_array, &block)
|
5
|
+
prod_array.map {|prod| visit(prod, &block)}
|
6
|
+
end
|
7
|
+
def visit(prod, &block)
|
8
|
+
done, ret = block.call(prod, &block)
|
9
|
+
if done
|
10
|
+
return ret
|
11
|
+
end
|
12
|
+
|
13
|
+
case prod
|
14
|
+
in ["gen", name, *types]
|
15
|
+
["gen", name, *visit_all(types, &block)]
|
16
|
+
in ["op", op, *prods]
|
17
|
+
["op", op, *visit_all(prods, &block)]
|
18
|
+
in ["map", prod]
|
19
|
+
["map", visit(prod, &block)]
|
20
|
+
in ["ary", prod]
|
21
|
+
["ary", visit(prod, &block)]
|
22
|
+
in ["gcho", *prods]
|
23
|
+
["gcho", *visit_all(prods, &block)]
|
24
|
+
in ["tcho", *prods]
|
25
|
+
["tcho", *visit_all(prods, &block)]
|
26
|
+
in ["seq", *prods]
|
27
|
+
["seq", *visit_all(prods, &block)]
|
28
|
+
in ["enum", prod]
|
29
|
+
["enum", visit(prod, &block)]
|
30
|
+
in ["unwrap", prod]
|
31
|
+
["unwrap", visit(prod, &block)] # XXX, this may need to be bottled in a rule
|
32
|
+
in ["prim", Array => prod, *prods]
|
33
|
+
["prim", visit(prod, &block), *visit_all(prods, &block)]
|
34
|
+
in ["mem", *prods]
|
35
|
+
["mem", *visit_all(prods, &block)]
|
36
|
+
in ["rep", s, e, prod]
|
37
|
+
["rep", s, e, visit(prod, &block)]
|
38
|
+
else
|
39
|
+
prod
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require_relative "../cddlc.rb"
|
2
|
+
|
3
|
+
class CDDL
|
4
|
+
|
5
|
+
def write_lhs(k)
|
6
|
+
case k
|
7
|
+
in [id, *parms]
|
8
|
+
"#{id}<#{parms.join(", ")}>"
|
9
|
+
in String
|
10
|
+
k
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# precedence:
|
15
|
+
# 0: // gcho
|
16
|
+
# 1: , seq
|
17
|
+
# 2: / tcho -> (type1)
|
18
|
+
# 3: (type1) .xxx op -> type2
|
19
|
+
# 4: type2
|
20
|
+
|
21
|
+
def prec_check(inner, targetprec, prec, indent_s)
|
22
|
+
if targetprec > prec
|
23
|
+
"(#{inner.gsub("\n", "\n" << indent_s)})" # XXX embedded byte strings
|
24
|
+
else
|
25
|
+
inner
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def write_rhs(v, targetprec = 0, indent = 0)
|
30
|
+
# warn "** #{v.inspect}"
|
31
|
+
indent_p = " " * indent
|
32
|
+
indent += 1
|
33
|
+
indent_s = " " * indent
|
34
|
+
prec, ret =
|
35
|
+
case v
|
36
|
+
in ["name", id]
|
37
|
+
[4, id]
|
38
|
+
in ["gen", id, *parms] # oops -- namep vs. namea; ouch
|
39
|
+
[4, "#{id}<#{parms.map{write_rhs(_1, 2, indent)}.join(", ")}>"]
|
40
|
+
in ["tcho", *types]
|
41
|
+
[2, types.map{write_rhs(_1, 3, indent)}.join(" / ")]
|
42
|
+
in ["gcho", *groups]
|
43
|
+
[0, groups.map{write_rhs(_1, 2, indent)}.join(" // ")]
|
44
|
+
in ["op", op, l, r]
|
45
|
+
[3, "#{write_rhs(l, 3, indent)} #{op} #{write_rhs(r, 3, indent)}"]
|
46
|
+
in ["map", group]
|
47
|
+
[4, "{#{write_rhs(group, 0, indent)}}"]
|
48
|
+
in ["ary", group]
|
49
|
+
[4, "[#{write_rhs(group, 0, indent)}]"]
|
50
|
+
in ["unwrap", namep]
|
51
|
+
[4, "~#{write_rhs(namep, 4, indent)}"]
|
52
|
+
in ["enum", ["name", _name] => namep]
|
53
|
+
[4, "&#{write_rhs(namep, 4, indent)}"]
|
54
|
+
in ["enum", ["gen", _name, *types] => namep]
|
55
|
+
[4, "&#{write_rhs(namep, 4, indent)})"]
|
56
|
+
in ["enum", group]
|
57
|
+
[4, "&(#{write_rhs(group, 0, indent)})"]
|
58
|
+
in ["prim"]
|
59
|
+
[4, "#"]
|
60
|
+
in ["prim", maj]
|
61
|
+
[4, "##{maj}"]
|
62
|
+
in ["prim", maj, min]
|
63
|
+
[4, "##{maj}.#{min}"]
|
64
|
+
in ["prim", 6, Integer => tag, type]
|
65
|
+
[4, "#6.#{tag}(#{write_rhs(type, 0, indent)})"]
|
66
|
+
in ["prim", 6, nil, type]
|
67
|
+
[4, "#6(#{write_rhs(type, 0, indent)})"]
|
68
|
+
# prim: extension for #6.<i>(t)
|
69
|
+
in ["seq", *groups]
|
70
|
+
case groups.size
|
71
|
+
when 0; [4, ""]
|
72
|
+
# when 1; "#{write_rhs(g[0], targetprec, indent)}"
|
73
|
+
else
|
74
|
+
[1, "\n#{indent_p}#{groups.map{write_rhs(_1, 1, indent)}.join(",\n#{indent_p}")},\n"]
|
75
|
+
end
|
76
|
+
in ["rep", s, e, group]
|
77
|
+
occur = case [s, e]
|
78
|
+
in [1, 1]; ""
|
79
|
+
in [0, 1]; "? "
|
80
|
+
in [0, false]; "* "
|
81
|
+
in [1, false]; "+ "
|
82
|
+
else
|
83
|
+
"#{s}*#{e || ""}"
|
84
|
+
end
|
85
|
+
[1, "#{occur}#{write_rhs(group, 2, indent)}"]
|
86
|
+
in ["mem", nil, t2]
|
87
|
+
[2, write_rhs(t2, 2, indent)]
|
88
|
+
in ["mem", t1, t2]
|
89
|
+
[2, "#{write_rhs(t1, 2, indent)} => #{write_rhs(t2, 2, indent)}"]
|
90
|
+
in ["text", t]
|
91
|
+
[4, "\"#{t}\""] # XXX escape
|
92
|
+
in ["number", t]
|
93
|
+
[4, t.to_s]
|
94
|
+
end
|
95
|
+
prec_check(ret, targetprec, prec, indent_s)
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
rules.map {|k, v|
|
100
|
+
"#{write_lhs(k)} = #{write_rhs(v, 2)}" # 2: parenthesize groups
|
101
|
+
}.join("\n")
|
102
|
+
end
|
103
|
+
|
104
|
+
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,9 +75,15 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- bin/cddlc
|
77
77
|
- cddlc.gemspec
|
78
|
+
- data/prelude.cddl
|
79
|
+
- data/rfc9052.cddl
|
78
80
|
- lib/cddlc.rb
|
79
81
|
- lib/parser/cddl-util.rb
|
80
82
|
- lib/parser/cddlgrammar.rb
|
83
|
+
- lib/processor/cddl-expander.rb
|
84
|
+
- lib/processor/cddl-undefined.rb
|
85
|
+
- lib/processor/cddl-visitor.rb
|
86
|
+
- lib/writer/cddl-writer.rb
|
81
87
|
homepage: http://github.com/cabo/cddlc
|
82
88
|
licenses:
|
83
89
|
- MIT
|
@@ -97,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
103
|
- !ruby/object:Gem::Version
|
98
104
|
version: '0'
|
99
105
|
requirements: []
|
100
|
-
rubygems_version: 3.2
|
106
|
+
rubygems_version: 3.4.2
|
101
107
|
signing_key:
|
102
108
|
specification_version: 4
|
103
109
|
summary: CDDL (Concise Data Definition Language) converters and miscellaneous tools
|