cddl 0.1.2 → 0.2.2

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.
package/README.md CHANGED
@@ -5,6 +5,9 @@ CDDL ![Test](https://github.com/christian-bromann/cddl/workflows/Test/badge.svg?
5
5
 
6
6
  CDDL expresses Concise Binary Object Representation (CBOR) data structures ([RFC 7049](https://tools.ietf.org/html/rfc7049)). Its main goal is to provide an easy and unambiguous way to express structures for protocol messages and data formats that use CBOR or JSON.
7
7
 
8
+ There are also CDDL parser for other languages:
9
+ - Rust: [anweiss/cddl](https://github.com/anweiss/cddl)
10
+
8
11
  __Note:__ this is __work in progress__, feel free to have a look at the code or contribute but don't use this for anything yet!
9
12
 
10
13
  ## Install
@@ -17,21 +20,35 @@ $ npm install cddl
17
20
 
18
21
  ## Using this package
19
22
 
20
- Currently you can use this package to parse a CDDL file into an [abstract syntax tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST). For example you can run the following script:
21
-
22
- ```js
23
- const fs = require('fs')
24
- const path = require('path')
23
+ Currently you can use this package to parse a CDDL file into an [abstract syntax tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST). For example, given the following CDDL file:
25
24
 
26
- const { Parser, Lexer } = require('cddl')
25
+ ```cddl
26
+ person = {
27
+ identity, ; an identity
28
+ employer: tstr, ; some employer
29
+ }
30
+ ```
27
31
 
28
- const input = fs.readFileSync('./spec.cddl')
32
+ You can use this package to parse the file into an abstract syntax tree (AST):
29
33
 
30
- const l = new Lexer(input)
31
- const parser = new Parser(l)
32
- console.log(JSON.stringify(parser.parse(), null, 4))
34
+ ```js
35
+ const CDDL = require('cddl').default
36
+
37
+ const ast = CDDL.parse('./spec.cddl')
38
+ console.log(ast)
39
+ /**
40
+ * outputs:
41
+ * [
42
+ * {
43
+ * Type: 'group',
44
+ * Name: 'person',
45
+ * Properties: [ [Object], [Object] ],
46
+ * IsChoiceAddition: false
47
+ * }
48
+ * ]
49
+ */
33
50
  ```
34
51
 
35
52
  ---
36
53
 
37
- If you are interested in this project, please feel free to contribute ideas or code patches. Have a look into our [contributing guidelines](https://github.com/christian-bromann/cddl/blob/master/LICENSE) to get started.
54
+ If you are interested in this project, please feel free to contribute ideas or code patches. Have a look into our [contributing guidelines](https://github.com/christian-bromann/cddl/blob/master/LICENSE) to get started.
package/build/ast.d.ts CHANGED
@@ -11,7 +11,8 @@
11
11
  export declare type Group = {
12
12
  Type: 'group';
13
13
  Name: string;
14
- Properties: Property[];
14
+ IsChoiceAddition: boolean;
15
+ Properties: (Property | Property[])[];
15
16
  };
16
17
  /**
17
18
  * an array definition
@@ -24,7 +25,7 @@ export declare type Group = {
24
25
  export declare type Array = {
25
26
  Type: 'array';
26
27
  Name: string;
27
- Values: Property[];
28
+ Values: (Property | Property[])[];
28
29
  };
29
30
  /**
30
31
  * a tag definition
@@ -45,6 +46,7 @@ export declare type Tag = {
45
46
  export declare type Variable = {
46
47
  Type: 'variable';
47
48
  Name: string;
49
+ IsChoiceAddition: boolean;
48
50
  PropertyType: PropertyType | PropertyType[];
49
51
  };
50
52
  /**
@@ -116,7 +118,7 @@ export declare type Range = {
116
118
  export declare type PropertyReferenceType = 'literal' | 'group' | 'group_array' | 'range' | 'tag';
117
119
  export declare type PropertyReference = {
118
120
  Type: PropertyReferenceType;
119
- Value: string | number | Group | Array | Range | Tag;
121
+ Value: string | number | boolean | Group | Array | Range | Tag;
120
122
  Unwrapped: boolean;
121
123
  };
122
124
  export declare type Assignment = Group | Array | Variable | Comment;
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,oBAAY,KAAK,GAAG;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,QAAQ,EAAE,CAAC;CAC1B,CAAA;AAED;;;;;;;GAOG;AACH,oBAAY,KAAK,GAAG;IAChB,IA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,SAAS,EAAE,OAAO,CAAC;CACtB,CAAA;AAED,oBAAY,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC5D,oBAAY,YAAY,GAAG,UAAU,GAAG,KAAK,GAAG,iBAAiB,GAAG,MAAM,CAAA;AAC1E,oBAAY,YAAY,GAAG,MAAM,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export declare const WHITESPACE_CHARACTERS: string[];
2
+ export declare const BOOLEAN_LITERALS: string[];
2
3
  /**
3
4
  * as defined in Appendix D
4
5
  * https://tools.ietf.org/html/draft-ietf-cbor-cddl-08#appendix-D
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,UAA0B,CAAA;AAE5D;;;GAGG;AACH,eAAO,MAAM,qBAAqB,UAQjC,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,UAA0B,CAAA;AAC5D,eAAO,MAAM,gBAAgB,UAAoB,CAAA;AAEjD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,UAQjC,CAAA"}
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PREDEFINED_IDENTIFIER = exports.WHITESPACE_CHARACTERS = void 0;
3
+ exports.PREDEFINED_IDENTIFIER = exports.BOOLEAN_LITERALS = exports.WHITESPACE_CHARACTERS = void 0;
4
4
  exports.WHITESPACE_CHARACTERS = [' ', '\t', '\n', '\r'];
5
+ exports.BOOLEAN_LITERALS = ['true', 'false'];
5
6
  /**
6
7
  * as defined in Appendix D
7
8
  * https://tools.ietf.org/html/draft-ietf-cbor-cddl-08#appendix-D
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,O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xB;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB,KAAK;CAsBR"}
package/build/parser.js CHANGED
@@ -20,16 +20,32 @@ class Parser {
20
20
  return true;
21
21
  }
22
22
  parseAssignments() {
23
- if (this.curToken.Type !== tokens_1.Tokens.IDENT && this.peekToken.Type !== tokens_1.Tokens.ASSIGN) {
23
+ /**
24
+ * expect group identifier, e.g.
25
+ * groupName =
26
+ * groupName /=
27
+ * groupName //=
28
+ */
29
+ if (this.curToken.Type !== tokens_1.Tokens.IDENT || !(this.peekToken.Type === tokens_1.Tokens.ASSIGN || this.peekToken.Type === tokens_1.Tokens.SLASH)) {
24
30
  throw new Error(`group identifier expected, received "${JSON.stringify(this.curToken)}"`);
25
31
  }
32
+ let isChoiceAddition = false;
26
33
  const groupName = this.curToken.Literal;
27
34
  this.nextToken(); // eat group identifier
35
+ // @ts-ignore
36
+ if (this.curToken.Type === tokens_1.Tokens.SLASH) {
37
+ isChoiceAddition = true;
38
+ this.nextToken(); // eat `/`
39
+ }
40
+ // @ts-ignore
41
+ if (this.curToken.Type === tokens_1.Tokens.SLASH) {
42
+ this.nextToken(); // eat `/`
43
+ }
28
44
  this.nextToken(); // eat `=`
29
- return this.parseAssignmentValue(groupName);
45
+ return this.parseAssignmentValue(groupName, isChoiceAddition);
30
46
  }
31
- parseAssignmentValue(groupName) {
32
- let assignment;
47
+ parseAssignmentValue(groupName, isChoiceAddition = false) {
48
+ let isChoice = false;
33
49
  const valuesOrProperties = [];
34
50
  const closingTokens = this.openSegment();
35
51
  /**
@@ -41,11 +57,12 @@ class Parser {
41
57
  const variable = {
42
58
  Type: 'variable',
43
59
  Name: groupName,
60
+ IsChoiceAddition: isChoiceAddition,
44
61
  PropertyType: this.parsePropertyTypes()
45
62
  };
46
63
  return variable;
47
64
  }
48
- return this.parsePropertyType();
65
+ return this.parsePropertyTypes();
49
66
  }
50
67
  while (!closingTokens.includes(this.curToken.Type)) {
51
68
  const propertyType = [];
@@ -114,49 +131,105 @@ class Parser {
114
131
  this.nextToken(); // eat ^
115
132
  }
116
133
  }
134
+ /**
135
+ * check if we have a choice instead of an assignment
136
+ */
137
+ if (this.curToken.Type === tokens_1.Tokens.SLASH && this.peekToken.Type === tokens_1.Tokens.SLASH) {
138
+ const prop = {
139
+ HasCut: hasCut,
140
+ Occurrence: occurrence,
141
+ Name: '',
142
+ Type: {
143
+ Type: "group",
144
+ Value: propertyName,
145
+ Unwrapped: isUnwrapped
146
+ },
147
+ Comment: comment
148
+ };
149
+ if (isChoice) {
150
+ /**
151
+ * if we already in a choice just push into it
152
+ */
153
+ valuesOrProperties[valuesOrProperties.length - 1].push(prop);
154
+ }
155
+ else {
156
+ /**
157
+ * otherwise create a new one
158
+ */
159
+ isChoice = true;
160
+ valuesOrProperties.push([prop]);
161
+ }
162
+ this.nextToken(); // eat /
163
+ this.nextToken(); // eat /
164
+ continue;
165
+ }
117
166
  /**
118
167
  * else if no colon was found, throw
119
168
  */
120
169
  if (!this.isPropertyValueSeparator()) {
121
- throw new Error('Expected ":" or "=>');
170
+ throw new Error('Expected ":" or "=>"');
122
171
  }
123
- this.nextToken();
172
+ this.nextToken(); // eat :
124
173
  /**
125
174
  * parse property value
126
175
  */
127
- propertyType.push(this.parseAssignmentValue());
128
- this.nextToken();
129
- /**
130
- * continue parse possible other types (e.g. `float / tstr / int`)
131
- */
132
- propertyType.push(...this.parsePropertyTypes(true));
176
+ const props = this.parseAssignmentValue();
177
+ if (Array.isArray(props)) {
178
+ /**
179
+ * property has multiple types (e.g. `float / tstr / int`)
180
+ */
181
+ propertyType.push(...props);
182
+ }
183
+ else {
184
+ propertyType.push(props);
185
+ }
133
186
  /**
134
187
  * advance comma
135
188
  */
136
- // @ts-ignore
189
+ let flipIsChoice = false;
137
190
  if (this.curToken.Type === tokens_1.Tokens.COMMA) {
138
- this.nextToken();
191
+ /**
192
+ * if we are in a choice, we leave it here
193
+ */
194
+ flipIsChoice = true;
195
+ this.nextToken(); // eat ,
139
196
  }
140
197
  comment = this.parseComment();
141
- valuesOrProperties.push({
198
+ const prop = {
142
199
  HasCut: hasCut,
143
200
  Occurrence: occurrence,
144
201
  Name: propertyName,
145
202
  Type: propertyType,
146
203
  Comment: comment
147
- });
204
+ };
205
+ if (isChoice) {
206
+ valuesOrProperties[valuesOrProperties.length - 1].push(prop);
207
+ }
208
+ else {
209
+ valuesOrProperties.push(prop);
210
+ }
211
+ if (flipIsChoice) {
212
+ isChoice = false;
213
+ }
148
214
  /**
149
215
  * if `}` is found we are at the end of the group
150
216
  */
151
- // @ts-ignore
152
217
  if (closingTokens.includes(this.curToken.Type)) {
153
218
  break;
154
219
  }
220
+ /**
221
+ * eat // if we are in a choice
222
+ */
223
+ if (isChoice) {
224
+ this.nextToken(); // eat /
225
+ this.nextToken(); // eat /
226
+ continue;
227
+ }
155
228
  }
156
229
  /**
157
230
  * close segment
158
231
  */
159
- while (this.curToken.Type === [...closingTokens].shift()) {
232
+ if (this.curToken.Type === [...closingTokens].shift()) {
160
233
  this.nextToken();
161
234
  }
162
235
  /**
@@ -175,7 +248,8 @@ class Parser {
175
248
  return {
176
249
  Type: 'group',
177
250
  Name: groupName || '',
178
- Properties: valuesOrProperties
251
+ Properties: valuesOrProperties,
252
+ IsChoiceAddition: isChoiceAddition
179
253
  };
180
254
  }
181
255
  isPropertyValueSeparator() {
@@ -249,7 +323,14 @@ class Parser {
249
323
  type = this.curToken.Literal;
250
324
  break;
251
325
  default: {
252
- if (this.curToken.Type === tokens_1.Tokens.IDENT) {
326
+ if (constants_1.BOOLEAN_LITERALS.includes(this.curToken.Literal)) {
327
+ type = {
328
+ Type: 'literal',
329
+ Value: this.curToken.Literal === 'true',
330
+ Unwrapped: isUnwrapped
331
+ };
332
+ }
333
+ else if (this.curToken.Type === tokens_1.Tokens.IDENT) {
253
334
  type = {
254
335
  Type: 'group',
255
336
  Value: this.curToken.Literal,
@@ -322,14 +403,19 @@ class Parser {
322
403
  }
323
404
  return type;
324
405
  }
325
- parsePropertyTypes(parseFromWithin) {
406
+ parsePropertyTypes() {
326
407
  const propertyTypes = [];
408
+ propertyTypes.push(this.parsePropertyType());
409
+ this.nextToken(); // eat `/`
327
410
  /**
328
- * if the first part of the property was parsed skip this step
411
+ * ensure we don't go into the next choice, e.g.:
412
+ * ```
413
+ * delivery = (
414
+ * city // lala: tstr / bool // per-pickup: true,
415
+ * )
329
416
  */
330
- if (!parseFromWithin) {
331
- propertyTypes.push(this.parsePropertyType());
332
- this.nextToken(); // eat `/`
417
+ if (this.curToken.Type === tokens_1.Tokens.SLASH && this.peekToken.Type === tokens_1.Tokens.SLASH) {
418
+ return propertyTypes;
333
419
  }
334
420
  /**
335
421
  * capture more if available (e.g. `tstr / float / boolean`)
@@ -338,6 +424,16 @@ class Parser {
338
424
  this.nextToken(); // eat `/`
339
425
  propertyTypes.push(this.parsePropertyType());
340
426
  this.nextToken();
427
+ /**
428
+ * ensure we don't go into the next choice, e.g.:
429
+ * ```
430
+ * delivery = (
431
+ * city // lala: tstr / bool // per-pickup: true,
432
+ * )
433
+ */
434
+ if (this.curToken.Type === tokens_1.Tokens.SLASH && this.peekToken.Type === tokens_1.Tokens.SLASH) {
435
+ break;
436
+ }
341
437
  }
342
438
  return propertyTypes;
343
439
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "cddl",
3
- "version": "0.1.2",
3
+ "version": "0.2.2",
4
4
  "description": "Concise data definition language (RFC 8610) implementation and JSON validator in Node.js",
5
- "main": "index.js",
5
+ "main": "build/index.js",
6
6
  "bin": {
7
7
  "cddl": "./bin/cddl.js"
8
8
  },