cddl 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +5 -1
  3. package/.release-it.ts +0 -10
  4. package/docs/README.md +0 -47
  5. package/docs/arrays.md +0 -356
  6. package/docs/ast-structure.md +0 -166
  7. package/docs/basic-types.md +0 -243
  8. package/docs/cddl-cheatsheet.md +0 -231
  9. package/docs/comments.md +0 -307
  10. package/docs/groups.md +0 -351
  11. package/docs/operators.md +0 -466
  12. package/docs/properties.md +0 -334
  13. package/docs/ranges.md +0 -339
  14. package/docs/references.md +0 -340
  15. package/docs/variables.md +0 -335
  16. package/src/ast.ts +0 -180
  17. package/src/cli/commands/repl.ts +0 -33
  18. package/src/cli/commands/validate.ts +0 -44
  19. package/src/cli/constants.ts +0 -1
  20. package/src/cli/index.ts +0 -18
  21. package/src/constants.ts +0 -16
  22. package/src/index.ts +0 -12
  23. package/src/lexer.ts +0 -238
  24. package/src/parser.ts +0 -993
  25. package/src/tokens.ts +0 -50
  26. package/src/utils.ts +0 -96
  27. package/tests/__snapshots__/complex_types.test.ts.snap +0 -80
  28. package/tests/__snapshots__/examples.test.ts.snap +0 -1077
  29. package/tests/__snapshots__/group-choices.test.ts.snap +0 -403
  30. package/tests/__snapshots__/parser.test.ts.snap +0 -3045
  31. package/tests/__snapshots__/webdriver-local.test.ts.snap +0 -11192
  32. package/tests/__snapshots__/webdriver-remote.test.ts.snap +0 -16350
  33. package/tests/commands/repl.test.ts +0 -52
  34. package/tests/commands/validate.test.ts +0 -66
  35. package/tests/complex_types.test.ts +0 -18
  36. package/tests/examples.test.ts +0 -25
  37. package/tests/group-choices.test.ts +0 -132
  38. package/tests/lexer.test.ts +0 -63
  39. package/tests/module.test.ts +0 -21
  40. package/tests/parser.test.ts +0 -63
  41. package/tests/utils.test.ts +0 -211
  42. package/tests/webdriver-local.test.ts +0 -15
  43. package/tests/webdriver-remote.test.ts +0 -15
  44. package/tsconfig.json +0 -11
