cddl 0.15.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 (46) hide show
  1. package/LICENSE +1 -1
  2. package/build/parser.d.ts.map +1 -1
  3. package/build/parser.js +26 -2
  4. package/package.json +5 -1
  5. package/.release-it.ts +0 -10
  6. package/docs/README.md +0 -47
  7. package/docs/arrays.md +0 -356
  8. package/docs/ast-structure.md +0 -166
  9. package/docs/basic-types.md +0 -243
  10. package/docs/cddl-cheatsheet.md +0 -231
  11. package/docs/comments.md +0 -307
  12. package/docs/groups.md +0 -351
  13. package/docs/operators.md +0 -466
  14. package/docs/properties.md +0 -334
  15. package/docs/ranges.md +0 -339
  16. package/docs/references.md +0 -340
  17. package/docs/variables.md +0 -335
  18. package/src/ast.ts +0 -180
  19. package/src/cli/commands/repl.ts +0 -33
  20. package/src/cli/commands/validate.ts +0 -44
  21. package/src/cli/constants.ts +0 -1
  22. package/src/cli/index.ts +0 -18
  23. package/src/constants.ts +0 -16
  24. package/src/index.ts +0 -12
  25. package/src/lexer.ts +0 -238
  26. package/src/parser.ts +0 -967
  27. package/src/tokens.ts +0 -50
  28. package/src/utils.ts +0 -96
  29. package/tests/__snapshots__/complex_types.test.ts.snap +0 -80
  30. package/tests/__snapshots__/examples.test.ts.snap +0 -1077
  31. package/tests/__snapshots__/group-choices.test.ts.snap +0 -278
  32. package/tests/__snapshots__/parser.test.ts.snap +0 -3045
  33. package/tests/__snapshots__/webdriver-local.test.ts.snap +0 -11192
  34. package/tests/__snapshots__/webdriver-remote.test.ts.snap +0 -16350
  35. package/tests/commands/repl.test.ts +0 -52
  36. package/tests/commands/validate.test.ts +0 -66
  37. package/tests/complex_types.test.ts +0 -18
  38. package/tests/examples.test.ts +0 -25
  39. package/tests/group-choices.test.ts +0 -103
  40. package/tests/lexer.test.ts +0 -63
  41. package/tests/module.test.ts +0 -21
  42. package/tests/parser.test.ts +0 -44
  43. package/tests/utils.test.ts +0 -211
  44. package/tests/webdriver-local.test.ts +0 -15
  45. package/tests/webdriver-remote.test.ts +0 -15
  46. package/tsconfig.json +0 -11
