cddlc 0.3.3 → 0.3.5

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: 87f4f966e5f0937e393d3157c80d345295bd672d088ccc4587c04223c7ec5f94
4
- data.tar.gz: 5be056668436fff6ab9835487326956461a98f748107fd7e0b8c4c7c6cd2dc7b
3
+ metadata.gz: 6d01061fd86124e6e68aae0a7ef043d23c9a2211992f9421e9333c50d8a870ee
4
+ data.tar.gz: 7efe567eeca90c756dac4354791583cae6da812b05eaf4074dfb953f71d09adb
5
5
  SHA512:
6
- metadata.gz: 46d27fe85391c66e58d9006391993eb44d14b828fe1254a1d9911d015a1ed0cd7675e5239cde4f9c90a11adfef78b97ca331d2b50eb1e53ba35808bc5f034164
7
- data.tar.gz: 27be4a4c43b65d7a6e764fc9c66eff853b3b4d37a99dff56c3fc8a5fbe975c341d2709704d82ec03cf4525b1c5a8621ea5e082e412e2d5d432cbf7a8b50e090a
6
+ metadata.gz: c051e4c6c4e319e223dc8126512ffe8c7368b985735c8b15b34ac3ae5dad183f7f80f74e3a4b90f1679877472c8c5a0968f38d73994fc4e3dbb8669a39938c09
7
+ data.tar.gz: 29fce82dbdfd0bf5e14184b8445d3281a648fdd3f1fb982e37020317c23b94100449d21fed9a609a2f041fdc4a035c7842e23f861b5730480f9a828963122fef
data/cddlc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cddlc"
3
- s.version = "0.3.3"
3
+ s.version = "0.3.5"
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"
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_development_dependency 'bundler', '~>1'
17
17
  s.add_dependency 'treetop', '~>1'
18
- s.add_dependency 'json', '~>2'
18
+ # s.add_dependency 'json', '~>2'
19
19
  s.add_dependency 'neatjson', '~>0.10'
20
20
  end
data/data/rfc9581.cddl ADDED
@@ -0,0 +1,118 @@
1
+ Etime = #6.1001(etime-detailed)
2
+
3
+ etime-framework = {
4
+ uint => any ; at least one base time
5
+ * (nint/text) => any ; elective supplementary information
6
+ * uint => any ; critical supplementary information
7
+ }
8
+
9
+ etime-detailed = ({
10
+ $$ETIME-BASETIME
11
+ ClockQuality-group
12
+ * $$ETIME-ELECTIVE
13
+ * $$ETIME-CRITICAL
14
+ * ((nint/text) .feature "etime-elective-extension") => any
15
+ * (uint .feature "etime-critical-extension") => any
16
+ }) .within etime-framework
17
+
18
+
19
+ $$ETIME-BASETIME //= (1: ~time)
20
+
21
+
22
+ $$ETIME-BASETIME //= (4: ~decfrac)
23
+ $$ETIME-BASETIME //= (5: ~bigfloat)
24
+
25
+
26
+ $$ETIME-ELECTIVE //= (-3: uint)
27
+ $$ETIME-ELECTIVE //= (-6: uint)
28
+ $$ETIME-ELECTIVE //= (-9: uint)
29
+ $$ETIME-ELECTIVE //= (-12: uint)
30
+ $$ETIME-ELECTIVE //= (-15: uint)
31
+ $$ETIME-ELECTIVE //= (-18: uint)
32
+
33
+
34
+ $$ETIME-ELECTIVE //= (-1 => $ETIME-TIMESCALE)
35
+ $$ETIME-ELECTIVE //= (-13 => $ETIME-TIMESCALE)
36
+ $$ETIME-CRITICAL //= (13 => $ETIME-TIMESCALE)
37
+
38
+ $ETIME-TIMESCALE /= &(etime-utc: 0)
39
+ $ETIME-TIMESCALE /= &(etime-tai: 1)
40
+
41
+
42
+ ClockQuality-group = (
43
+ ? &(ClockClass: -2) => uint .size 1 ; PTP/RFC8575
44
+ ? &(ClockAccuracy: -4) => uint .size 1 ; PTP/RFC8575
45
+ ? &(OffsetScaledLogVariance: -5) => uint .size 2 ; PTP/RFC8575
46
+ ? &(Uncertainty: -7) => ~time/~duration
47
+ ? &(Guarantee: -8) => ~time/~duration
48
+ )
49
+
50
+
51
+ $$ETIME-ELECTIVE //= (-10: time-zone-info)
52
+ $$ETIME-CRITICAL //= (10: time-zone-info)
53
+
54
+ time-zone-info = tstr .abnf
55
+ ("time-zone-name / time-numoffset" .det IXDTFtz)
56
+ IXDTFtz = '
57
+ time-hour = 2DIGIT ; 00-23
58
+ time-minute = 2DIGIT ; 00-59
59
+ time-numoffset = ("+" / "-") time-hour ":" time-minute
60
+
61
+
62
+
63
+ time-zone-initial = ALPHA / "." / "_"
64
+ time-zone-char = time-zone-initial / DIGIT / "-" / "+"
65
+ time-zone-part = time-zone-initial *time-zone-char
66
+ ; but not "." or ".."
67
+ time-zone-name = time-zone-part *("/" time-zone-part)
68
+ ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
69
+ DIGIT = %x30-39 ; 0-9
70
+ ' ; extracted from [RFC9557] and [RFC3339]
71
+
72
+
73
+ $$ETIME-ELECTIVE //= (-11: suffix-info-map)
74
+ $$ETIME-CRITICAL //= (11: suffix-info-map)
75
+
76
+ suffix-info-map = { * suffix-key => suffix-values }
77
+ suffix-key = tstr .abnf ("suffix-key" .det IXDTF)
78
+ suffix-values = one-or-more<suffix-value>
79
+ one-or-more<T> = T / [ 2* T ]
80
+ suffix-value = tstr .abnf ("suffix-value" .det IXDTF)
81
+
82
+ IXDTF = '
83
+ key-initial = lcalpha / "_"
84
+ key-char = key-initial / DIGIT / "-"
85
+ suffix-key = key-initial *key-char
86
+
87
+ suffix-value = 1*alphanum
88
+ alphanum = ALPHA / DIGIT
89
+ lcalpha = %x61-7A
90
+ ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
91
+ DIGIT = %x30-39 ; 0-9
92
+ ' ; extracted from [RFC9557]
93
+
94
+
95
+ Duration = #6.1002(etime-detailed)
96
+
97
+
98
+ simple-Period = #6.1003([
99
+ start: ~Etime / null
100
+ end: ~Etime / null
101
+ ? duration: ~Duration
102
+ ])
103
+
104
+
105
+ Period = #6.1003([
106
+ (start: ~Etime,
107
+ ((end: ~Etime) //
108
+ (end: null,
109
+ duration: ~Duration))) //
110
+ (start: null,
111
+ end: ~Etime,
112
+ duration: ~Duration)
113
+ ])
114
+
115
+
116
+ etime = #6.1001({* (int/tstr) => any})
117
+ duration = #6.1002({* (int/tstr) => any})
118
+ period = #6.1003([~etime/null, ~etime/null, ?~duration])
@@ -2,6 +2,32 @@ require_relative "../cddlc.rb"
2
2
 
