cddl 0.12.1 → 0.13.1
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/build/cli/commands/repl.d.ts +1 -1
- package/build/cli/commands/repl.d.ts.map +1 -1
- package/build/cli/commands/repl.js +2 -2
- package/build/lexer.d.ts.map +1 -1
- package/build/lexer.js +0 -1
- package/build/parser.d.ts.map +1 -1
- package/build/parser.js +12 -4
- package/docs/cddl-cheatsheet.md +35 -0
- package/package.json +11 -7
|
@@ -3,5 +3,5 @@ export declare const command = "repl";
|
|
|
3
3
|
export declare const desc = "Run CDDL repl";
|
|
4
4
|
export declare const builder: (yargs: Argv<{}>) => Argv<{}>;
|
|
5
5
|
export declare const handler: () => void;
|
|
6
|
-
export declare function evaluate(evalCmd: string, _: any,
|
|
6
|
+
export declare function evaluate(evalCmd: string, _: any, _file: string, callback: (err: Error | null, result: any) => void): void;
|
|
7
7
|
//# sourceMappingURL=repl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/repl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAMjC,eAAO,MAAM,OAAO,SAAS,CAAA;AAC7B,eAAO,MAAM,IAAI,kBAAkB,CAAA;AACnC,eAAO,MAAM,OAAO,GAAI,OAAO,IAAI,CAAC,EAAE,CAAC,aAItC,CAAA;AAED,eAAO,MAAM,OAAO,YAKnB,CAAA;AAED,wBAAgB,QAAQ,CAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/repl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAMjC,eAAO,MAAM,OAAO,SAAS,CAAA;AAC7B,eAAO,MAAM,IAAI,kBAAkB,CAAA;AACnC,eAAO,MAAM,OAAO,GAAI,OAAO,IAAI,CAAC,EAAE,CAAC,aAItC,CAAA;AAED,eAAO,MAAM,OAAO,YAKnB,CAAA;AAED,wBAAgB,QAAQ,CAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,QAUnH"}
|
|
@@ -10,12 +10,12 @@ export const builder = (yargs) => {
|
|
|
10
10
|
.help();
|
|
11
11
|
};
|
|
12
12
|
export const handler = () => {
|
|
13
|
-
|
|
13
|
+
repl.start({
|
|
14
14
|
prompt: '> ',
|
|
15
15
|
eval: evaluate
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
|
-
export function evaluate(evalCmd, _,
|
|
18
|
+
export function evaluate(evalCmd, _, _file, callback) {
|
|
19
19
|
if (!evalCmd) {
|
|
20
20
|
return callback(new Error('No input'), null);
|
|
21
21
|
}
|
package/build/lexer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../src/lexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,aAAa,CAAC;AAI5C,MAAM,CAAC,OAAO,OAAO,KAAK;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAI;IACpB,YAAY,EAAE,MAAM,CAAI;IACxB,EAAE,EAAE,MAAM,CAAI;gBAED,MAAM,EAAE,MAAM;IAM3B,OAAO,CAAC,QAAQ;IAUhB,WAAW;;;;
|
|
1
|
+
{"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../src/lexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,aAAa,CAAC;AAI5C,MAAM,CAAC,OAAO,OAAO,KAAK;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAI;IACpB,YAAY,EAAE,MAAM,CAAI;IACxB,EAAE,EAAE,MAAM,CAAI;gBAED,MAAM,EAAE,MAAM;IAM3B,OAAO,CAAC,QAAQ;IAUhB,WAAW;;;;IAoBX,OAAO,CAAE,UAAU,EAAE,MAAM;IAI3B,eAAe;IASf,SAAS,IAAK,KAAK;IA+FnB,OAAO,CAAC,cAAc;IA2BtB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,iBAAiB;IA8BzB,OAAO,CAAC,cAAc;CAKzB"}
|
package/build/lexer.js
CHANGED
package/build/parser.d.ts.map
CHANGED
|
@@ -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;IAC7B,cAAc,EAAE,KAAK,CAAa;gBAErB,QAAQ,EAAE,MAAM;IAS7B,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,gBAAgB;IA2CxB,OAAO,CAAC,oBAAoB;
|
|
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;IAC7B,cAAc,EAAE,KAAK,CAAa;gBAErB,QAAQ,EAAE,MAAM;IAS7B,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,gBAAgB;IA2CxB,OAAO,CAAC,oBAAoB;IAue5B,OAAO,CAAC,wBAAwB;IAahC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,iBAAiB;IAqKzB,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
|
@@ -120,7 +120,7 @@ export default class Parser {
|
|
|
120
120
|
const propertyType = [];
|
|
121
121
|
while (!closingTokens.includes(this.curToken.Type)) {
|
|
122
122
|
propertyType.push(...this.parsePropertyTypes());
|
|
123
|
-
if (this.curToken.Type
|
|
123
|
+
if (closingTokens.includes(this.curToken.Type)) {
|
|
124
124
|
this.nextToken();
|
|
125
125
|
break;
|
|
126
126
|
}
|
|
@@ -239,6 +239,14 @@ export default class Parser {
|
|
|
239
239
|
this.nextToken();
|
|
240
240
|
isChoice = false;
|
|
241
241
|
}
|
|
242
|
+
if (this.curToken.Type === Tokens.SLASH && this.peekToken.Type !== Tokens.SLASH) {
|
|
243
|
+
if (!isChoice) {
|
|
244
|
+
const last = valuesOrProperties.pop();
|
|
245
|
+
valuesOrProperties.push([last]);
|
|
246
|
+
isChoice = true;
|
|
247
|
+
}
|
|
248
|
+
this.nextToken();
|
|
249
|
+
}
|
|
242
250
|
continue;
|
|
243
251
|
}
|
|
244
252
|
/**
|
|
@@ -727,8 +735,8 @@ export default class Parser {
|
|
|
727
735
|
Operator: this.parseOperator()
|
|
728
736
|
};
|
|
729
737
|
}
|
|
730
|
-
else {
|
|
731
|
-
this.nextToken(); // eat
|
|
738
|
+
else if (this.curToken.Type !== Tokens.SLASH) {
|
|
739
|
+
this.nextToken(); // eat Property if not already consumed (e.g. by Group parsing)
|
|
732
740
|
}
|
|
733
741
|
propertyTypes.push(prop);
|
|
734
742
|
/**
|
|
@@ -747,7 +755,7 @@ export default class Parser {
|
|
|
747
755
|
while (this.curToken.Type === Tokens.SLASH) {
|
|
748
756
|
this.nextToken(); // eat `/`
|
|
749
757
|
propertyTypes.push(this.parsePropertyType());
|
|
750
|
-
if (!this.isOperator()) {
|
|
758
|
+
if (!this.isOperator() && this.curToken.Type !== Tokens.SLASH) {
|
|
751
759
|
/**
|
|
752
760
|
* If we are not parsing an operator, we need to eat the next token;
|
|
753
761
|
* otherwise, the operator will be parsed by the caller
|
package/docs/cddl-cheatsheet.md
CHANGED
|
@@ -193,4 +193,39 @@ LiteralTest = {
|
|
|
193
193
|
is_active: true,
|
|
194
194
|
deleted_at: null
|
|
195
195
|
}
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 6. Groups as Maps
|
|
200
|
+
|
|
201
|
+
Wrap a **Group** in curly braces `{}` to treat it as a **Map**.
|
|
202
|
+
|
|
203
|
+
```cddl
|
|
204
|
+
; A reusable Group of fields
|
|
205
|
+
DateFields = ( year: int, month: int, day: int )
|
|
206
|
+
|
|
207
|
+
; 1. Mix it into a Map
|
|
208
|
+
Appointment = {
|
|
209
|
+
description: tstr,
|
|
210
|
+
DateFields
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
; 2. Standalone Map
|
|
214
|
+
DateObject = { DateFields }
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Choices with Groups and Maps
|
|
218
|
+
|
|
219
|
+
You can mix explicit Maps and Groups-as-Maps in type choices:
|
|
220
|
+
|
|
221
|
+
```cddl
|
|
222
|
+
ArrayMap = { type: "array", values: [...] }
|
|
223
|
+
DateGroup = ( type: "date", value: tstr )
|
|
224
|
+
|
|
225
|
+
; Matches either map structure
|
|
226
|
+
MixedValue = (
|
|
227
|
+
ArrayMap / ; Map defined elsewhere
|
|
228
|
+
{ DateGroup } ; Group wrapped in Map
|
|
229
|
+
)
|
|
230
|
+
```
|
|
196
231
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cddl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
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",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"keywords": [
|
|
13
13
|
"cddl"
|
|
14
14
|
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20.0.0",
|
|
17
|
+
"npm": ">=9.0.0"
|
|
18
|
+
},
|
|
15
19
|
"bugs": {
|
|
16
20
|
"url": "https://github.com/christian-bromann/cddl/issues"
|
|
17
21
|
},
|
|
@@ -35,15 +39,15 @@
|
|
|
35
39
|
"watch": "tsc --watch"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
|
-
"@types/
|
|
39
|
-
"@types/
|
|
40
|
-
"@vitest/coverage-v8": "^
|
|
42
|
+
"@types/node": "^24.12.0",
|
|
43
|
+
"@types/yargs": "^17.0.35",
|
|
44
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
41
45
|
"npm-run-all": "^4.1.5",
|
|
42
46
|
"release-it": "^19.2.4",
|
|
43
|
-
"typescript": "^5.
|
|
44
|
-
"vitest": "^
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vitest": "^4.1.0"
|
|
45
49
|
},
|
|
46
50
|
"dependencies": {
|
|
47
|
-
"yargs": "^
|
|
51
|
+
"yargs": "^18.0.0"
|
|
48
52
|
}
|
|
49
53
|
}
|