@@ -1,334 +0,0 @@
1
- # Properties
2
-
3
- Properties are a fundamental component of CDDL that define the members of groups and elements of arrays. This document explains how properties are represented in the AST.
4
-
5
- ## Property Definition
6
-
7
- In the AST, a property is represented by the following structure:
8
-
9
- ```typescript
10
- export type Property = {
11
- HasCut: boolean
12
- Occurrence: Occurrence
13
- Name: PropertyName
14
- Type: PropertyType | PropertyType[]
15
- Comments: Comment[]
16
- Operator?: Operator
17
- }
18
- ```
19
-
20
- Where:
21
- - `HasCut`: A boolean indicating if the property has a "cut" marker (/)
22
- - `Occurrence`: An object defining how many times the property can occur
23
- - `Name`: The name of the property (string)
24
- - `Type`: The type(s) of the property
25
- - `Comments`: An array of comments associated with the property
26
- - `Operator`: An optional operator modifying the property
27
-
28
- ## Property Names
29
-
30
- Property names are simple strings that identify the property within a group or array. A property can also have an empty name (`""`), which is used for:
31
-
32
- 1. Unnamed elements in arrays
33
- 2. Group composition (including one group within another)
34
-
35
- ## Occurrence Definition
36
-
37
- The occurrence of a property defines how many times it can appear. It is represented by:
38
-
39
- ```typescript
40
- export type Occurrence = {
41
- n: number // Minimum occurrence
42
- m: number // Maximum occurrence
43
- }
44
- ```
45
-
46
- Common occurrence patterns:
47
- - `{ n: 1, m: 1 }`: Exactly one time (default)
48
- - `{ n: 0, m: Infinity }`: Zero or more times (`*`)
49
- - `{ n: 1, m: Infinity }`: One or more times (`+`)
50
- - `{ n: 0, m: 1 }`: Zero or one time (`?`)
51
- - `{ n: a, m: b }`: At least `a` and at most `b` times (`a*b`)
52
-
53
- ## Cut Marker
54
-
55
- The `HasCut` field indicates whether the property has a cut marker (`/`) in CDDL. In CDDL syntax, a cut marker indicates that the property should be matched exactly once, even if the property appears later in an extended group.
56
-
57
- Example in CDDL:
58
- ```cddl
59
- person = {
60
- name: tstr,
61
- / age: uint,
62
- }
63
- ```
64
-
65
- AST representation:
66
- ```json
67
- {
68
- "HasCut": true,
69
- "Occurrence": { "n": 1, "m": 1 },
70
- "Name": "age",
71
- "Type": ["uint"],
72
- "Comments": []
73
- }
74
- ```
75
-
76
- ## Property Types
77
-
78
- The `Type` field can contain various types of values:
79
-
80
- 1. A string representing a primitive type:
81
- ```json
82
- "Type": ["tstr"]
83
- ```
84
-
85
- 2. A reference to a named type:
86
- ```json
87
- "Type": [
88
- {
89
- "Type": "group",
90
- "Value": "address",
91
- "Unwrapped": false
92
- }
93
- ]
94
- ```
95
-
96
- 3. An array of alternative types (choices):
97
- ```json
98
- "Type": ["tstr", "uint"]
99
- ```
100
-
101
- 4. A literal value:
102
- ```json
103
- "Type": [
104
- {
105
- "Type": "literal",
106
- "Value": "active",
107
- "Unwrapped": false
108
- }
109
- ]
110
- ```
111
-
112
- 5. A nested structure (group or array):
113
- ```json
114
- "Type": [
115
- {
116
- "Type": "group",
117
- "Name": "",
118
- "Properties": [...],
119
- "Comments": []
120
- }
121
- ]
122
- ```
123
-
124
- ## Property Examples
125
-
126
- ### Basic Property
127
-
128
- ```cddl
129
- person = {
130
- name: tstr,
131
- age: uint
132
- }
133
- ```
134
-
135
- AST representation of the "name" property:
136
-
137
- ```json
138
- {
139
- "HasCut": true,
140
- "Occurrence": { "n": 1, "m": 1 },
141
- "Name": "name",
142
- "Type": ["tstr"],
143
- "Comments": []
144
- }
145
- ```
146
-
147
- ### Optional Property
148
-
149
- ```cddl
150
- person = {
151
- name: tstr,
152
- ?email: tstr
153
- }
154
- ```
155
-
156
- AST representation of the "email" property:
157
-
158
- ```json
159
- {
160
- "HasCut": true,
161
- "Occurrence": { "n": 0, "m": Infinity },
162
- "Name": "email",
163
- "Type": ["tstr"],
164
- "Comments": []
165
- }
166
- ```
167
-
168
- ### Property with Occurrence Indicator
169
-
170
- ```cddl
171
- someGroup = {
172
- optional: tstr ?, ; zero or more
173
- anotherOptional: tstr *, ; zero or more
174
- atLeastOne: tstr +, ; one or more
175
- numberedOccurence: tstr 23*42, ; between 23 and 42
176
- withoutLeftSide: tstr *42, ; at most 42
177
- withoutRightSide: tstr 23* ; at least 23
178
- }
179
- ```
180
-
181
- AST representation of "numberedOccurence":
182
-
183
- ```json
184
- {
185
- "HasCut": true,
186
- "Occurrence": { "n": 23, "m": 42 },
187
- "Name": "numberedOccurence",
188
- "Type": ["tstr"],
189
- "Comments": []
190
- }
191
- ```
192
-
193
- ### Property with Comments
194
-
195
- ```cddl
196
- person = {
197
- ; a good employer
198
- employer: tstr
199
- }
200
- ```
201
-
202
- AST representation:
203
-
204
- ```json
205
- {
206
- "HasCut": true,
207
- "Occurrence": { "n": 1, "m": 1 },
208
- "Name": "employer",
209
- "Type": ["tstr"],
210
- "Comments": [
211
- {
212
- "Type": "comment",
213
- "Content": "a good employer",
214
- "Leading": false
215
- }
216
- ]
217
- }
218
- ```
219
-
220
- ### Property with Choice of Types
221
-
222
- ```cddl
223
- person = {
224
- id: uint / tstr
225
- }
226
- ```
227
-
228
- AST representation:
229
-
230
- ```json
231
- {
232
- "HasCut": true,
233
- "Occurrence": { "n": 1, "m": 1 },
234
- "Name": "id",
235
- "Type": ["uint", "tstr"],
236
- "Comments": []
237
- }
238
- ```
239
-
240
- ### Property with Default Value
241
-
242
- ```cddl
243
- someGroup = {
244
- optional: tstr .default "foobar" ?,
245
- orientation: ("portrait" / "landscape") .default "portrait" ?,
246
- scale: (0.1..2) .default 1 ?,
247
- shrinkToFit: bool .default true ?
248
- }
249
- ```
250
-
251
- AST representation of "optional":
252
-
253
- ```json
254
- {
255
- "HasCut": true,
256
- "Occurrence": { "n": 0, "m": Infinity },
257
- "Name": "optional",
258
- "Type": [
259
- {
260
- "Type": "tstr",
261
- "Operator": {
262
- "Type": "default",
263
- "Value": {
264
- "Type": "literal",
265
- "Value": "foobar",
266
- "Unwrapped": false
267
- }
268
- }
269
- }
270
- ],
271
- "Comments": []
272
- }
273
- ```
274
-
275
- AST representation of "orientation":
276
-
277
- ```json
278
- {
279
- "HasCut": true,
280
- "Occurrence": { "n": 0, "m": Infinity },
281
- "Name": "orientation",
282
- "Type": [
283
- {
284
- "Type": "literal",
285
- "Value": "portrait",
286
- "Unwrapped": false
287
- },
288
- {
289
- "Type": "literal",
290
- "Value": "landscape",
291
- "Unwrapped": false
292
- }
293
- ],
294
- "Operator": {
295
- "Type": "default",
296
- "Value": {
297
- "Type": "literal",
298
- "Value": "portrait",
299
- "Unwrapped": false
300
- }
301
- },
302
- "Comments": []
303
- }
304
- ```
305
-
306
- ## Group Member Properties vs. Array Element Properties
307
-
308
- Properties are used in both groups and arrays, but their interpretation differs slightly:
309
-
310
- 1. In groups, properties typically have names (except for group composition cases)
311
- 2. In arrays, elements can be named or unnamed and can have occurrence indicators
312
-
313
- Array element example:
314
-
315
- ```cddl
316
- Geography = [
317
- city: tstr,
318
- * float
319
- ]
320
- ```
321
-
322
- AST representation of the unnamed element:
323
-
324
- ```json
325
- {
326
- "HasCut": false,
327
- "Occurrence": { "n": 0, "m": Infinity },
328
- "Name": "",
329
- "Type": ["float"],
330
- "Comments": []
331
- }
332
- ```
333
-
334
- By understanding these different property representations in the AST, you can properly interpret and process CDDL property definitions for further transformation or analysis.
package/docs/ranges.md DELETED
@@ -1,339 +0,0 @@
1
- # Ranges
2
-
3
- Ranges in CDDL define a continuous set of values between a minimum and maximum value. This document explains how ranges are represented in the AST.
4
-
5
- ## Range Definition
6
-
7
- In the AST, a range is represented by the following structure:
8
-
9
- ```typescript
10
- export type Range = {
11
- Min: RangePropertyReference
12
- Max: RangePropertyReference
13
- Inclusive: boolean
14
- }
15
-
16
- export type RangePropertyReference = number | string
17
- ```
18
-
19
- Where:
20
- - `Min`: The minimum value of the range (can be a number or a reference to another value)
21
- - `Max`: The maximum value of the range (can be a number or a reference to another value)
22
- - `Inclusive`: A boolean indicating if the range boundaries are inclusive
23
-
24
- ## Range Property Reference
25
-
26
- The `Min` and `Max` values in a range can be:
27
-
28
- 1. Direct numeric values:
29
- ```json
30
- "Min": 0,
31
- "Max": 255
32
- ```
33
-
34
- 2. References to named values:
35
- ```json
36
- "Min": 0,
37
- "Max": "max-byte"
38
- ```
39
-
40
- ## Range Syntax in CDDL
41
-
42
- In CDDL, ranges are defined using the `..` operator for inclusive ranges or `...` for exclusive ranges:
43
-
44
- ```cddl
45
- byte = 0..255
46
- byte1 = 0...first-non-byte
47
- ```
48
-
49
- ## Range with Literal Values
50
-
51
- ```cddl
52
- byte = 0..255
53
- ```
54
-
55
- AST representation:
56
-
57
- ```json
58
- {
59
- "Type": "variable",
60
- "Name": "byte",
61
- "IsChoiceAddition": false,
62
- "PropertyType": [
63
- {
64
- "Type": "range",
65
- "Value": {
66
- "Min": 0,
67
- "Max": 255,
68
- "Inclusive": true
69
- },
70
- "Unwrapped": false
71
- }
72
- ],
73
- "Comments": []
74
- }
75
- ```
76
-
77
- ## Range with References to Named Values
78
-
79
- ```cddl
80
- max-byte = 255
81
- byte = 0..max-byte
82
- ```
83
-
84
- AST representation:
85
-
86
- ```json
87
- [
88
- {
89
- "Type": "variable",
90
- "Name": "max-byte",
91
- "IsChoiceAddition": false,
92
- "PropertyType": [
93
- {
94
- "Type": "literal",
95
- "Value": 255,
96
- "Unwrapped": false
97
- }
98
- ],
99
- "Comments": []
100
- },
101
- {
102
- "Type": "variable",
103
- "Name": "byte",
104
- "IsChoiceAddition": false,
105
- "PropertyType": [
106
- {
107
- "Type": "range",
108
- "Value": {
109
- "Min": 0,
110
- "Max": {
111
- "Type": "group",
112
- "Value": "max-byte",
113
- "Unwrapped": false
114
- },
115
- "Inclusive": true
116
- },
117
- "Unwrapped": false
118
- }
119
- ],
120
- "Comments": []
121
- }
122
- ]
123
- ```
124
-
125
- ## Exclusive Range
126
-
127
- ```cddl
128
- first-non-byte = 256
129
- byte1 = 0...first-non-byte
130
- ```
131
-
132
- AST representation:
133
-
134
- ```json
135
- [
136
- {
137
- "Type": "variable",
138
- "Name": "first-non-byte",
139
- "IsChoiceAddition": false,
140
- "PropertyType": [
141
- {
142
- "Type": "literal",
143
- "Value": 256,
144
- "Unwrapped": false
145
- }
146
- ],
147
- "Comments": []
148
- },
149
- {
150
- "Type": "variable",
151
- "Name": "byte1",
152
- "IsChoiceAddition": false,
153
- "PropertyType": [
154
- {
155
- "Type": "range",
156
- "Value": {
157
- "Min": 0,
158
- "Max": {
159
- "Type": "group",
160
- "Value": "first-non-byte",
161
- "Unwrapped": false
162
- },
163
- "Inclusive": false
164
- },
165
- "Unwrapped": false
166
- }
167
- ],
168
- "Comments": []
169
- }
170
- ]
171
- ```
172
-
173
- ## Range with Floating-Point Values
174
-
175
- ```cddl
176
- scale = (0.1..2) .default 1
177
- ```
178
-
179
- AST representation:
180
-
181
- ```json
182
- {
183
- "Type": "variable",
184
- "Name": "scale",
185
- "IsChoiceAddition": false,
186
- "PropertyType": [
187
- {
188
- "Type": {
189
- "Type": "range",
190
- "Value": {
191
- "Min": 0.1,
192
- "Max": 2,
193
- "Inclusive": true
194
- },
195
- "Unwrapped": false
196
- },
197
- "Operator": {
198
- "Type": "default",
199
- "Value": {
200
- "Type": "literal",
201
- "Value": 1,
202
- "Unwrapped": false
203
- }
204
- }
205
- }
206
- ],
207
- "Comments": []
208
- }
209
- ```
210
-
211
- ## Large Integer Ranges
212
-
213
- CDDL can represent large integer ranges:
214
-
215
- ```cddl
216
- js-int = -9007199254740991..9007199254740991
217
- ```
218
-
219
- AST representation:
220
-
221
- ```json
222
- {
223
- "Type": "variable",
224
- "Name": "js-int",
225
- "IsChoiceAddition": false,
226
- "PropertyType": [
227
- {
228
- "Type": "range",
229
- "Value": {
230
- "Min": -9007199254740991,
231
- "Max": 9007199254740991,
232
- "Inclusive": true
233
- },
234
- "Unwrapped": false
235
- }
236
- ],
237
- "Comments": []
238
- }
239
- ```
240
-
241
- ## Using Ranges in Groups and Arrays
242
-
243
- Ranges can be used as types within group properties or array elements:
244
-
245
- ```cddl
246
- port-range = {
247
- start: 0..65535,
248
- end: 0..65535
249
- }
250
- ```
251
-
252
- AST representation:
253
-
254
- ```json
255
- {
256
- "Type": "group",
257
- "Name": "port-range",
258
- "IsChoiceAddition": false,
259
- "Properties": [
260
- {
261
- "HasCut": true,
262
- "Occurrence": { "n": 1, "m": 1 },
263
- "Name": "start",
264
- "Type": [
265
- {
266
- "Type": "range",
267
- "Value": {
268
- "Min": 0,
269
- "Max": 65535,
270
- "Inclusive": true
271
- },
272
- "Unwrapped": false
273
- }
274
- ],
275
- "Comments": []
276
- },
277
- {
278
- "HasCut": true,
279
- "Occurrence": { "n": 1, "m": 1 },
280
- "Name": "end",
281
- "Type": [
282
- {
283
- "Type": "range",
284
- "Value": {
285
- "Min": 0,
286
- "Max": 65535,
287
- "Inclusive": true
288
- },
289
- "Unwrapped": false
290
- }
291
- ],
292
- "Comments": []
293
- }
294
- ],
295
- "Comments": []
296
- }
297
- ```
298
-
299
- ## Ranges with Operators
300
-
301
- Ranges can be used with operators like `.default`:
302
-
303
- ```cddl
304
- scale = (0.1..2) .default 1
305
- ```
306
-
307
- AST representation:
308
-
309
- ```json
310
- {
311
- "Type": "variable",
312
- "Name": "scale",
313
- "IsChoiceAddition": false,
314
- "PropertyType": [
315
- {
316
- "Type": {
317
- "Type": "range",
318
- "Value": {
319
- "Min": 0.1,
320
- "Max": 2,
321
- "Inclusive": true
322
- },
323
- "Unwrapped": false
324
- },
325
- "Operator": {
326
- "Type": "default",
327
- "Value": {
328
- "Type": "literal",
329
- "Value": 1,
330
- "Unwrapped": false
331
- }
332
- }
333
- }
334
- ],
335
- "Comments": []
336
- }
337
- ```
338
-
339
- By understanding these range representations in the AST, you can properly interpret and process CDDL range definitions for further transformation or analysis.