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/operators.md DELETED
@@ -1,466 +0,0 @@
1
- # Operators
2
-
3
- Operators in CDDL modify or constrain types, providing additional semantics beyond basic type definitions. This document explains how operators are represented in the AST.
4
-
5
- ## Operator Definition
6
-
7
- In the AST, an operator is represented by the following structure:
8
-
9
- ```typescript
10
- export type OperatorType = 'default' | 'size' | 'regexp' | 'bits' | 'and' | 'within' | 'eq' | 'ne' | 'lt' | 'le' | 'gt' | 'ge'
11
-
12
- export interface Operator {
13
- Type: OperatorType
14
- Value: PropertyType
15
- }
16
- ```
17
-
18
- Where:
19
- - `Type`: The type of operator
20
- - `Value`: The value or constraint applied by the operator
21
-
22
- ## Operator Types
23
-
24
- CDDL supports the following operators, represented in the AST:
25
-
26
- 1. `default`: Specifies a default value for a type
27
- 2. `size`: Constrains the size of a value (e.g., for strings or arrays)
28
- 3. `regexp`: Specifies a regular expression pattern for strings
29
- 4. `bits`: Specifies a bit mask for integers
30
- 5. `and`: Logical AND operation between types
31
- 6. `within`: Specifies that a value must be within another value
32
- 7. `eq`: Equality comparison
33
- 8. `ne`: Inequality comparison
34
- 9. `lt`: Less than comparison
35
- 10. `le`: Less than or equal comparison
36
- 11. `gt`: Greater than comparison
37
- 12. `ge`: Greater than or equal comparison
38
-
39
- ## Operator Location in the AST
40
-
41
- Operators can be attached to:
42
-
43
- 1. Variables:
44
- ```json
45
- {
46
- "Type": "variable",
47
- "Name": "ip4",
48
- "PropertyType": [{
49
- "Type": "bstr",
50
- "Operator": {
51
- "Type": "size",
52
- "Value": {
53
- "Type": "literal",
54
- "Value": 4,
55
- "Unwrapped": false
56
- }
57
- }
58
- }]
59
- }
60
- ```
61
-
62
- 2. Properties:
63
- ```json
64
- {
65
- "HasCut": true,
66
- "Name": "orientation",
67
- "Type": [
68
- {
69
- "Type": "literal",
70
- "Value": "portrait",
71
- "Unwrapped": false
72
- },
73
- {
74
- "Type": "literal",
75
- "Value": "landscape",
76
- "Unwrapped": false
77
- }
78
- ],
79
- "Operator": {
80
- "Type": "default",
81
- "Value": {
82
- "Type": "literal",
83
- "Value": "portrait",
84
- "Unwrapped": false
85
- }
86
- }
87
- }
88
- ```
89
-
90
- 3. Types within properties:
91
- ```json
92
- {
93
- "HasCut": true,
94
- "Name": "optional",
95
- "Type": [
96
- {
97
- "Type": "tstr",
98
- "Operator": {
99
- "Type": "default",
100
- "Value": {
101
- "Type": "literal",
102
- "Value": "foobar",
103
- "Unwrapped": false
104
- }
105
- }
106
- }
107
- ]
108
- }
109
- ```
110
-
111
- ## Examples of Operators
112
-
113
- ### Default Value Operator
114
-
115
- The `.default` operator specifies a default value for an optional field:
116
-
117
- ```cddl
118
- optional = tstr .default "foobar"
119
- ```
120
-
121
- AST representation:
122
-
123
- ```json
124
- {
125
- "Type": "variable",
126
- "Name": "optional",
127
- "IsChoiceAddition": false,
128
- "PropertyType": [
129
- {
130
- "Type": "tstr",
131
- "Operator": {
132
- "Type": "default",
133
- "Value": {
134
- "Type": "literal",
135
- "Value": "foobar",
136
- "Unwrapped": false
137
- }
138
- }
139
- }
140
- ],
141
- "Comments": []
142
- }
143
- ```
144
-
145
- ### Size Operator
146
-
147
- The `.size` operator constrains the size of a value:
148
-
149
- ```cddl
150
- ip4 = bstr .size 4
151
- ```
152
-
153
- AST representation:
154
-
155
- ```json
156
- {
157
- "Type": "variable",
158
- "Name": "ip4",
159
- "IsChoiceAddition": false,
160
- "PropertyType": [
161
- {
162
- "Type": "bstr",
163
- "Operator": {
164
- "Type": "size",
165
- "Value": {
166
- "Type": "literal",
167
- "Value": 4,
168
- "Unwrapped": false
169
- }
170
- }
171
- }
172
- ],
173
- "Comments": []
174
- }
175
- ```
176
-
177
- ### Size Operator with Range
178
-
179
- The `.size` operator can also use a range:
180
-
181
- ```cddl
182
- label = bstr .size (1..63)
183
- ```
184
-
185
- AST representation:
186
-
187
- ```json
188
- {
189
- "Type": "variable",
190
- "Name": "label",
191
- "IsChoiceAddition": false,
192
- "PropertyType": [
193
- {
194
- "Type": "bstr",
195
- "Operator": {
196
- "Type": "size",
197
- "Value": {
198
- "Type": "range",
199
- "Value": {
200
- "Min": 1,
201
- "Max": 63,
202
- "Inclusive": true
203
- },
204
- "Unwrapped": false
205
- }
206
- }
207
- }
208
- ],
209
- "Comments": []
210
- }
211
- ```
212
-
213
- ### Regular Expression Operator
214
-
215
- The `.regexp` operator specifies a pattern for text strings:
216
-
217
- ```cddl
218
- nai = tstr .regexp "[A-Za-z0-9]+@[A-Za-z0-9]+(\.[A-Za-z0-9]+)+"
219
- ```
220
-
221
- AST representation:
222
-
223
- ```json
224
- {
225
- "Type": "variable",
226
- "Name": "nai",
227
- "IsChoiceAddition": false,
228
- "PropertyType": [
229
- {
230
- "Type": "tstr",
231
- "Operator": {
232
- "Type": "regexp",
233
- "Value": {
234
- "Type": "literal",
235
- "Value": "[A-Za-z0-9]+@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)+",
236
- "Unwrapped": false
237
- }
238
- }
239
- }
240
- ],
241
- "Comments": []
242
- }
243
- ```
244
-
245
- ### Comparison Operators
246
-
247
- The `.ge`, `.gt`, `.le`, `.lt`, `.eq`, and `.ne` operators specify numerical constraints:
248
-
249
- ```cddl
250
- speed = number .ge 0
251
- ```
252
-
253
- AST representation:
254
-
255
- ```json
256
- {
257
- "Type": "variable",
258
- "Name": "speed",
259
- "IsChoiceAddition": false,
260
- "PropertyType": [
261
- {
262
- "Type": {
263
- "Type": "group",
264
- "Value": "number",
265
- "Unwrapped": false
266
- },
267
- "Operator": {
268
- "Type": "ge",
269
- "Value": {
270
- "Type": "literal",
271
- "Value": 0,
272
- "Unwrapped": false
273
- }
274
- }
275
- }
276
- ],
277
- "Comments": []
278
- }
279
- ```
280
-
281
- ### Logical Operators
282
-
283
- The `.and` and `.within` operators combine constraints:
284
-
285
- ```cddl
286
- foo = ip4 .and nai
287
- ```
288
-
289
- AST representation:
290
-
291
- ```json
292
- {
293
- "Type": "variable",
294
- "Name": "foo",
295
- "IsChoiceAddition": false,
296
- "PropertyType": [
297
- {
298
- "Type": {
299
- "Type": "group",
300
- "Value": "ip4",
301
- "Unwrapped": false
302
- },
303
- "Operator": {
304
- "Type": "and",
305
- "Value": {
306
- "Type": "group",
307
- "Value": "nai",
308
- "Unwrapped": false
309
- }
310
- }
311
- }
312
- ],
313
- "Comments": []
314
- }
315
- ```
316
-
317
- ### Operator on Properties in Groups
318
-
319
- Operators can be applied to properties in groups:
320
-
321
- ```cddl
322
- someGroup = {
323
- optional: tstr .default "foobar" ?,
324
- orientation: ("portrait" / "landscape") .default "portrait" ?,
325
- scale: (0.1..2) .default 1 ?,
326
- shrinkToFit: bool .default true ?
327
- }
328
- ```
329
-
330
- AST representation:
331
-
332
- ```json
333
- {
334
- "Type": "group",
335
- "Name": "someGroup",
336
- "IsChoiceAddition": false,
337
- "Properties": [
338
- {
339
- "HasCut": true,
340
- "Occurrence": { "n": 0, "m": Infinity },
341
- "Name": "optional",
342
- "Type": [
343
- {
344
- "Type": "tstr",
345
- "Operator": {
346
- "Type": "default",
347
- "Value": {
348
- "Type": "literal",
349
- "Value": "foobar",
350
- "Unwrapped": false
351
- }
352
- }
353
- }
354
- ],
355
- "Comments": []
356
- },
357
- {
358
- "HasCut": true,
359
- "Occurrence": { "n": 0, "m": Infinity },
360
- "Name": "orientation",
361
- "Type": [
362
- {
363
- "Type": "literal",
364
- "Value": "portrait",
365
- "Unwrapped": false
366
- },
367
- {
368
- "Type": "literal",
369
- "Value": "landscape",
370
- "Unwrapped": false
371
- }
372
- ],
373
- "Operator": {
374
- "Type": "default",
375
- "Value": {
376
- "Type": "literal",
377
- "Value": "portrait",
378
- "Unwrapped": false
379
- }
380
- },
381
- "Comments": []
382
- },
383
- {
384
- "HasCut": true,
385
- "Occurrence": { "n": 0, "m": Infinity },
386
- "Name": "scale",
387
- "Type": [
388
- {
389
- "Type": {
390
- "Type": "range",
391
- "Value": {
392
- "Min": 0.1,
393
- "Max": 2,
394
- "Inclusive": true
395
- },
396
- "Unwrapped": false
397
- },
398
- "Operator": {
399
- "Type": "default",
400
- "Value": {
401
- "Type": "literal",
402
- "Value": 1,
403
- "Unwrapped": false
404
- }
405
- }
406
- }
407
- ],
408
- "Comments": []
409
- },
410
- {
411
- "HasCut": true,
412
- "Occurrence": { "n": 0, "m": Infinity },
413
- "Name": "shrinkToFit",
414
- "Type": [
415
- {
416
- "Type": "bool",
417
- "Operator": {
418
- "Type": "default",
419
- "Value": {
420
- "Type": "literal",
421
- "Value": true,
422
- "Unwrapped": false
423
- }
424
- }
425
- }
426
- ],
427
- "Comments": []
428
- }
429
- ],
430
- "Comments": []
431
- }
432
- ```
433
-
434
- ## Operator Placement in the AST
435
-
436
- There are two common patterns for where operators appear in the AST:
437
-
438
- 1. **Type-level operators**: The operator is attached directly to the type. This is represented by the `Operator` field being part of the type:
439
- ```json
440
- {
441
- "Type": "tstr",
442
- "Operator": {
443
- "Type": "default",
444
- "Value": {
445
- "Type": "literal",
446
- "Value": "foobar",
447
- "Unwrapped": false
448
- }
449
- }
450
- }
451
- ```
452
-
453
- 2. **Property-level operators**: The operator applies to the entire property rather than just the type. This is represented by the `Operator` field being part of the property:
454
- ```json
455
- {
456
- "HasCut": true,
457
- "Name": "orientation",
458
- "Type": [...],
459
- "Operator": {
460
- "Type": "default",
461
- "Value": {...}
462
- }
463
- }
464
- ```
465
-
466
- By understanding these operator representations in the AST, you can properly interpret and process CDDL constraints for further transformation or analysis.