3
3
  class CDDL
4
4
 
5
+ # In each specific case, use the appropriate subset
6
+ ESCAPED_STRING_MAPPINGS = Hash[[
7
+ ["\x08", "b"],
8
+ ["\x09", "t"],
9
+ ["\x0A", "n"],
10
+ ["\x0C", "f"],
11
+ ["\x0D", "r"],
12
+ ["\x22", "\""],
13
+ ["\x27", "'"],
14
+ ["\x2F", "/"],
15
+ ["\x5C", "\\"],
16
+ ]]
17
+
18
+ # TODO: Enable selecting Unicode-friendly variants
19
+ def escape_string(s)
20
+ s.gsub(/[^\n !#-\[\]-~]/) {|ch|
21
+ if m = ESCAPED_STRING_MAPPINGS[ch]
22
+ "\\#{m}"
23
+ elsif (o = ch.ord) < 0x10000
24
+ "\\u#{"%04x" % o}"
25
+ else
26
+ "\\u{#{"%x" % o}}"
27
+ end
28
+ }
29
+ end
30
+
5
31
  def write_lhs(k, parmnames)
6
32
  if parmnames
7
33
  "#{k}<#{parmnames.join(", ")}>"
@@ -104,7 +130,7 @@ class CDDL
104
130
  in ["bytes", t]
105
131
  [4, t] # XXX not very clean
106
132
  in ["text", t]
107
- [4, "\"#{t}\""] # XXX escape
133
+ [4, "\"#{escape_string(t)}\""]
108
134
  in ["number", t]
109
135
  [4, t.to_s]
110
136
  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.3.3
4
+ version: 0.3.5
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-03-06 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1'
41
- - !ruby/object:Gem::Dependency
42
- name: json
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: neatjson
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +88,7 @@ files:
102
88
  - data/rfc9393-sign1.cddl
103
89
  - data/rfc9393-tags.cddl
104
90
  - data/rfc9393.cddl
91
+ - data/rfc9581.cddl
105
92
  - lib/cddlc.rb
106
93
  - lib/parser/cddl-util.rb
107
94
  - lib/parser/cddlgrammar.rb
@@ -130,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
117
  - !ruby/object:Gem::Version
131
118
  version: '0'
132
119
  requirements: []
133
- rubygems_version: 3.4.10
120
+ rubygems_version: 3.5.14
134
121
  signing_key:
135
122
  specification_version: 4
136
123
  summary: CDDL (Concise Data Definition Language) converters and miscellaneous tools