package/docs/comments.md DELETED
@@ -1,307 +0,0 @@
1
- # Comments
2
-
3
- Comments are an important part of CDDL files that provide additional context and information about the definitions. This document explains how comments are represented in the AST.
4
-
5
- ## Comment Definition
6
-
7
- In the AST, a comment is represented by the following structure:
8
-
9
- ```typescript
10
- export type Comment = {
11
- Type: 'comment'
12
- Content: string
13
- Leading: boolean
14
- }
15
- ```
16
-
17
- Where:
18
- - `Type`: Always set to 'comment' to identify this node as a comment
19
- - `Content`: The text content of the comment (without the comment marker)
20
- - `Leading`: A boolean indicating if this is a leading comment (appears before the definition) or a trailing comment (appears after the definition)
21
-
22
- ## Comment Syntax
23
-
24
- In CDDL, comments are denoted by a semicolon `;` and continue until the end of the line:
25
-
26
- ```cddl
27
- ; This is a comment
28
- person = {
29
- name: tstr, ; This is another comment
30
- age: uint
31
- }
32
- ```
33
-
34
- ## Comment Location in the AST
35
-
36
- Comments can be associated with various elements in the AST:
37
-
38
- 1. Groups
39
- 2. Arrays
40
- 3. Variables
41
- 4. Properties
42
-
43
- Each of these elements has a `Comments` field that contains an array of comment objects associated with that element.
44
-
45
- ## Examples
46
-
47
- ### Comments on Group Definitions
48
-
49
- ```cddl
50
- ; This is a comment
51
- ; foobar
52
- ; This is another
53
- ; very nice comment
54
- person = {
55
- ; a good employer
56
- employer: tstr
57
- }
58
- ```
59
-
60
- AST representation:
61
-
62
- ```json
63
- {
64
- "Type": "group",
65
- "Name": "person",
66
- "IsChoiceAddition": false,
67
- "Properties": [
68
- {
69
- "HasCut": true,
70
- "Occurrence": { "n": 1, "m": 1 },
71
- "Name": "employer",
72
- "Type": ["tstr"],
73
- "Comments": [
74
- {
75
- "Type": "comment",
76
- "Content": "a good employer",
77
- "Leading": false
78
- }
79
- ]
80
- }
81
- ],
82
- "Comments": [
83
- {
84
- "Type": "comment",
85
- "Content": "This is a comment",
86
- "Leading": false
87
- },
88
- {
89
- "Type": "comment",
90
- "Content": "foobar",
91
- "Leading": false
92
- },
93
- {
94
- "Type": "comment",
95
- "Content": "This is another",
96
- "Leading": false
97
- },
98
- {
99
- "Type": "comment",
100
- "Content": "very nice comment",
101
- "Leading": false
102
- }
103
- ]
104
- }
105
- ```
106
-
107
- ### Comments on Array Elements
108
-
109
- ```cddl
110
- Geography = [
111
- ; a city
112
- city: tstr,
113
- ; some coordinates
114
- gpsCoordinates: GpsCoordinates
115
- ]
116
- ```
117
-
118
- AST representation:
119
-
120
- ```json
121
- {
122
- "Type": "array",
123
- "Name": "Geography",
124
- "Values": [
125
- {
126
- "HasCut": true,
127
- "Occurrence": { "n": 1, "m": 1 },
128
- "Name": "city",
129
- "Type": ["tstr"],
130
- "Comments": [
131
- {
132
- "Type": "comment",
133
- "Content": "a city",
134
- "Leading": false
135
- }
136
- ]
137
- },
138
- {
139
- "HasCut": true,
140
- "Occurrence": { "n": 1, "m": 1 },
141
- "Name": "gpsCoordinates",
142
- "Type": [{
143
- "Type": "group",
144
- "Value": "GpsCoordinates",
145
- "Unwrapped": false
146
- }],
147
- "Comments": [
148
- {
149
- "Type": "comment",
150
- "Content": "some coordinates",
151
- "Leading": false
152
- }
153
- ]
154
- }
155
- ],
156
- "Comments": []
157
- }
158
- ```
159
-
160
- ### Comments on Variable Definitions
161
-
162
- ```cddl
163
- ; unit: m/s
164
- speed = number .ge 0
165
- ```
166
-
167
- AST representation:
168
-
169
- ```json
170
- {
171
- "Type": "variable",
172
- "Name": "speed",
173
- "IsChoiceAddition": false,
174
- "PropertyType": [
175
- {
176
- "Type": {
177
- "Type": "group",
178
- "Value": "number",
179
- "Unwrapped": false
180
- },
181
- "Operator": {
182
- "Type": "ge",
183
- "Value": {
184
- "Type": "literal",
185
- "Value": 0,
186
- "Unwrapped": false
187
- }
188
- }
189
- }
190
- ],
191
- "Comments": [
192
- {
193
- "Type": "comment",
194
- "Content": "unit: m/s",
195
- "Leading": false
196
- }
197
- ]
198
- }
199
- ```
200
-
201
- ### Comments on Properties in Groups
202
-
203
- ```cddl
204
- GpsCoordinates = {
205
- ; degrees, scaled by 10^7
206
- longitude: uint,
207
- ; degreed, scaled by 10^7
208
- latitude: uint
209
- }
210
- ```
211
-
212
- AST representation:
213
-
214
- ```json
215
- {
216
- "Type": "group",
217
- "Name": "GpsCoordinates",
218
- "IsChoiceAddition": false,
219
- "Properties": [
220
- {
221
- "HasCut": true,
222
- "Occurrence": { "n": 1, "m": 1 },
223
- "Name": "longitude",
224
- "Type": ["uint"],
225
- "Comments": [
226
- {
227
- "Type": "comment",
228
- "Content": "degrees, scaled by 10^7",
229
- "Leading": false
230
- }
231
- ]
232
- },
233
- {
234
- "HasCut": true,
235
- "Occurrence": { "n": 1, "m": 1 },
236
- "Name": "latitude",
237
- "Type": ["uint"],
238
- "Comments": [
239
- {
240
- "Type": "comment",
241
- "Content": "degreed, scaled by 10^7",
242
- "Leading": false
243
- }
244
- ]
245
- }
246
- ],
247
- "Comments": []
248
- }
249
- ```
250
-
251
- ### Multiple Comments on an Element
252
-
253
- Comments can be stacked together in the CDDL file:
254
-
255
- ```cddl
256
- ; some comment
257
- ; another comment
258
- foo = {
259
- bar
260
- }
261
- ```
262
-
263
- AST representation:
264
-
265
- ```json
266
- {
267
- "Type": "group",
268
- "Name": "foo",
269
- "IsChoiceAddition": false,
270
- "Properties": [
271
- {
272
- "HasCut": false,
273
- "Occurrence": { "n": 1, "m": 1 },
274
- "Name": "",
275
- "Type": [{
276
- "Type": "group",
277
- "Value": "bar",
278
- "Unwrapped": false
279
- }],
280
- "Comments": []
281
- }
282
- ],
283
- "Comments": [
284
- {
285
- "Type": "comment",
286
- "Content": "some comment",
287
- "Leading": false
288
- },
289
- {
290
- "Type": "comment",
291
- "Content": "another comment",
292
- "Leading": false
293
- }
294
- ]
295
- }
296
- ```
297
-
298
- ## Working with Comments
299
-
300
- When processing the AST, you can use the comments to:
301
-
302
- 1. Generate documentation from the CDDL file
303
- 2. Add explanatory comments to generated code
304
- 3. Provide additional context or constraints not directly expressible in CDDL
305
- 4. Preserve the original author's intentions and notes
306
-
307
- Comments provide valuable metadata about the CDDL definitions and should be preserved when transforming the AST to other formats.
package/docs/groups.md DELETED
@@ -1,351 +0,0 @@
1
- # Groups
2
-
3
- Groups are a fundamental building block of CDDL definitions. They define a collection of properties and are used to represent structured data. This document explains how groups are represented in the AST.
4
-
5
- ## Group Definition
6
-
7
- In the AST, a group is represented by the following structure:
8
-
9
- ```typescript
10
- export type Group = {
11
- Type: 'group'
12
- Name: string
13
- IsChoiceAddition: boolean
14
- Properties: (Property|Property[])[]
15
- Comments: Comment[]
16
- }
17
- ```
18
-
19
- Where:
20
- - `Type`: Always set to 'group' to identify this node as a group
21
- - `Name`: The name of the group
22
- - `IsChoiceAddition`: A boolean indicating if this group is a choice addition (using the `/=` operator)
23
- - `Properties`: An array of property definitions or property choice arrays
24
- - `Comments`: An array of comments associated with the group
25
-
26
- ## Group Properties
27
-
28
- The properties of a group define its structure. Each property can be one of:
29
-
30
- 1. A single property definition:
31
- ```typescript
32
- Property
33
- ```
34
-
35
- 2. An array of property definitions for choices:
36
- ```typescript
37
- Property[]
38
- ```
39
-
40
- This allows for representing properties with alternatives.
41
-
42
- ## Anonymous and Named Groups
43
-
44
- Groups can be either named (top-level) or anonymous (inline). Named groups appear as top-level assignments in the AST, while anonymous groups can appear as property types within other groups or arrays.
45
-
46
- ### Named Group Example
47
-
48
- ```cddl
49
- person = {
50
- name: tstr,
51
- age: uint
52
- }
53
- ```
54
-
55
- AST representation:
56
-
57
- ```json
58
- {
59
- "Type": "group",
60
- "Name": "person",
61
- "IsChoiceAddition": false,
62
- "Properties": [
63
- {
64
- "HasCut": true,
65
- "Occurrence": { "n": 1, "m": 1 },
66
- "Name": "name",
67
- "Type": ["tstr"],
68
- "Comments": []
69
- },
70
- {
71
- "HasCut": true,
72
- "Occurrence": { "n": 1, "m": 1 },
73
- "Name": "age",
74
- "Type": ["uint"],
75
- "Comments": []
76
- }
77
- ],
78
- "Comments": []
79
- }
80
- ```
81
-
82
- ### Anonymous Group Example
83
-
84
- ```cddl
85
- person = {
86
- name: tstr,
87
- address: {
88
- street: tstr,
89
- city: tstr
90
- }
91
- }
92
- ```
93
-
94
- AST representation:
95
-
96
- ```json
97
- {
98
- "Type": "group",
99
- "Name": "person",
100
- "IsChoiceAddition": false,
101
- "Properties": [
102
- {
103
- "HasCut": true,
104
- "Occurrence": { "n": 1, "m": 1 },
105
- "Name": "name",
106
- "Type": ["tstr"],
107
- "Comments": []
108
- },
109
- {
110
- "HasCut": true,
111
- "Occurrence": { "n": 1, "m": 1 },
112
- "Name": "address",
113
- "Type": [{
114
- "Type": "group",
115
- "Name": "",
116
- "IsChoiceAddition": false,
117
- "Properties": [
118
- {
119
- "HasCut": true,
120
- "Occurrence": { "n": 1, "m": 1 },
121
- "Name": "street",
122
- "Type": ["tstr"],
123
- "Comments": []
124
- },
125
- {
126
- "HasCut": true,
127
- "Occurrence": { "n": 1, "m": 1 },
128
- "Name": "city",
129
- "Type": ["tstr"],
130
- "Comments": []
131
- }
132
- ],
133
- "Comments": []
134
- }],
135
- "Comments": []
136
- }
137
- ],
138
- "Comments": []
139
- }
140
- ```
141
-
142
- ## Group Composition
143
-
144
- CDDL allows groups to be composed by including another group. This is represented in the AST using a property with an empty name that references the included group.
145
-
146
- ```cddl
147
- address = {
148
- street: tstr,
149
- city: tstr
150
- }
151
-
152
- fullAddress = {
153
- address,
154
- country: tstr
155
- }
156
- ```
157
-
158
- AST representation:
159
-
160
- ```json
161
- [
162
- {
163
- "Type": "group",
164
- "Name": "address",
165
- "IsChoiceAddition": false,
166
- "Properties": [
167
- {
168
- "HasCut": true,
169
- "Occurrence": { "n": 1, "m": 1 },
170
- "Name": "street",
171
- "Type": ["tstr"],
172
- "Comments": []
173
- },
174
- {
175
- "HasCut": true,
176
- "Occurrence": { "n": 1, "m": 1 },
177
- "Name": "city",
178
- "Type": ["tstr"],
179
- "Comments": []
180
- }
181
- ],
182
- "Comments": []
183
- },
184
- {
185
- "Type": "group",
186
- "Name": "fullAddress",
187
- "IsChoiceAddition": false,
188
- "Properties": [
189
- {
190
- "HasCut": false,
191
- "Occurrence": { "n": 1, "m": 1 },
192
- "Name": "",
193
- "Type": [{
194
- "Type": "group",
195
- "Value": "address",
196
- "Unwrapped": false
197
- }],
198
- "Comments": []
199
- },
200
- {
201
- "HasCut": true,
202
- "Occurrence": { "n": 1, "m": 1 },
203
- "Name": "country",
204
- "Type": ["tstr"],
205
- "Comments": []
206
- }
207
- ],
208
- "Comments": []
209
- }
210
- ]
211
- ```
212
-
213
- ## Group Choice Additions
214
-
215
- CDDL allows extending choices using the `/=` operator. This is represented in the AST with the `IsChoiceAddition` flag set to `true`.
216
-
217
- ```cddl
218
- delivery = {
219
- street: tstr,
220
- number: uint,
221
- city: city
222
- }
223
-
224
- delivery /= {
225
- lat: float,
226
- long: float,
227
- drone-type: tstr
228
- }
229
- ```
230
-
231
- AST representation:
232
-
233
- ```json
234
- [
235
- {
236
- "Type": "group",
237
- "Name": "delivery",
238
- "IsChoiceAddition": false,
239
- "Properties": [
240
- {
241
- "HasCut": true,
242
- "Name": "street",
243
- "Occurrence": { "n": 1, "m": 1 },
244
- "Type": ["tstr"],
245
- "Comments": []
246
- },
247
- {
248
- "HasCut": true,
249
- "Name": "number",
250
- "Occurrence": { "n": 1, "m": 1 },
251
- "Type": ["uint"],
252
- "Comments": []
253
- },
254
- {
255
- "HasCut": true,
256
- "Name": "city",
257
- "Occurrence": { "n": 1, "m": 1 },
258
- "Type": [{
259
- "Type": "group",
260
- "Value": "city",
261
- "Unwrapped": false
262
- }],
263
- "Comments": []
264
- }
265
- ],
266
- "Comments": []
267
- },
268
- {
269
- "Type": "group",
270
- "Name": "delivery",
271
- "IsChoiceAddition": true,
272
- "Properties": [
273
- {
274
- "HasCut": true,
275
- "Name": "lat",
276
- "Occurrence": { "n": 1, "m": 1 },
277
- "Type": ["float"],
278
- "Comments": []
279
- },
280
- {
281
- "HasCut": true,
282
- "Name": "long",
283
- "Occurrence": { "n": 1, "m": 1 },
284
- "Type": ["float"],
285
- "Comments": []
286
- },
287
- {
288
- "HasCut": true,
289
- "Name": "drone-type",
290
- "Occurrence": { "n": 1, "m": 1 },
291
- "Type": ["tstr"],
292
- "Comments": []
293
- }
294
- ],
295
- "Comments": []
296
- }
297
- ]
298
- ```
299
-
300
- ## Property Choices
301
-
302
- CDDL allows for choice between properties in a group, represented by the `/` operator. In the AST, this is represented as an array of properties within the `Properties` array.
303
-
304
- ```cddl
305
- delivery = {
306
- street: tstr,
307
- (city: city // po-box: uint)
308
- }
309
- ```
310
-
311
- AST representation:
312
-
313
- ```json
314
- {
315
- "Type": "group",
316
- "Name": "delivery",
317
- "IsChoiceAddition": false,
318
- "Properties": [
319
- {
320
- "HasCut": true,
321
- "Name": "street",
322
- "Occurrence": { "n": 1, "m": 1 },
323
- "Type": ["tstr"],
324
- "Comments": []
325
- },
326
- [
327
- {
328
- "HasCut": false,
329
- "Name": "",
330
- "Occurrence": { "n": 1, "m": 1 },
331
- "Type": {
332
- "Type": "group",
333
- "Value": "city",
334
- "Unwrapped": false
335
- },
336
- "Comments": []
337
- },
338
- {
339
- "HasCut": true,
340
- "Name": "po-box",
341
- "Occurrence": { "n": 1, "m": 1 },
342
- "Type": ["uint"],
343
- "Comments": []
344
- }
345
- ]
346
- ],
347
- "Comments": []
348
- }
349
- ```
350
-
351
- By understanding these different group representations in the AST, you can properly interpret and process CDDL group definitions for further transformation or analysis.