cddl 0.9.0 → 0.11.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.
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAU,MAAM,aAAa,CAAC;AAG5C,OAAO,EAE2C,UAAU,EAE3D,MAAM,UAAU,CAAA;AAoBjB,MAAM,CAAC,OAAO,OAAO,MAAM;;IAEvB,CAAC,EAAE,KAAK,CAAC;IAET,QAAQ,EAAE,KAAK,CAAa;IAC5B,SAAS,EAAE,KAAK,CAAa;gBAEhB,QAAQ,EAAE,MAAM;IAQ7B,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,gBAAgB;IA2CxB,OAAO,CAAC,oBAAoB;IAua5B,OAAO,CAAC,wBAAwB;IAahC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,iBAAiB;IA8HzB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;IAiD1B,OAAO,CAAC,gBAAgB;IA4DxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAcpB,KAAK;IAaL,OAAO,CAAC,WAAW;CAKtB"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAU,MAAM,aAAa,CAAC;AAG5C,OAAO,EAE2C,UAAU,EAE3D,MAAM,UAAU,CAAA;AAoBjB,MAAM,CAAC,OAAO,OAAO,MAAM;;IAEvB,CAAC,EAAE,KAAK,CAAC;IAET,QAAQ,EAAE,KAAK,CAAa;IAC5B,SAAS,EAAE,KAAK,CAAa;gBAEhB,QAAQ,EAAE,MAAM;IAQ7B,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,gBAAgB;IA2CxB,OAAO,CAAC,oBAAoB;IAqb5B,OAAO,CAAC,wBAAwB;IAahC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,iBAAiB;IAqJzB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;IAuD1B,OAAO,CAAC,gBAAgB;IA4DxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAcpB,KAAK;IAaL,OAAO,CAAC,WAAW;CAKtB"}
package/build/parser.js CHANGED
@@ -142,9 +142,11 @@ export default class Parser {
142
142
  * parse operator assignments, e.g. `ip4 = (float .ge 0.0) .default 1.0`
143
143
  */
144
144
  if (closingTokens.length === 1 && this.peekToken.Type === Tokens.DOT) {
145
+ const propertyType = this.parsePropertyType();
146
+ const operator = this.isOperator() ? this.parseOperator() : undefined;
145
147
  const prop = {
146
- Type: this.parsePropertyType(),
147
- Operator: this.parseOperator()
148
+ Type: propertyType,
149
+ ...(operator ? { Operator: operator } : {})
148
150
  };
149
151
  this.nextToken(); // eat closing token
150
152
  if (groupName) {
@@ -315,6 +317,18 @@ export default class Parser {
315
317
  */
316
318
  const props = this.parseAssignmentValue();
317
319
  const operator = this.isOperator() ? this.parseOperator() : undefined;
320
+ if (!isChoice && this.curToken.Type === Tokens.SLASH) {
321
+ this.nextToken();
322
+ const nextType = this.parsePropertyType();
323
+ if (Array.isArray(props)) {
324
+ /**
325
+ * property has not yet been flagged as a choice, but is part
326
+ * of one, e.g. `(float .ge 1.0) / null`
327
+ */
328
+ props.push(nextType);
329
+ this.nextToken();
330
+ }
331
+ }
318
332
  if (Array.isArray(props)) {
319
333
  /**
320
334
  * property has multiple types (e.g. `float / tstr / int`)
@@ -609,6 +623,28 @@ export default class Parser {
609
623
  },
610
624
  Unwrapped: isUnwrapped
611
625
  };
626
+ if (!isGroupedRange && this.peekToken.Literal === Tokens.RPAREN) {
627
+ /**
628
+ * If we are at the end of a grouped range, and this was called
629
+ * on the first item of the range as opposed to the opening
630
+ * parenthesis, isGroupedRange will not be set to true at this
631
+ * point. We need to advance to the closing parenthesis, and if
632
+ * the next token is an operator, we need to advance to the dot
633
+ * so that parseOperator will work properly.
634
+ * e.g.
635
+ *
636
+ * ```
637
+ * (1.0..2.0) .default 1.5
638
+ * ```
639
+ *
640
+ * This will be called on the `1.0` and then the `2.0` will be parsed
641
+ * as a grouped range.
642
+ */
643
+ this.nextToken();
644
+ if (this.peekToken.Type === Tokens.DOT) {
645
+ isGroupedRange = true;
646
+ }
647
+ }
612
648
  if (isGroupedRange) {
613
649
  this.nextToken(); // eat ")"
614
650
  }
@@ -661,7 +697,13 @@ export default class Parser {
661
697
  while (this.curToken.Type === Tokens.SLASH) {
662
698
  this.nextToken(); // eat `/`
663
699
  propertyTypes.push(this.parsePropertyType());
664
- this.nextToken();
700
+ if (!this.isOperator()) {
701
+ /**
702
+ * If we are not parsing an operator, we need to eat the next token;
703
+ * otherwise, the operator will be parsed by the caller
704
+ */
705
+ this.nextToken();
706
+ }
665
707
  /**
666
708
  * ensure we don't go into the next choice, e.g.:
667
709
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cddl",
3
- "version": "0.9.0",
3
+ "version": "0.11.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",