cddlc 0.1.7 → 0.2.1

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: 2d56a7033911531ad73966b0807a1c6b9d9c09b9b09638d43274337e067a02fa
4
- data.tar.gz: 609ab555ddc49c64a1dde396b99e01b2c79fd9a4fb63b1efb19ccd0ba3a311c1
3
+ metadata.gz: ea4f2c1a1ecedae6a543bebad045a0063e3b7103b757306a8f1da1fea694c3ca
4
+ data.tar.gz: 247a51f6016e133358fb37e524e0692eec3c84104ea63137b9549e3164ff65ad
5
5
  SHA512:
6
- metadata.gz: c704b7fbc908dd1449a6c267936bea906f689852d54b54291fc8a2bc4ca62c39b2e947223da42069343e5d1b28e997907ffeb451d528c5436a7a96f82de17498
7
- data.tar.gz: 8e9f965b91b31eae2986a5e4c621dc0048bb64308017ec917d1a7b90853b9c6322674eaf4ef034905c8f0c555791e5664112cb905b03255fe72b857f57830f67
6
+ metadata.gz: 1d039d6618590fea6f3baaf19888583afdddcab37887cb4e9fb24b56c1fcf52455964426c8ea8325f2d57fa67e19008c05de791278664c094e3da500455387d8
7
+ data.tar.gz: be73e1a03f41bb0052eac06e1fac77bddb3ef55eade8e2b8f0e4c9f625cd5c7bd928a5b464a693e07826521135bd402583d32d801908a95c2749c9f3508eb253
data/bin/cddlc CHANGED
@@ -15,7 +15,7 @@ def named_keys(tree)
15
15
  when "rep"
16
16
  named_keys(tree[3])
17
17
  when "mem"
18
- key = tree[1]
18
+ key = tree[2]
19
19
  if Array === key && key[0] == "name"
20
20
  [key[1]]
21
21
  end
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.7"
3
+ s.version = "0.2.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"
data/lib/cddlc.rb CHANGED
@@ -55,6 +55,7 @@ class CDDL
55
55
  SAFE_FN = /\A[-._a-zA-Z0-9]+\z/
56
56
  IMPINC = /\A(?:import|include)\z/
57
57
  IDENTIFIER_RE = /\A[A-Za-z@_$]([-.]*[A-Za-z@_$0-9])*\z/
58
+ INT_RE = /\A0|[-]?[1-9][0-9]*\z/
58
59
 
59
60
  def self.from_cddl(s)
60
61
  ast = @@parser.parse s
@@ -1812,7 +1812,9 @@ module CDDLGRAMMAR
1812
1812
  end
1813
1813
 
1814
1814
  module Grpent2
1815
- def ast() repwrap(elements[0], ["mem", elements[1].elements ? elements[1].memberkey.ast : nil, elements[2].ast]) end
1815
+ def ast()
1816
+ repwrap(elements[0], ["mem", *elements[1].elements ? elements[1].memberkey.ast : [false, nil],
1817
+ elements[2].ast]) end
1816
1818
  end
1817
1819
 
1818
1820
  module Grpent3
@@ -2012,7 +2014,7 @@ module CDDLGRAMMAR
2012
2014
  end
2013
2015
 
2014
2016
  module Memberkey2
2015
- def ast() type1.ast end
2017
+ def ast() [!!elements[2].elements, type1.ast] end
2016
2018
  end
2017
2019
 
2018
2020
  module Memberkey3
@@ -2027,7 +2029,7 @@ module CDDLGRAMMAR
2027
2029
  end
2028
2030
 
2029
2031
  module Memberkey4
2030
- def ast() ["text", bareword.text_value] end
2032
+ def ast() [true, ["text", bareword.text_value]] end
2031
2033
  end
2032
2034
 
2033
2035
  module Memberkey5
@@ -2042,7 +2044,7 @@ module CDDLGRAMMAR
2042
2044
  end
2043
2045
 
2044
2046
  module Memberkey6
2045
- def ast() value.ast end
2047
+ def ast() [true, value.ast] end
2046
2048
  end
2047
2049
 
2048
2050
  def _nt_memberkey
@@ -3148,15 +3150,9 @@ module CDDLGRAMMAR
3148
3150
  r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
3149
3151
  r0 = r3
3150
3152
  else
3151
- if has_terminal?(@regexps[gr = '\A[€-􏿽]'] ||= Regexp.new(gr), :regexp, index)
3152
- r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
3153
- r4.extend(SCHAR3)
3154
- r4.extend(SCHAR3)
3155
- @index += 1
3156
- else
3157
- terminal_parse_failure('[€-􏿽]')
3158
- r4 = nil
3159
- end
3153
+ r4 = _nt_NONASCII
3154
+ r4.extend(SCHAR3)
3155
+ r4.extend(SCHAR3)
3160
3156
  if r4
