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
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Christian Bromann
3
+ Copyright (c) 2026 WebdriverIO Project
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cddl",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Concise data definition language (RFC 8610) implementation and JSON validator in Node.js",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "license": "MIT",
@@ -21,6 +21,10 @@
21
21
  "bin": {
22
22
  "cddl": "./bin/cddl.js"
23
23
  },
24
+ "files": [
25
+ "build",
26
+ "bin"
27
+ ],
24
28
  "devDependencies": {
25
29
  "@types/node": "^25.5.0",
26
30
  "@types/yargs": "^17.0.35"
package/.release-it.ts DELETED
@@ -1,10 +0,0 @@
1
- import baseConfig from '../../.release-it.base';
2
- import type { Config } from 'release-it';
3
-
4
- const config: Config = {
5
- ...baseConfig('cddl'),
6
- };
7
-
8
- console.log("Release-it config for cddl loaded", config);
9
-
10
- export default config;
package/docs/README.md DELETED
@@ -1,47 +0,0 @@
1
- # CDDL AST Parser Documentation
2
-
3
- This documentation describes the Abstract Syntax Tree (AST) generated by the CDDL (Concise Data Definition Language) parser in this project. The CDDL format is defined in the [RFC 8610 specification](https://datatracker.ietf.org/doc/rfc8610/).
4
-
5
- ## Overview
6
-
7
- The parser transforms CDDL files into an Abstract Syntax Tree (AST) representation that can be further processed to generate other formats like TypeScript type definitions. This documentation explains the structure of the AST and its components.
8
-
9
- ## Documentation Structure
10
-
11
- - [AST Structure](./ast-structure.md) - Overview of the AST structure
12
- - [Basic Types](./basic-types.md) - Core types in the AST
13
- - [Groups](./groups.md) - Group definitions
14
- - [Arrays](./arrays.md) - Array definitions
15
- - [Variables](./variables.md) - Variable assignments
16
- - [Properties](./properties.md) - Property definitions
17
- - [Comments](./comments.md) - Comment handling
18
- - [Ranges](./ranges.md) - Range representations
19
- - [Operators](./operators.md) - Available operators
20
- - [References](./references.md) - Property reference types
21
-
22
- ## Example Usage
23
-
24
- ```typescript
25
- import Parser from '../src/parser.js'
26
-
27
- // Create a new parser instance with the path to a CDDL file
28
- const parser = new Parser('./example.cddl')
29
-
30
- // Parse the file and get the AST
31
- const ast = parser.parse()
32
-
33
- // Now you can work with the AST to generate other formats
34
- console.log(JSON.stringify(ast, null, 2))
35
- ```
36
-
37
- ## AST Format
38
-
39
- The AST generated by the parser consists of a series of Assignment nodes, which can be one of:
40
-
41
- - Group definitions
42
- - Array definitions
43
- - Variable assignments
44
-
45
- Each of these contains properties and references that form a tree structure representing the CDDL document.
46
-
47
- See the individual documentation files for detailed information on each component of the AST.
package/docs/arrays.md DELETED
@@ -1,356 +0,0 @@
1
- # Arrays
2
-
3
- Arrays are a core component of CDDL that define ordered collections of elements. This document explains how arrays are represented in the AST.
4
-
5
- ## Array Definition
6
-
7
- In the AST, an array is represented by the following structure:
8
-
9
- ```typescript
10
- export type Array = {
11
- Type: 'array'
12
- Name: string
13
- Values: (Property|Property[])[]
14
- Comments: Comment[]
15
- }
16
- ```
17
-
18
- Where:
19
- - `Type`: Always set to 'array' to identify this node as an array
20
- - `Name`: The name of the array
21
- - `Values`: An array of properties or property choice arrays that define the elements of the array
22
- - `Comments`: An array of comments associated with the array
23
-
24
- ## Array Elements
25
-
26
- The elements of an array are defined by the `Values` field, which contains property definitions. Each property can represent:
27
-
28
- 1. A named element:
29
- ```cddl
30
- [field1: int, field2: text]
31
- ```
32
-
33
- 2. An unnamed element:
34
- ```cddl
35
- [int, text]
36
- ```
37
-
38
- 3. A repeated element with occurrence indicators:
39
- ```cddl
40
- [* int]
41
- ```
42
-
43
- 4. A choice between multiple elements:
44
- ```cddl
45
- [(int // text)]
46
- ```
47
-
48
- ## Named Array Example
49
-
50
- ```cddl
51
- basic-header = [
52
- field1: int,
53
- field2: text
54
- ]
55
- ```
56
-
57
- AST representation:
58
-
59
- ```json
60
- {
61
- "Type": "array",
62
- "Name": "basic-header",
63
- "Values": [
64
- {
65
- "HasCut": true,
66
- "Occurrence": { "n": 1, "m": 1 },
67
- "Name": "field1",
68
- "Type": ["int"],
69
- "Comments": []
70
- },
71
- {
72
- "HasCut": true,
73
- "Occurrence": { "n": 1, "m": 1 },
74
- "Name": "field2",
75
- "Type": ["text"],
76
- "Comments": []
77
- }
78
- ],
79
- "Comments": []
80
- }
81
- ```
82
-
83
- ## Array with Occurrence Indicators
84
-
85
- CDDL allows specifying how many times an element can occur using occurrence indicators. The AST represents this using the `Occurrence` field in the Property object.
86
-
87
- ```cddl
88
- unlimited-people = [* person]
89
- at-least-one-person = [+ person]
90
- zero-or-one-person = [? person]
91
- one-or-two-people = [1*2 person]
92
- zero-or-two-people = [0*2 person]
93
- two-or-infinity-people = [2* person]
94
- ```
95
-
96
- AST representation for "unlimited-people":
97
-
98
- ```json
99
- {
100
- "Type": "array",
101
- "Name": "unlimited-people",
102
- "Values": [
103
- {
104
- "HasCut": false,
105
- "Occurrence": { "n": 0, "m": Infinity },
106
- "Name": "",
107
- "Type": [
108
- {
109
- "Type": "group",
110
- "Value": "person",
111
- "Unwrapped": false
112
- }
113
- ],
114
- "Comments": []
115
- }
116
- ],
117
- "Comments": []
118
- }
119
- ```
120
-
121
- AST representation for "one-or-two-people":
122
-
123
- ```json
124
- {
125
- "Type": "array",
126
- "Name": "one-or-two-people",
127
- "Values": [
128
- {
129
- "HasCut": false,
130
- "Occurrence": { "n": 1, "m": 2 },
131
- "Name": "",
132
- "Type": [
133
- {
134
- "Type": "group",
135
- "Value": "person",
136
- "Unwrapped": false
137
- }
138
- ],
139
- "Comments": []
140
- }
141
- ],
142
- "Comments": []
143
- }
144
- ```
145
-
146
- ## Unwrapped Arrays
147
-
148
- CDDL allows for unwrapping arrays to include their elements directly in another array. This is represented in the AST with the `Unwrapped` flag set to `true` in the type reference.
149
-
150
- ```cddl
151
- basic-header = [
152
- field1: int,
153
- field2: text
154
- ]
155
-
156
- advanced-header = [
157
- ~basic-header,
158
- field3: bytes,
159
- field4: ~time
160
- ]
161
- ```
162
-
163
- AST representation for "advanced-header":
164
-
165
- ```json
166
- {
167
- "Type": "array",
168
- "Name": "advanced-header",
169
- "Values": [
170
- {
171
- "HasCut": false,
172
- "Occurrence": { "n": 1, "m": 1 },
173
- "Name": "",
174
- "Type": [
175
- {
176
- "Type": "group",
177
- "Value": "basic-header",
178
- "Unwrapped": true
179
- }
180
- ],
181
- "Comments": []
182
- },
183
- {
184
- "HasCut": true,
185
- "Occurrence": { "n": 1, "m": 1 },
186
- "Name": "field3",
187
- "Type": ["bytes"],
188
- "Comments": []
189
- },
190
- {
191
- "HasCut": true,
192
- "Occurrence": { "n": 1, "m": 1 },
193
- "Name": "field4",
194
- "Type": [
195
- {
196
- "Type": "group",
197
- "Value": "time",
198
- "Unwrapped": true
199
- }
200
- ],
201
- "Comments": []
202
- }
203
- ],
204
- "Comments": []
205
- }
206
- ```
207
-
208
- ## Nested Arrays
209
-
210
- Arrays can be nested to represent more complex structures:
211
-
212
- ```cddl
213
- script.MappingRemoteValue = [
214
- * [
215
- script.RemoteValue / text,
216
- script.RemoteValue
217
- ]
218
- ]
219
- ```
220
-
221
- AST representation:
222
-
223
- ```json
224
- {
225
- "Type": "array",
226
- "Name": "script.MappingRemoteValue",
227
- "Values": [
228
- {
229
- "HasCut": false,
230
- "Occurrence": { "n": 0, "m": Infinity },
231
- "Name": "",
232
- "Type": {
233
- "Type": "array",
234
- "Name": "",
235
- "Values": [
236
- {
237
- "HasCut": false,
238
- "Occurrence": { "n": 1, "m": 1 },
239
- "Name": "",
240
- "Type": [
241
- {
242
- "Type": "group",
243
- "Value": "script.RemoteValue",
244
- "Unwrapped": false
245
- },
246
- "text"
247
- ],
248
- "Comments": []
249
- },
250
- {
251
- "HasCut": false,
252
- "Occurrence": { "n": 1, "m": 1 },
253
- "Name": "",
254
- "Type": [
255
- {
256
- "Type": "group",
257
- "Value": "script.RemoteValue",
258
- "Unwrapped": false
259
- }
260
- ],
261
- "Comments": []
262
- }
263
- ],
264
- "Comments": []
265
- },
266
- "Comments": []
267
- }
268
- ],
269
- "Comments": []
270
- }
271
- ```
272
-
273
- ## Array Element Choices
274
-
275
- CDDL allows for choices between different types of elements in an array. In the AST, this is represented by an array of types in the `Type` field of a property.
276
-
277
- ```cddl
278
- points = [* (int / float)]
279
- ```
280
-
281
- AST representation:
282
-
283
- ```json
284
- {
285
- "Type": "array",
286
- "Name": "points",
287
- "Values": [
288
- {
289
- "HasCut": false,
290
- "Occurrence": { "n": 0, "m": Infinity },
291
- "Name": "",
292
- "Type": [
293
- "int",
294
- "float"
295
- ],
296
- "Comments": []
297
- }
298
- ],
299
- "Comments": []
300
- }
301
- ```
302
-
303
- ## Using Arrays as Types
304
-
305
- Arrays can also be used as types in property definitions:
306
-
307
- ```cddl
308
- located-samples = {
309
- sample-point: int,
310
- samples: [+ float]
311
- }
312
- ```
313
-
314
- AST representation:
315
-
316
- ```json
317
- {
318
- "Type": "group",
319
- "Name": "located-samples",
320
- "IsChoiceAddition": false,
321
- "Properties": [
322
- {
323
- "HasCut": false,
324
- "Occurrence": { "n": 1, "m": 1 },
325
- "Name": "sample-point",
326
- "Type": ["int"],
327
- "Comments": []
328
- },
329
- {
330
- "HasCut": false,
331
- "Occurrence": { "n": 1, "m": 1 },
332
- "Name": "samples",
333
- "Type": [
334
- {
335
- "Type": "array",
336
- "Name": "",
337
- "Values": [
338
- {
339
- "HasCut": false,
340
- "Occurrence": { "n": 1, "m": Infinity },
341
- "Name": "",
342
- "Type": "float",
343
- "Comments": []
344
- }
345
- ],
346
- "Comments": []
347
- }
348
- ],
349
- "Comments": []
350
- }
351
- ],
352
- "Comments": []
353
- }
354
- ```
355
-
356
- By understanding these different array representations in the AST, you can properly interpret and process CDDL array definitions for further transformation or analysis.
@@ -1,166 +0,0 @@
1
- # AST Structure
2
-
3
- The CDDL parser generates an Abstract Syntax Tree (AST) that represents the structure and semantics of a CDDL document. This document provides an overview of the AST structure.
4
-
5
- ## Root Structure
6
-
7
- The root of the AST is an array of `Assignment` nodes, which can be one of:
8
-
9
- - `Group` - Defines a group of properties
10
- - `Array` - Defines an array of values
11
- - `Variable` - Defines a variable assignment
12
-
13
- ```typescript
14
- // The type hierarchy of the AST root
15
- export type Assignment = Group | Array | Variable
16
- ```
17
-
18
- ## Core Components
19
-
20
- The AST is composed of several core types that represent different CDDL constructs:
21
-
22
- ### Assignments
23
-
24
- Assignments are the top-level nodes in the AST. They represent named definitions in CDDL.
25
-
26
- ```typescript
27
- // Example AST for a group assignment:
28
- {
29
- "Type": "group",
30
- "Name": "person",
31
- "IsChoiceAddition": false,
32
- "Properties": [
33
- // Properties...
34
- ],
35
- "Comments": []
36
- }
37
- ```
38
-
39
- ### Properties
40
-
41
- Properties define members of groups or elements of arrays.
42
-
43
- ```typescript
44
- export type Property = {
45
- HasCut: boolean // Whether the property has a "cut" marker (/)
46
- Occurrence: Occurrence // How many times the property can occur
47
- Name: PropertyName // The name of the property (string)
48
- Type: PropertyType | PropertyType[] // The type(s) of the property
49
- Comments: Comment[] // Comments attached to the property
50
- Operator?: Operator // Optional operator modifying the property
51
- }
52
- ```
53
-
54
- ### Types
55
-
56
- Types define the allowed values for properties and variables. They can be:
57
-
58
- - Primitive types (int, uint, tstr, etc.)
59
- - References to groups or other types
60
- - Literals (specific values)
61
- - Complex types (like ranges, choices, etc.)
62
-
63
- ```typescript
64
- export type PropertyType = Assignment | Array | PropertyReference | string | NativeTypeWithOperator
65
- ```
66
-
67
- ## Relationships Between Components
68
-
69
- The AST forms a tree structure where:
70
-
71
- 1. The root consists of assignments
72
- 2. Assignments contain properties or type definitions
73
- 3. Properties reference types
74
- 4. Types can reference other assignments
75
-
76
- This hierarchical structure allows the AST to represent complex CDDL documents with nested definitions, references, and type relationships.
77
-
78
- ## Example AST
79
-
80
- Here's a simplified example of an AST for a basic CDDL definition:
81
-
82
- ```cddl
83
- person = {
84
- name: tstr,
85
- age: uint,
86
- addresses: [* address],
87
- }
88
-
89
- address = {
90
- street: tstr,
91
- city: tstr,
92
- }
93
- ```
94
-
95
- Would generate an AST like:
96
-
97
- ```json
98
- [
99
- {
100
- "Type": "group",
101
- "Name": "person",
102
- "IsChoiceAddition": false,
103
- "Properties": [
104
- {
105
- "HasCut": true,
106
- "Occurrence": { "n": 1, "m": 1 },
107
- "Name": "name",
108
- "Type": ["tstr"],
109
- "Comments": []
110
- },
111
- {
112
- "HasCut": true,
113
- "Occurrence": { "n": 1, "m": 1 },
114
- "Name": "age",
115
- "Type": ["uint"],
116
- "Comments": []
117
- },
118
- {
119
- "HasCut": true,
120
- "Occurrence": { "n": 1, "m": 1 },
121
- "Name": "addresses",
122
- "Type": [{
123
- "Type": "array",
124
- "Values": [{
125
- "HasCut": false,
126
- "Occurrence": { "n": 0, "m": Infinity },
127
- "Name": "",
128
- "Type": [{
129
- "Type": "group",
130
- "Value": "address",
131
- "Unwrapped": false
132
- }],
133
- "Comments": []
134
- }]
135
- }],
136
- "Comments": []
137
- }
138
- ],
139
- "Comments": []
140
- },
141
- {
142
- "Type": "group",
143
- "Name": "address",
144
- "IsChoiceAddition": false,
145
- "Properties": [
146
- {
147
- "HasCut": true,
148
- "Occurrence": { "n": 1, "m": 1 },
149
- "Name": "street",
150
- "Type": ["tstr"],
151
- "Comments": []
152
- },
153
- {
154
- "HasCut": true,
155
- "Occurrence": { "n": 1, "m": 1 },
156
- "Name": "city",
157
- "Type": ["tstr"],
158
- "Comments": []
159
- }
160
- ],
161
- "Comments": []
162
- }
163
- ]
164
- ```
165
-
166
- See the other documentation files for details on each component of the AST.