cddl 0.16.0 → 0.17.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
@@ -1,340 +0,0 @@
1
- # Property References
2
-
3
- Property references in CDDL allow referring to previously defined types, groups, literals, and other constructs. This document explains how property references are represented in the AST.
4
-
5
- ## Property Reference Definition
6
-
7
- In the AST, a property reference is represented by the following structure:
8
-
9
- ```typescript
10
- export type PropertyReferenceType = 'literal' | 'group' | 'group_array' | 'array' | 'range' | 'tag'
11
-
12
- export type PropertyReference = {
13
- Type: PropertyReferenceType
14
- Value: string | number | boolean | Group | Array | Range | Tag
15
- Unwrapped: boolean
16
- Operator?: Operator
17
- }
18
- ```
19
-
20
- Where:
21
- - `Type`: The type of reference
22
- - `Value`: The value being referenced (can be various types)
23
- - `Unwrapped`: A boolean indicating if this reference should be unwrapped (applicable for arrays and groups)
24
- - `Operator`: An optional operator that modifies the referenced value
25
-
26
- ## Reference Types
27
-
28
- The AST supports several types of references:
29
-
30
- 1. `literal`: References a literal value (string, number, boolean)
31
- 2. `group`: References a named group
32
- 3. `group_array`: References a group that should be treated as an array
33
- 4. `array`: References a named array
34
- 5. `range`: References a range definition
35
- 6. `tag`: References a tag definition
36
-
37
- ## Examples of Property References
38
-
39
- ### Reference to a Named Group
40
-
41
- ```cddl
42
- person = {
43
- address: address
44
- }
45
-
46
- address = {
47
- street: tstr,
48
- city: tstr
49
- }
50
- ```
51
-
52
- AST representation of the reference:
53
-
54
- ```json
55
- {
56
- "Type": "group",
57
- "Value": "address",
58
- "Unwrapped": false
59
- }
60
- ```
61
-
62
- ### Reference to a Literal Value
63
-
64
- ```cddl
65
- status = "active" / "inactive" / "suspended"
66
- ```
67
-
68
- AST representation:
69
-
70
- ```json
71
- {
72
- "Type": "variable",
73
- "Name": "status",
74
- "IsChoiceAddition": false,
75
- "PropertyType": [
76
- {
77
- "Type": "literal",
78
- "Value": "active",
79
- "Unwrapped": false
80
- },
81
- {
82
- "Type": "literal",
83
- "Value": "inactive",
84
- "Unwrapped": false
85
- },
86
- {
87
- "Type": "literal",
88
- "Value": "suspended",
89
- "Unwrapped": false
90
- }
91
- ],
92
- "Comments": []
93
- }
94
- ```
95
-
96
- ### Reference with Unwrapping
97
-
98
- ```cddl
99
- basic-header = [
100
- field1: int,
101
- field2: text
102
- ]
103
-
104
- advanced-header = [
105
- ~basic-header,
106
- field3: bytes
107
- ]
108
- ```
109
-
110
- AST representation of the unwrapped reference:
111
-
112
- ```json
113
- {
114
- "Type": "group",
115
- "Value": "basic-header",
116
- "Unwrapped": true
117
- }
118
- ```
119
-
120
- ### Reference to a Range
121
-
122
- ```cddl
123
- port = 0..65535
124
- ```
125
-
126
- AST representation:
127
-
128
- ```json
129
- {
130
- "Type": "range",
131
- "Value": {
132
- "Min": 0,
133
- "Max": 65535,
134
- "Inclusive": true
135
- },
136
- "Unwrapped": false
137
- }
138
- ```
139
-
140
- ### Reference to a Tag
141
-
142
- ```cddl
143
- my_uri = #6.32(tstr) / tstr
144
- ```
145
-
146
- AST representation:
147
-
148
- ```json
149
- {
150
- "Type": "tag",
151
- "Value": {
152
- "NumericPart": 6.32,
153
- "TypePart": "tstr"
154
- },
155
- "Unwrapped": false
156
- }
157
- ```
158
-
159
- ## Reference with Operator
160
-
161
- ```cddl
162
- ip4 = bstr .size 4
163
- foo = ip4 .and nai
164
- ```
165
-
166
- AST representation:
167
-
168
- ```json
169
- {
170
- "Type": {
171
- "Type": "group",
172
- "Value": "ip4",
173
- "Unwrapped": false
174
- },
175
- "Operator": {
176
- "Type": "and",
177
- "Value": {
178
- "Type": "group",
179
- "Value": "nai",
180
- "Unwrapped": false
181
- }
182
- }
183
- }
184
- ```
185
-
186
- ## References in Group Composition
187
-
188
- References can be used for group composition, where one group incorporates all the properties of another:
189
-
190
- ```cddl
191
- person = {
192
- name: tstr,
193
- age: uint
194
- }
195
-
196
- employee = {
197
- person,
198
- employeeId: uint,
199
- department: tstr
200
- }
201
- ```
202
-
203
- AST representation of the composition:
204
-
205
- ```json
206
- {
207
- "Type": "group",
208
- "Name": "employee",
209
- "IsChoiceAddition": false,
210
- "Properties": [
211
- {
212
- "HasCut": false,
213
- "Occurrence": { "n": 1, "m": 1 },
214
- "Name": "",
215
- "Type": [
216
- {
217
- "Type": "group",
218
- "Value": "person",
219
- "Unwrapped": false
220
- }
221
- ],
222
- "Comments": []
223
- },
224
- {
225
- "HasCut": true,
226
- "Occurrence": { "n": 1, "m": 1 },
227
- "Name": "employeeId",
228
- "Type": ["uint"],
229
- "Comments": []
230
- },
231
- {
232
- "HasCut": true,
233
- "Occurrence": { "n": 1, "m": 1 },
234
- "Name": "department",
235
- "Type": ["tstr"],
236
- "Comments": []
237
- }
238
- ],
239
- "Comments": []
240
- }
241
- ```
242
-
243
- ## References in Array Elements
244
-
245
- References can be used to define array elements:
246
-
247
- ```cddl
248
- people = [* person]
249
- ```
250
-
251
- AST representation:
252
-
253
- ```json
254
- {
255
- "Type": "array",
256
- "Name": "people",
257
- "Values": [
258
- {
259
- "HasCut": false,
260
- "Occurrence": { "n": 0, "m": Infinity },
261
- "Name": "",
262
- "Type": [
263
- {
264
- "Type": "group",
265
- "Value": "person",
266
- "Unwrapped": false
267
- }
268
- ],
269
- "Comments": []
270
- }
271
- ],
272
- "Comments": []
273
- }
274
- ```
275
-
276
- ## Nested References
277
-
278
- References can refer to complex nested structures:
279
-
280
- ```cddl
281
- location = {
282
- city: tstr,
283
- country: {
284
- name: tstr,
285
- code: tstr
286
- }
287
- }
288
- ```
289
-
290
- AST representation:
291
-
292
- ```json
293
- {
294
- "Type": "group",
295
- "Name": "location",
296
- "IsChoiceAddition": false,
297
- "Properties": [
298
- {
299
- "HasCut": true,
300
- "Occurrence": { "n": 1, "m": 1 },
301
- "Name": "city",
302
- "Type": ["tstr"],
303
- "Comments": []
304
- },
305
- {
306
- "HasCut": true,
307
- "Occurrence": { "n": 1, "m": 1 },
308
- "Name": "country",
309
- "Type": [
310
- {
311
- "Type": "group",
312
- "Name": "",
313
- "IsChoiceAddition": false,
314
- "Properties": [
315
- {
316
- "HasCut": true,
317
- "Occurrence": { "n": 1, "m": 1 },
318
- "Name": "name",
319
- "Type": ["tstr"],
320
- "Comments": []
321
- },
322
- {
323
- "HasCut": true,
324
- "Occurrence": { "n": 1, "m": 1 },
325
- "Name": "code",
326
- "Type": ["tstr"],
327
- "Comments": []
328
- }
329
- ],
330
- "Comments": []
331
- }
332
- ],
333
- "Comments": []
334
- }
335
- ],
336
- "Comments": []
337
- }
338
- ```
339
-
340
- By understanding these property reference representations in the AST, you can properly interpret and process CDDL references for further transformation or analysis.
package/docs/variables.md DELETED
@@ -1,335 +0,0 @@
1
- # Variables
2
-
3
- Variables in CDDL are assignments that associate a name with a type or a choice of types. This document explains how variables are represented in the AST.
4
-
5
- ## Variable Definition
6
-
7
- In the AST, a variable is represented by the following structure:
8
-
9
- ```typescript
10
- export type Variable = {
11
- Type: 'variable'
12
- Name: string
13
- IsChoiceAddition: boolean
14
- PropertyType: PropertyType | PropertyType[]
15
- Operator?: Operator
16
- Comments: Comment[]
17
- }
18
- ```
19
-
20
- Where:
21
- - `Type`: Always set to 'variable' to identify this node as a variable
22
- - `Name`: The name of the variable
23
- - `IsChoiceAddition`: A boolean indicating if this variable is a choice addition (using the `/=` operator)
24
- - `PropertyType`: The type or array of types assigned to the variable
25
- - `Operator`: An optional operator that modifies the variable's type
26
- - `Comments`: An array of comments associated with the variable
27
-
28
- ## Basic Variable Assignments
29
-
30
- The simplest form of variable assignment associates a name with a single type:
31
-
32
- ```cddl
33
- device-address = byte
34
- ```
35
-
36
- AST representation:
37
-
38
- ```json
39
- {
40
- "Type": "variable",
41
- "Name": "device-address",
42
- "IsChoiceAddition": false,
43
- "PropertyType": [
44
- {
45
- "Type": "group",
46
- "Value": "byte",
47
- "Unwrapped": false
48
- }
49
- ],
50
- "Comments": []
51
- }
52
- ```
53
-
54
- ## Variable with Multiple Type Choices
55
-
56
- Variables can be assigned multiple type options using the choice operator (`/`):
57
-
58
- ```cddl
59
- attire = "bow tie" / "necktie" / "Internet attire"
60
- ```
61
-
62
- AST representation:
63
-
64
- ```json
65
- {
66
- "Type": "variable",
67
- "Name": "attire",
68
- "IsChoiceAddition": false,
69
- "PropertyType": [
70
- {
71
- "Type": "literal",
72
- "Value": "bow tie",
73
- "Unwrapped": false
74
- },
75
- {
76
- "Type": "literal",
77
- "Value": "necktie",
78
- "Unwrapped": false
79
- },
80
- {
81
- "Type": "literal",
82
- "Value": "Internet attire",
83
- "Unwrapped": false
84
- }
85
- ],
86
- "Comments": []
87
- }
88
- ```
89
-
90
- ## Variable with Numeric Literals
91
-
92
- Variables can be assigned numeric literals:
93
-
94
- ```cddl
95
- protocol = 6 / 17
96
- js-int = -9007199254740991..9007199254740991
97
- ```
98
-
99
- AST representation for "protocol":
100
-
101
- ```json
102
- {
103
- "Type": "variable",
104
- "Name": "protocol",
105
- "IsChoiceAddition": false,
106
- "PropertyType": [
107
- {
108
- "Type": "literal",
109
- "Value": 6,
110
- "Unwrapped": false
111
- },
112
- {
113
- "Type": "literal",
114
- "Value": 17,
115
- "Unwrapped": false
116
- }
117
- ],
118
- "Comments": []
119
- }
120
- ```
121
-
122
- AST representation for "js-int" (using range):
123
-
124
- ```json
125
- {
126
- "Type": "variable",
127
- "Name": "js-int",
128
- "IsChoiceAddition": false,
129
- "PropertyType": [
130
- {
131
- "Type": "range",
132
- "Value": {
133
- "Min": -9007199254740991,
134
- "Max": 9007199254740991,
135
- "Inclusive": true
136
- },
137
- "Unwrapped": false
138
- }
139
- ],
140
- "Comments": []
141
- }
142
- ```
143
-
144
- ## Variable with Operators
145
-
146
- Variables can be modified with operators that constrain or transform their values:
147
-
148
- ```cddl
149
- ip4 = bstr .size 4
150
- nai = tstr .regexp "[A-Za-z0-9]+@[A-Za-z0-9]+(\.[A-Za-z0-9]+)+"
151
- speed = number .ge 0
152
- displayed-step = number .default 1
153
- ```
154
-
155
- AST representation for "ip4":
156
-
157
- ```json
158
- {
159
- "Type": "variable",
160
- "Name": "ip4",
161
- "IsChoiceAddition": false,
162
- "PropertyType": [
163
- {
164
- "Type": "bstr",
165
- "Operator": {
166
- "Type": "size",
167
- "Value": {
168
- "Type": "literal",
169
- "Value": 4,
170
- "Unwrapped": false
171
- }
172
- }
173
- }
174
- ],
175
- "Comments": []
176
- }
177
- ```
178
-
179
- AST representation for "speed":
180
-
181
- ```json
182
- {
183
- "Type": "variable",
184
- "Name": "speed",
185
- "IsChoiceAddition": false,
186
- "PropertyType": [
187
- {
188
- "Type": {
189
- "Type": "group",
190
- "Value": "number",
191
- "Unwrapped": false
192
- },
193
- "Operator": {
194
- "Type": "ge",
195
- "Value": {
196
- "Type": "literal",
197
- "Value": 0,
198
- "Unwrapped": false
199
- }
200
- }
201
- }
202
- ],
203
- "Comments": []
204
- }
205
- ```
206
-
207
- AST representation for "displayed-step":
208
-
209
- ```json
210
- {
211
- "Type": "variable",
212
- "Name": "displayed-step",
213
- "IsChoiceAddition": false,
214
- "PropertyType": [
215
- {
216
- "Type": {
217
- "Type": "group",
218
- "Value": "number",
219
- "Unwrapped": false
220
- },
221
- "Operator": {
222
- "Type": "default",
223
- "Value": {
224
- "Type": "literal",
225
- "Value": 1,
226
- "Unwrapped": false
227
- }
228
- }
229
- }
230
- ],
231
- "Comments": []
232
- }
233
- ```
234
-
235
- ## Variable Choice Additions
236
-
237
- CDDL allows extending variable choices using the `/=` operator. This is represented in the AST with the `IsChoiceAddition` flag set to `true`.
238
-
239
- ```cddl
240
- attire = "bow tie" / "necktie" / "Internet attire"
241
- attire /= "swimwear"
242
- ```
243
-
244
- AST representation for the addition:
245
-
246
- ```json
247
- {
248
- "Type": "variable",
249
- "Name": "attire",
250
- "IsChoiceAddition": true,
251
- "PropertyType": [
252
- {
253
- "Type": "literal",
254
- "Value": "swimwear",
255
- "Unwrapped": false
256
- }
257
- ],
258
- "Comments": []
259
- }
260
- ```
261
-
262
- ## Variables with Comments
263
-
264
- Comments can be associated with variable definitions:
265
-
266
- ```cddl
267
- ; unit: m/s
268
- speed = number .ge 0
269
- ```
270
-
271
- AST representation:
272
-
273
- ```json
274
- {
275
- "Type": "variable",
276
- "Name": "speed",
277
- "IsChoiceAddition": false,
278
- "PropertyType": [
279
- {
280
- "Type": {
281
- "Type": "group",
282
- "Value": "number",
283
- "Unwrapped": false
284
- },
285
- "Operator": {
286
- "Type": "ge",
287
- "Value": {
288
- "Type": "literal",
289
- "Value": 0,
290
- "Unwrapped": false
291
- }
292
- }
293
- }
294
- ],
295
- "Comments": [
296
- {
297
- "Type": "comment",
298
- "Content": "unit: m/s",
299
- "Leading": false
300
- }
301
- ]
302
- }
303
- ```
304
-
305
- ## Variables with CBOR Tags
306
-
307
- CDDL allows specifying CBOR tags for variables. In the AST, this is represented using the `tag` type:
308
-
309
- ```cddl
310
- my_uri = #6.32(tstr) / tstr
311
- ```
312
-
313
- AST representation:
314
-
315
- ```json
316
- {
317
- "Type": "variable",
318
- "Name": "my_uri",
319
- "IsChoiceAddition": false,
320
- "PropertyType": [
321
- {
322
- "Type": "tag",
323
- "Value": {
324
- "NumericPart": 6.32,
325
- "TypePart": "tstr"
326
- },
327
- "Unwrapped": false
328
- },
329
- "tstr"
330
- ],
331
- "Comments": []
332
- }
333
- ```
334
-
335
- By understanding these different variable representations in the AST, you can properly interpret and process CDDL variable definitions for further transformation or analysis.