cddlc 0.2.5 → 0.2.7

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: dcc0bfbc969c582b8e4e40d841a908e514a9255b98215a0b90a658bcde763737
4
- data.tar.gz: 82399e691f628b544bc236c1a4648ff36e977f075501235f1e07cfeac3cee6ed
3
+ metadata.gz: f9b2369e311571fc7dd58410f31098071ff75e8d53c144d3a478bc957945d7ae
4
+ data.tar.gz: 326423811614449c38fb1af24e5a2fae1fa1cb4e467084f024e62c9cd514ac62
5
5
  SHA512:
6
- metadata.gz: e07d69bb1e25bbcf081cc8693429e489ed537712ace54ad14fcec31fb852ca630337d8617e00d380a0a2930ab1f9443feb02294e38e4d63c5af737960bf4e59e
7
- data.tar.gz: 22ccbe0f63ee9675522c3303463d28e30381e535eee4431ca1696412b24b576580705ef3e6fc84c4978bc868367014aa9d33c71574f4b00e4cc7f60d0ac904f9
6
+ metadata.gz: 0eac4ccf86acb957e9abf0eba253a61e07de25a84aea3f6a34e547a9e77b80e8d22f9ecbf106404d272920be114dea28074e65aa59eb2081e72dde942b28a8b3
7
+ data.tar.gz: 03f7f303c48ae86ab3d99ecff74f9ddf7c07d23ec60660611aec0b734f62790f7f1a26f1b8f758950f7ae2414d5b734f30bd97352df4f1b6782b046f3117a0de
data/bin/cddlc CHANGED
@@ -64,7 +64,7 @@ begin
64
64
  opts.on("-2", "--[no-]cddl2", "Perform some CDDL 2.0 processing") do |v|
65
65
  $options.cddl2 = v
66
66
  end
67
- opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :enum, :cddl], "Target format") do |v|
67
+ opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :const, :enum, :cddl], "Target format") do |v|
68
68
  $options.target = v
69
69
  end
70
70
  opts.on("-sRULE", "--start=RULE", String, "Start rule name") do |v|
@@ -152,6 +152,9 @@ when :neat, :json
152
152
  puts JSON.neat_generate(result, after_comma: 1, after_colon: 1)
153
153
  when :yaml
154
154
  puts result.to_yaml
155
+ when :const
156
+ require_relative "../lib/processor/cddl-constants.rb"
157
+ puts cddl.extract_constants.to_yaml
155
158
  when :enum
156
159
  rules = cddl.rules
157
160
  rules.each do |k, v|
data/cddlc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cddlc"
3
- s.version = "0.2.5"
3
+ s.version = "0.2.7"
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"
@@ -0,0 +1,27 @@
1
+ require_relative "../cddlc.rb"
2
+ require_relative "./cddl-visitor.rb"
3
+
4
+ class CDDL
5
+ def constant_evaluate(rhs)
6
+ case rhs
7
+ in ["number", n]
8
+ [true, eval(n)]
9
+ in ["text", n]
10
+ [true, n]
11
+ in ["name", n]
12
+ if nv = rules[n]
13
+ constant_evaluate(nv)
14
+ end
15
+ else
16
+ [false]
17
+ end
18
+ end
19
+ def extract_constants
20
+ nr = {}
21
+ rules.each do |k, v|
22
+ isconstant, value = constant_evaluate(v)
23
+ nr[k] = value if isconstant
24
+ end
25
+ nr
26
+ end
27
+ end
@@ -61,12 +61,14 @@ class CDDL
61
61
  keyname
62
62
  end
63
63
  new_value2 = flattening_mogrify(new_name, value, symtab, alias_rules)
64
- if ar = alias_rules[new_name]
65
- fail [:ALIAS_RULES, ar, new_value].inspect if ar != new_value2
66
- else
67
- alias_rules[new_name] = new_value2
64
+ new_name2 = new_name
65
+ n = 0
66
+ while ar = alias_rules[new_name2] and ar != new_value2
67
+ n += 1
68
+ new_name2 = new_name << "@" << n.to_s
68
69
  end
69
- [true, ["mem", cut, key, ["name", new_name]]]
70
+ alias_rules[new_name2] = new_value2
71
+ [true, ["mem", cut, key, ["name", new_name2]]]
70
72
  end
71
73
  else
72
74
  false
@@ -74,8 +76,8 @@ class CDDL
74
76
  end
75
77
  step2 = visit(step1) do |here|
76
78
  case here
77
- in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE], ["name", MOGRIFIED_ID_RE => new_name]]]
78
- [true, ["name", new_name]]
79
+ in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE], ["name", MOGRIFIED_ID_RE => new_name2]]]
80
+ [true, ["name", new_name2]]
79
81
  else
80
82
  false
81
83
  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.2.5
4
+ version: 0.2.7
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-01-27 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,6 +105,7 @@ files:
105
105
  - lib/cddlc.rb
106
106
  - lib/parser/cddl-util.rb
107
107
  - lib/parser/cddlgrammar.rb
108
+ - lib/processor/cddl-constants.rb
108
109
  - lib/processor/cddl-expander.rb
109
110
  - lib/processor/cddl-flattening.rb
110
111
  - lib/processor/cddl-undefined.rb