3161
3157
  r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
3162
3158
  r0 = r4
@@ -3951,40 +3947,46 @@ module CDDLGRAMMAR
3951
3947
  r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
3952
3948
  r0 = r2
3953
3949
  else
3954
- if has_terminal?(@regexps[gr = '\A[\\]-􏿽]'] ||= Regexp.new(gr), :regexp, index)
3950
+ if has_terminal?(@regexps[gr = '\A[\\]-~]'] ||= Regexp.new(gr), :regexp, index)
3955
3951
  r3 = true
3956
3952
  @index += 1
3957
3953
  else
3958
- terminal_parse_failure('[\\]-􏿽]')
3954
+ terminal_parse_failure('[\\]-~]')
3959
3955
  r3 = nil
3960
3956
  end
3961
3957
  if r3
3962
3958
  r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
3963
3959
  r0 = r3
3964
3960
  else
3965
- r4 = _nt_SESC
3961
+ r4 = _nt_NONASCII
3966
3962
  if r4
3967
3963
  r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
3968
3964
  r0 = r4
3969
3965
  else
3970
- if (match_len = has_terminal?("\\'", false, index))
3971
- r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
3972
- @index += match_len
3973
- else
3974
- terminal_parse_failure('"\\\\\'"')
3975
- r5 = nil
3976
- end
3966
+ r5 = _nt_SESC
3977
3967
  if r5
3978
3968
  r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
3979
3969
  r0 = r5
3980
3970
  else
3981
- r6 = _nt_CRLF
3971
+ if (match_len = has_terminal?("\\'", false, index))
3972
+ r6 = instantiate_node(SyntaxNode,input, index...(index + match_len))
3973
+ @index += match_len
3974
+ else
3975
+ terminal_parse_failure('"\\\\\'"')
3976
+ r6 = nil
3977
+ end
3982
3978
  if r6
3983
3979
  r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
3984
3980
  r0 = r6
3985
3981
  else
3986
- @index = i0
3987
- r0 = nil
3982
+ r7 = _nt_CRLF
3983
+ if r7
3984
+ r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
3985
+ r0 = r7
3986
+ else
3987
+ @index = i0
3988
+ r0 = nil
3989
+ end
3988
3990
  end
3989
3991
  end
3990
3992
  end
@@ -4623,11 +4625,49 @@ module CDDLGRAMMAR
4623
4625
  r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
4624
4626
  r0 = r1
4625
4627
  else
4626
- if has_terminal?(@regexps[gr = '\A[€-􏿽]'] ||= Regexp.new(gr), :regexp, index)
4628
+ r2 = _nt_NONASCII
4629
+ if r2
4630
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
4631
+ r0 = r2
4632
+ else
4633
+ @index = i0
4634
+ r0 = nil
4635
+ end
4636
+ end
4637
+
4638
+ node_cache[:PCHAR][start_index] = r0
4639
+
4640
+ r0
4641
+ end
4642
+
4643
+ def _nt_NONASCII
4644
+ start_index = index
4645
+ if node_cache[:NONASCII].has_key?(index)
4646
+ cached = node_cache[:NONASCII][index]
4647
+ if cached
4648
+ node_cache[:NONASCII][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
4649
+ @index = cached.interval.end
4650
+ end
4651
+ return cached
4652
+ end
4653
+
4654
+ i0 = index
4655
+ if has_terminal?(@regexps[gr = '\A[ -퟿]'] ||= Regexp.new(gr), :regexp, index)
4656
+ r1 = true
4657
+ @index += 1
4658
+ else
4659
+ terminal_parse_failure('[ -퟿]')
4660
+ r1 = nil
4661
+ end
4662
+ if r1
4663
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
4664
+ r0 = r1
4665
+ else
4666
+ if has_terminal?(@regexps[gr = '\A[-􏿽]'] ||= Regexp.new(gr), :regexp, index)
4627
4667
  r2 = true
4628
4668
  @index += 1
4629
4669
  else
4630
- terminal_parse_failure('[€-􏿽]')
4670
+ terminal_parse_failure('[-􏿽]')
4631
4671
  r2 = nil
4632
4672
  end
4633
4673
  if r2
@@ -4639,7 +4679,7 @@ module CDDLGRAMMAR
4639
4679
  end
4640
4680
  end
4641
4681
 
4642
- node_cache[:PCHAR][start_index] = r0
4682
+ node_cache[:NONASCII][start_index] = r0
4643
4683
 
4644
4684
  r0
4645
4685
  end
@@ -2,15 +2,14 @@ require_relative "../cddlc.rb"
2
2
  require_relative "./cddl-visitor.rb"
3
3
 
4
4
  class CDDL
5
- ID_RE = /\A[A-Za-z@_$]([-.]*[A-Za-z@_$0-9])*\z/
6
5
  MOGRIFIED_ID_RE = /\A\$\.[A-Za-z@_$]([-.]*[A-Za-z@_$0-9])*\z/
7
6
  def flattening_key_name(key, value, env = nil)
8
7
  case key
9
- in ["enum", ["mem", ["text", ID_RE => text], _]]
8
+ in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE => text], _]]
10
9
  [false, text]
