cddl 0.2.1 → 0.3.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.
- package/.nvmrc +1 -0
- package/README.md +5 -5
- package/bin/cddl.js +3 -1
- package/build/ast.d.ts +14 -14
- package/build/ast.d.ts.map +1 -1
- package/build/ast.js +2 -5
- package/build/cli/commands/repl.d.ts +3 -3
- package/build/cli/commands/repl.d.ts.map +1 -1
- package/build/cli/commands/repl.js +13 -20
- package/build/cli/commands/validate.d.ts +4 -4
- package/build/cli/commands/validate.d.ts.map +1 -1
- package/build/cli/commands/validate.js +14 -19
- package/build/cli/constants.d.ts +1 -1
- package/build/cli/constants.js +1 -4
- package/build/cli/index.d.ts +7 -3
- package/build/cli/index.d.ts.map +1 -1
- package/build/cli/index.js +12 -12
- package/build/constants.d.ts +4 -0
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +8 -6
- package/build/index.d.ts +6 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +16 -17
- package/build/lexer.d.ts +7 -1
- package/build/lexer.d.ts.map +1 -1
- package/build/lexer.js +81 -50
- package/build/parser.d.ts +6 -4
- package/build/parser.d.ts.map +1 -1
- package/build/parser.js +126 -79
- package/build/tokens.d.ts +2 -2
- package/build/tokens.d.ts.map +1 -1
- package/build/tokens.js +2 -5
- package/build/transform/ts.d.ts +3 -0
- package/build/transform/ts.d.ts.map +1 -0
- package/build/transform/ts.js +113 -0
- package/build/types.d.ts +5 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +1 -0
- package/build/utils.d.ts +1 -1
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +11 -18
- package/examples/webdriver/local.cddl +846 -0
- package/examples/webdriver/remote.cddl +830 -0
- package/package.json +30 -26
- package/vitest.config.ts +16 -0
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v18.15.0
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ CDDL  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
|
|
8
|
+
There are also CDDL parsers for other languages:
|
|
9
9
|
- Rust: [anweiss/cddl](https://github.com/anweiss/cddl)
|
|
10
10
|
|
|
11
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!
|
|
@@ -20,7 +20,7 @@ $ npm install cddl
|
|
|
20
20
|
|
|
21
21
|
## Using this package
|
|
22
22
|
|
|
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:
|
|
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:
|
|
24
24
|
|
|
25
25
|
```cddl
|
|
26
26
|
person = {
|
|
@@ -32,9 +32,9 @@ person = {
|
|
|
32
32
|
You can use this package to parse the file into an abstract syntax tree (AST):
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
|
|
35
|
+
import { parse } from 'cddl'
|
|
36
36
|
|
|
37
|
-
const ast =
|
|
37
|
+
const ast = parse('./spec.cddl')
|
|
38
38
|
console.log(ast)
|
|
39
39
|
/**
|
|
40
40
|
* outputs:
|
|
@@ -51,4 +51,4 @@ console.log(ast)
|
|
|
51
51
|
|
|
52
52
|
---
|
|
53
53
|
|
|
54
|
-
If you are interested in this project, please feel free to contribute ideas or code patches. Have a look
|
|
54
|
+
If you are interested in this project, please feel free to contribute ideas or code patches. Have a look at our [contributing](https://github.com/christian-bromann/cddl/blob/master/LICENSE) guidelines](https://github.com/christian-bromann/cddl/blob/master/LICENSE) to get started.
|
package/bin/cddl.js
CHANGED
package/build/ast.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* }
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type Group = {
|
|
12
12
|
Type: 'group';
|
|
13
13
|
Name: string;
|
|
14
14
|
IsChoiceAddition: boolean;
|
|
@@ -22,7 +22,7 @@ export declare type Group = {
|
|
|
22
22
|
* ]
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export type Array = {
|
|
26
26
|
Type: 'array';
|
|
27
27
|
Name: string;
|
|
28
28
|
Values: (Property | Property[])[];
|
|
@@ -33,7 +33,7 @@ export declare type Array = {
|
|
|
33
33
|
* #6.32(tstr)
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export
|
|
36
|
+
export type Tag = {
|
|
37
37
|
NumericPart: number;
|
|
38
38
|
TypePart: string;
|
|
39
39
|
};
|
|
@@ -43,7 +43,7 @@ export declare type Tag = {
|
|
|
43
43
|
* device-address = byte
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
export
|
|
46
|
+
export type Variable = {
|
|
47
47
|
Type: 'variable';
|
|
48
48
|
Name: string;
|
|
49
49
|
IsChoiceAddition: boolean;
|
|
@@ -55,15 +55,15 @@ export declare type Variable = {
|
|
|
55
55
|
* ; This is a comment
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
|
-
export
|
|
58
|
+
export type Comment = {
|
|
59
59
|
Type: 'comment';
|
|
60
60
|
Content: string;
|
|
61
61
|
};
|
|
62
|
-
export
|
|
62
|
+
export type Occurrence = {
|
|
63
63
|
n: number;
|
|
64
64
|
m: number;
|
|
65
65
|
};
|
|
66
|
-
export
|
|
66
|
+
export type Property = {
|
|
67
67
|
HasCut: boolean;
|
|
68
68
|
Occurrence: Occurrence;
|
|
69
69
|
Name: PropertyName;
|
|
@@ -109,19 +109,19 @@ export declare enum Type {
|
|
|
109
109
|
* }
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
|
-
export
|
|
113
|
-
export
|
|
112
|
+
export type RangePropertyReference = number | string;
|
|
113
|
+
export type Range = {
|
|
114
114
|
Min: RangePropertyReference;
|
|
115
115
|
Max: RangePropertyReference;
|
|
116
116
|
Inclusive: boolean;
|
|
117
117
|
};
|
|
118
|
-
export
|
|
119
|
-
export
|
|
118
|
+
export type PropertyReferenceType = 'literal' | 'group' | 'group_array' | 'range' | 'tag';
|
|
119
|
+
export type PropertyReference = {
|
|
120
120
|
Type: PropertyReferenceType;
|
|
121
121
|
Value: string | number | boolean | Group | Array | Range | Tag;
|
|
122
122
|
Unwrapped: boolean;
|
|
123
123
|
};
|
|
124
|
-
export
|
|
125
|
-
export
|
|
126
|
-
export
|
|
124
|
+
export type Assignment = Group | Array | Variable | Comment;
|
|
125
|
+
export type PropertyType = Assignment | Array | PropertyReference | string;
|
|
126
|
+
export type PropertyName = string;
|
|
127
127
|
//# sourceMappingURL=ast.d.ts.map
|
package/build/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,KAAK,GAAG;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,CAAC,QAAQ,GAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;CACvC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,KAAK,GAAG;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,QAAQ,GAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;CACnC,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,GAAG,GAAG;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG;IACnB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,YAAY,GAAG,YAAY,EAAE,CAAC;CAC/C,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACb,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,oBAAY,IAAI;IACZ;;OAEG;IAEH,IAAI,SAAS;IAEb;;OAEG;IAEH,GAAG,QAAQ;IAEX,IAAI,SAAS;IAEb,IAAI,SAAS;IAEb,KAAK,UAAU;IAEf,OAAO,YAAY;IAEnB,OAAO,YAAY;IAEnB,OAAO,YAAY;IAEnB;;OAEG;IAEH,IAAI,SAAS;IAEb,KAAK,UAAU;IAEf,IAAI,SAAS;IAEb,IAAI,SAAS;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,MAAM,CAAA;AAEpD,MAAM,MAAM,KAAK,GAAG;IAChB,GAAG,EAAE,sBAAsB,CAAC;IAC5B,GAAG,EAAE,sBAAsB,CAAC;IAC5B,SAAS,EAAE,OAAO,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,GAAG,OAAO,GAAG,KAAK,CAAA;AACzF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,GAAG,CAAC;IAC/D,SAAS,EAAE,OAAO,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC5D,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,KAAK,GAAG,iBAAiB,GAAG,MAAM,CAAA;AAC1E,MAAM,MAAM,YAAY,GAAG,MAAM,CAAA"}
|
package/build/ast.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Type = void 0;
|
|
4
|
-
var Type;
|
|
1
|
+
export var Type;
|
|
5
2
|
(function (Type) {
|
|
6
3
|
/**
|
|
7
4
|
* boolean types
|
|
@@ -36,4 +33,4 @@ var Type;
|
|
|
36
33
|
Type["TSTR"] = "tstr";
|
|
37
34
|
// Text string (major type 3)
|
|
38
35
|
Type["TEXT"] = "text";
|
|
39
|
-
})(Type
|
|
36
|
+
})(Type || (Type = {}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Argv } from 'yargs';
|
|
2
2
|
export declare const command = "repl";
|
|
3
3
|
export declare const desc = "Run CDDL repl";
|
|
4
|
-
export declare const builder: (yargs:
|
|
5
|
-
export declare const handler: (
|
|
4
|
+
export declare const builder: (yargs: Argv<{}>) => Argv<{}>;
|
|
5
|
+
export declare const handler: () => void;
|
|
6
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,MAAM,OAAO,CAAA;
|
|
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,UAAW,KAAK,EAAE,CAAC,aAItC,CAAA;AAED,eAAO,MAAM,OAAO,YAKnB,CAAA;AAED,wBAAgB,QAAQ,CAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,QAUlH"}
|
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
|
-
const lexer_1 = __importDefault(require("../../lexer"));
|
|
10
|
-
const tokens_1 = require("../../tokens");
|
|
11
|
-
exports.command = 'repl';
|
|
12
|
-
exports.desc = 'Run CDDL repl';
|
|
13
|
-
exports.builder = (yargs) => {
|
|
1
|
+
import repl from 'node:repl';
|
|
2
|
+
import { CLI_EPILOGUE } from '../constants.js';
|
|
3
|
+
import Lexer from '../../lexer.js';
|
|
4
|
+
import { Tokens } from '../../tokens.js';
|
|
5
|
+
export const command = 'repl';
|
|
6
|
+
export const desc = 'Run CDDL repl';
|
|
7
|
+
export const builder = (yargs) => {
|
|
14
8
|
return yargs
|
|
15
|
-
.epilogue(
|
|
9
|
+
.epilogue(CLI_EPILOGUE)
|
|
16
10
|
.help();
|
|
17
11
|
};
|
|
18
|
-
|
|
19
|
-
const r =
|
|
12
|
+
export const handler = () => {
|
|
13
|
+
const r = repl.start({
|
|
20
14
|
prompt: '> ',
|
|
21
15
|
eval: evaluate
|
|
22
16
|
});
|
|
23
17
|
};
|
|
24
|
-
function evaluate(evalCmd, _, file, callback) {
|
|
18
|
+
export function evaluate(evalCmd, _, file, callback) {
|
|
25
19
|
if (!evalCmd) {
|
|
26
20
|
return callback(new Error('No input'), null);
|
|
27
21
|
}
|
|
28
|
-
const l = new
|
|
29
|
-
for (let tok = l.nextToken(); tok.Type !==
|
|
22
|
+
const l = new Lexer(evalCmd);
|
|
23
|
+
for (let tok = l.nextToken(); tok.Type !== Tokens.EOF; tok = l.nextToken()) {
|
|
30
24
|
console.log(tok);
|
|
31
25
|
}
|
|
32
26
|
return callback(null, null);
|
|
33
27
|
}
|
|
34
|
-
exports.evaluate = evaluate;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
interface ValidateArguments
|
|
1
|
+
import type { Argv, ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
interface ValidateArguments {
|
|
3
3
|
filePath: string;
|
|
4
4
|
}
|
|
5
5
|
export declare const command = "validate <filePath>";
|
|
6
6
|
export declare const desc = "Validate a *.cddl file";
|
|
7
|
-
export declare const builder: (yargs:
|
|
8
|
-
export declare const handler: (argv: ValidateArguments) => undefined;
|
|
7
|
+
export declare const builder: (yargs: Argv<{}>) => Argv<{}>;
|
|
8
|
+
export declare const handler: (argv: ArgumentsCamelCase<ValidateArguments>) => undefined;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAMrD,UAAU,iBAAiB;IACvB,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,eAAO,MAAM,OAAO,wBAAwB,CAAA;AAC5C,eAAO,MAAM,IAAI,2BAA2B,CAAA;AAC5C,eAAO,MAAM,OAAO,UAAW,KAAK,EAAE,CAAC,aAItC,CAAA;AAED,eAAO,MAAM,OAAO,SAAU,mBAAmB,iBAAiB,CAAC,cAuBlE,CAAA"}
|
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const constants_1 = require("../constants");
|
|
10
|
-
const __1 = __importDefault(require("../../"));
|
|
11
|
-
exports.command = 'validate <filePath>';
|
|
12
|
-
exports.desc = 'Validate a *.cddl file';
|
|
13
|
-
exports.builder = (yargs) => {
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { CLI_EPILOGUE } from '../constants.js';
|
|
4
|
+
import { ParseTargets } from '../../constants.js';
|
|
5
|
+
import CDDL from '../../index.js';
|
|
6
|
+
export const command = 'validate <filePath>';
|
|
7
|
+
export const desc = 'Validate a *.cddl file';
|
|
8
|
+
export const builder = (yargs) => {
|
|
14
9
|
return yargs
|
|
15
|
-
.epilogue(
|
|
10
|
+
.epilogue(CLI_EPILOGUE)
|
|
16
11
|
.help();
|
|
17
12
|
};
|
|
18
|
-
|
|
13
|
+
export const handler = (argv) => {
|
|
19
14
|
const filePath = argv.filePath.startsWith('/')
|
|
20
15
|
? argv.filePath
|
|
21
|
-
:
|
|
22
|
-
if (!
|
|
16
|
+
: path.resolve(process.cwd(), argv.filePath);
|
|
17
|
+
if (!fs.existsSync(filePath)) {
|
|
23
18
|
console.error(`Couldn't find CDDL file at ${filePath}`);
|
|
24
19
|
return process.exit(1);
|
|
25
20
|
}
|
|
26
21
|
try {
|
|
27
|
-
|
|
22
|
+
CDDL.parse(filePath, { target: ParseTargets.AST });
|
|
28
23
|
/**
|
|
29
24
|
* ToDo check for
|
|
30
25
|
* - missing group declarations
|
|
@@ -32,7 +27,7 @@ exports.handler = (argv) => {
|
|
|
32
27
|
console.log('✅ Valid CDDL file!');
|
|
33
28
|
}
|
|
34
29
|
catch (err) {
|
|
35
|
-
console.error(`⚠️ Invalid CDDL file (${filePath})\n\
|
|
30
|
+
console.error(`⚠️ Invalid CDDL file (${filePath})\n\n${err.message}`);
|
|
36
31
|
process.exit(1);
|
|
37
32
|
}
|
|
38
33
|
};
|
package/build/cli/constants.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const CLI_EPILOGUE = "Copyright
|
|
1
|
+
export declare const CLI_EPILOGUE = "Copyright 2023 - Christian Bromann";
|
|
2
2
|
//# sourceMappingURL=constants.d.ts.map
|
package/build/cli/constants.js
CHANGED
package/build/cli/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export default function (): {
|
|
1
|
+
export default function (): Promise<{
|
|
2
2
|
[x: string]: unknown;
|
|
3
|
-
_: string[];
|
|
3
|
+
_: (string | number)[];
|
|
4
4
|
$0: string;
|
|
5
|
-
}
|
|
5
|
+
} | {
|
|
6
|
+
[x: string]: unknown;
|
|
7
|
+
_: (string | number)[];
|
|
8
|
+
$0: string;
|
|
9
|
+
}>;
|
|
6
10
|
//# sourceMappingURL=index.d.ts.map
|
package/build/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAUC"}
|
package/build/cli/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.commandDir('commands')
|
|
1
|
+
import yargs from 'yargs/yargs';
|
|
2
|
+
import { hideBin } from 'yargs/helpers';
|
|
3
|
+
import * as replCommand from './commands/repl.js';
|
|
4
|
+
import * as validateCommand from './commands/validate.js';
|
|
5
|
+
import { CLI_EPILOGUE } from './constants.js';
|
|
6
|
+
export default async function () {
|
|
7
|
+
const argv = yargs(hideBin(process.argv))
|
|
8
|
+
.command(replCommand)
|
|
9
|
+
.command(validateCommand)
|
|
11
10
|
.example('$0 repl', 'Start CDDL repl')
|
|
12
|
-
.epilogue(
|
|
11
|
+
.epilogue(CLI_EPILOGUE)
|
|
12
|
+
.demandCommand()
|
|
13
|
+
.help();
|
|
13
14
|
return argv.argv;
|
|
14
15
|
}
|
|
15
|
-
exports.default = default_1;
|
package/build/constants.d.ts
CHANGED
|
@@ -5,4 +5,8 @@ export declare const BOOLEAN_LITERALS: string[];
|
|
|
5
5
|
* https://tools.ietf.org/html/draft-ietf-cbor-cddl-08#appendix-D
|
|
6
6
|
*/
|
|
7
7
|
export declare const PREDEFINED_IDENTIFIER: string[];
|
|
8
|
+
export declare enum ParseTargets {
|
|
9
|
+
AST = "ast",
|
|
10
|
+
TS = "ts"
|
|
11
|
+
}
|
|
8
12
|
//# sourceMappingURL=constants.d.ts.map
|
package/build/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
+
{"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;AAED,oBAAY,YAAY;IACpB,GAAG,QAAQ;IACX,EAAE,OAAO;CACZ"}
|
package/build/constants.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.PREDEFINED_IDENTIFIER = exports.BOOLEAN_LITERALS = exports.WHITESPACE_CHARACTERS = void 0;
|
|
4
|
-
exports.WHITESPACE_CHARACTERS = [' ', '\t', '\n', '\r'];
|
|
5
|
-
exports.BOOLEAN_LITERALS = ['true', 'false'];
|
|
1
|
+
export const WHITESPACE_CHARACTERS = [' ', '\t', '\n', '\r'];
|
|
2
|
+
export const BOOLEAN_LITERALS = ['true', 'false'];
|
|
6
3
|
/**
|
|
7
4
|
* as defined in Appendix D
|
|
8
5
|
* https://tools.ietf.org/html/draft-ietf-cbor-cddl-08#appendix-D
|
|
9
6
|
*/
|
|
10
|
-
|
|
7
|
+
export const PREDEFINED_IDENTIFIER = [
|
|
11
8
|
'any', 'uint', 'nint', 'int', 'bstr', 'bytes', 'tstr', 'text',
|
|
12
9
|
'tdate', 'time', 'number', 'biguint', 'bignint', 'bigint',
|
|
13
10
|
'integer', 'unsigned', 'decfrac', 'bigfloat', 'eb64url',
|
|
@@ -16,3 +13,8 @@ exports.PREDEFINED_IDENTIFIER = [
|
|
|
16
13
|
'float32', 'float64', 'float16-32', 'float32-64', 'float',
|
|
17
14
|
'false', 'true', 'bool', 'nil', 'null', 'undefined'
|
|
18
15
|
];
|
|
16
|
+
export var ParseTargets;
|
|
17
|
+
(function (ParseTargets) {
|
|
18
|
+
ParseTargets["AST"] = "ast";
|
|
19
|
+
ParseTargets["TS"] = "ts";
|
|
20
|
+
})(ParseTargets || (ParseTargets = {}));
|
package/build/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import Lexer from './lexer';
|
|
2
|
-
import Parser from './parser';
|
|
1
|
+
import Lexer from './lexer.js';
|
|
2
|
+
import Parser from './parser.js';
|
|
3
|
+
import { ParseTargets } from './constants.js';
|
|
4
|
+
import type { ParseOptions } from './types.js';
|
|
3
5
|
declare const _default: {
|
|
4
|
-
parse: (filePath: string) => import("./ast").Assignment[];
|
|
6
|
+
parse: (filePath: string, opts: ParseOptions) => string | import("./ast.js").Assignment[];
|
|
5
7
|
};
|
|
6
8
|
export default _default;
|
|
7
|
-
export { Lexer, Parser };
|
|
9
|
+
export { Lexer, Parser, ParseTargets };
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,MAAM,MAAM,aAAa,CAAA;AAGhC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;;sBAGxB,MAAM,QAAQ,YAAY;;AADhD,wBAcC;AAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const parser = new parser_1.default(l);
|
|
17
|
-
return parser.parse();
|
|
1
|
+
import Lexer from './lexer.js';
|
|
2
|
+
import Parser from './parser.js';
|
|
3
|
+
import { transform as transformTS } from './transform/ts.js';
|
|
4
|
+
import { ParseTargets } from './constants.js';
|
|
5
|
+
export default {
|
|
6
|
+
parse: (filePath, opts) => {
|
|
7
|
+
const parser = new Parser(filePath);
|
|
8
|
+
const ast = parser.parse();
|
|
9
|
+
if (opts.target === ParseTargets.AST) {
|
|
10
|
+
return ast;
|
|
11
|
+
}
|
|
12
|
+
if (opts.target === ParseTargets.TS) {
|
|
13
|
+
return transformTS(ast);
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`Unsupported parse target: "${opts.target || 'undefined'}"`);
|
|
18
16
|
}
|
|
19
17
|
};
|
|
18
|
+
export { Lexer, Parser, ParseTargets };
|
package/build/lexer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Token } from './tokens';
|
|
1
|
+
import { Token } from './tokens.js';
|
|
2
2
|
export default class Lexer {
|
|
3
3
|
input: string;
|
|
4
4
|
position: number;
|
|
@@ -6,6 +6,12 @@ export default class Lexer {
|
|
|
6
6
|
ch: number;
|
|
7
7
|
constructor(source: string);
|
|
8
8
|
private readChar;
|
|
9
|
+
getLocation(): {
|
|
10
|
+
line: number;
|
|
11
|
+
position: number;
|
|
12
|
+
};
|
|
13
|
+
getLine(lineNumber: number): string;
|
|
14
|
+
getLocationInfo(): string;
|
|
9
15
|
nextToken(): Token;
|
|
10
16
|
private readIdentifier;
|
|
11
17
|
private readComment;
|
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,
|
|
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;;;;IAqBX,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;IAiCzB,OAAO,CAAC,cAAc;CAKzB"}
|