11
- in ["text", ID_RE => text]
10
+ in ["text", IDENTIFIER_RE => text]
12
11
  [false, text]
13
- in ["number", /\A0|[-]?[1-9][0-9]*\z/ => intval] if env
12
+ in ["number", INT_RE => intval] if env
14
13
  [true, "$.#{env}$#{intval}"]
15
14
  else
16
15
  [false]
@@ -21,7 +20,7 @@ class CDDL
21
20
  rules.each do |name, prod|
22
21
  visit(prod) do |here|
23
22
  case here
24
- in ["mem", key, value]
23
+ in ["mem", _cut, key, value]
25
24
  _labeled, keyname = flattening_key_name(key, value, false)
26
25
  if keyname
27
26
  symtab[keyname] << [name, value]
@@ -45,7 +44,7 @@ class CDDL
45
44
  def flattening_mogrify(name, prod, symtab, alias_rules)
46
45
  step1 = visit(prod) do |here|
47
46
  case here
48
- in ["mem", key, value]
47
+ in ["mem", cut, key, value]
49
48
  ### mogrify
50
49
  labeled, keyname = flattening_key_name(key, value, name)
51
50
  if keyname
@@ -67,7 +66,7 @@ class CDDL
67
66
  else
68
67
  alias_rules[new_name] = new_value2
69
68
  end
70
- [true, ["mem", key, ["name", new_name]]]
69
+ [true, ["mem", cut, key, ["name", new_name]]]
71
70
  end
72
71
  else
73
72
  false
@@ -75,7 +74,7 @@ class CDDL
75
74
  end
76
75
  step2 = visit(step1) do |here|
77
76
  case here
78
- in ["enum", ["mem", ["text", ID_RE], ["name", MOGRIFIED_ID_RE => new_name]]]
77
+ in ["enum", ["mem", _cut, ["text", IDENTIFIER_RE], ["name", MOGRIFIED_ID_RE => new_name]]]
79
78
  [true, ["name", new_name]]
80
79
  else
81
80
  false
@@ -33,8 +33,8 @@ class CDDL
33
33
  ["unwrap", visit(prod, &block)] # XXX, this may need to be bottled in a rule
34
34
  in ["prim", prod, *prods]
35
35
  ["prim", visit(prod, &block), *visit_all(prods, &block)]
36
- in ["mem", *prods]
37
- ["mem", *visit_all(prods, &block)]
36
+ in ["mem", cut, *prods]
37
+ ["mem", cut, *visit_all(prods, &block)]
38
38
  in ["rep", s, e, prod]
39
39
  ["rep", s, e, visit(prod, &block)]
40
40
  else
@@ -90,10 +90,14 @@ class CDDL
90
90
  "#{s}*#{e || ""}"
91
91
  end
92
92
  [1, "#{occur}#{write_rhs(group, 2, indent, pn)}"]
93
- in ["mem", nil, t2]
93
+ in ["mem", false, nil, t2]
94
94
  [2, write_rhs(t2, 2, indent, pn)]
95
- in ["mem", t1, t2]
96
- [2, "#{write_rhs(t1, 3, indent, pn)} => #{write_rhs(t2, 2, indent, pn)}"]
95
+ in ["mem", true, ["text", IDENTIFIER_RE => bareword], t2]
96
+ [2, "#{bareword}: #{write_rhs(t2, 2, indent, pn)}"]
97
+ in ["mem", true, ["number", INT_RE => bareword], t2]
98
+ [2, "#{bareword}: #{write_rhs(t2, 2, indent, pn)}"]
99
+ in ["mem", cut, t1, t2]
100
+ [2, "#{write_rhs(t1, 3, indent, pn)} #{cut ? "^" : ""}=> #{write_rhs(t2, 2, indent, pn)}"]
97
101
  # 2->3: work around cddl tool limitation
98
102
  in ["bytes", t]
99
103
  [4, t] # XXX not very clean
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.1.7
4
+ version: 0.2.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: 2023-03-11 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.4.6
127
+ rubygems_version: 3.4.10
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: CDDL (Concise Data Definition Language) converters and miscellaneous tools