cddl 0.2.2 → 0.4.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 (45) hide show
  1. package/.nvmrc +1 -0
  2. package/README.md +5 -5
  3. package/bin/cddl.js +3 -1
  4. package/build/ast.d.ts +14 -14
  5. package/build/ast.d.ts.map +1 -1
  6. package/build/ast.js +2 -5
  7. package/build/cli/commands/repl.d.ts +3 -3
  8. package/build/cli/commands/repl.d.ts.map +1 -1
  9. package/build/cli/commands/repl.js +13 -20
  10. package/build/cli/commands/validate.d.ts +4 -4
  11. package/build/cli/commands/validate.d.ts.map +1 -1
  12. package/build/cli/commands/validate.js +14 -19
  13. package/build/cli/constants.d.ts +1 -1
  14. package/build/cli/constants.js +1 -4
  15. package/build/cli/index.d.ts +7 -3
  16. package/build/cli/index.d.ts.map +1 -1
  17. package/build/cli/index.js +12 -12
  18. package/build/constants.d.ts +4 -0
  19. package/build/constants.d.ts.map +1 -1
  20. package/build/constants.js +8 -6
  21. package/build/index.d.ts +6 -4
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +16 -17
  24. package/build/lexer.d.ts +7 -1
  25. package/build/lexer.d.ts.map +1 -1
  26. package/build/lexer.js +81 -50
  27. package/build/parser.d.ts +6 -4
  28. package/build/parser.d.ts.map +1 -1
  29. package/build/parser.js +148 -79
  30. package/build/tokens.d.ts +2 -2
  31. package/build/tokens.d.ts.map +1 -1
  32. package/build/tokens.js +2 -5
  33. package/build/transform/ts.d.ts +3 -0
  34. package/build/transform/ts.d.ts.map +1 -0
  35. package/build/transform/ts.js +113 -0
  36. package/build/types.d.ts +5 -0
  37. package/build/types.d.ts.map +1 -0
  38. package/build/types.js +1 -0
  39. package/build/utils.d.ts +1 -1
  40. package/build/utils.d.ts.map +1 -1
  41. package/build/utils.js +11 -18
  42. package/examples/webdriver/local.cddl +846 -0
  43. package/examples/webdriver/remote.cddl +830 -0
  44. package/package.json +30 -26
  45. 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 ![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:
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
- const CDDL = require('cddl').default
35
+ import { parse } from 'cddl'
36
36
 
37
- const ast = CDDL.parse('./spec.cddl')
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 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 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
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import run from '../build/cli/index.js'
4
+
3
5
  if (process.env.NODE_ENV == null) {
4
6
  process.env.NODE_ENV = 'test'
5
7
  }
6
8
 
7
- require('../build/cli').default()
9
+ run()
package/build/ast.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * }
9
9
  * ```
10
10
  */
11
- export declare type Group = {
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 declare type Array = {
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 declare type Tag = {
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 declare type Variable = {
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 declare type Comment = {
58
+ export type Comment = {
59
59
  Type: 'comment';
60
60
  Content: string;
61
61
  };
62
- export declare type Occurrence = {
62
+ export type Occurrence = {
63
63
  n: number;
64
64
  m: number;
65
65
  };
66
- export declare type Property = {
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 declare type RangePropertyReference = number | string;
113
- export declare type Range = {
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 declare type PropertyReferenceType = 'literal' | 'group' | 'group_array' | 'range' | 'tag';
119
- export declare type PropertyReference = {
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 declare type Assignment = Group | Array | Variable | Comment;
125
- export declare type PropertyType = Assignment | Array | PropertyReference | string;
126
- export declare type PropertyName = string;
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
@@ -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,CAAA;IACZ,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,CAAC,QAAQ,GAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;CACvC,CAAA;AAED;;;;;;;GAOG;AACH,oBAAY,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,oBAAY,GAAG,GAAG;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAA;AAED;;;;;GAKG;AACH,oBAAY,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;;;;;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{ 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 = exports.Type || (exports.Type = {}));
36
+ })(Type || (Type = {}));
@@ -1,7 +1,7 @@
1
- import yargs from 'yargs';
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: yargs.Argv<{}>) => yargs.Argv<{}>;
5
- export declare const handler: (argv: yargs.Arguments) => void;
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;AAMzB,eAAO,MAAM,OAAO,SAAS,CAAA;AAC7B,eAAO,MAAM,IAAI,kBAAkB,CAAA;AACnC,eAAO,MAAM,OAAO,2CAInB,CAAA;AAED,eAAO,MAAM,OAAO,SAAU,MAAM,SAAS,SAK5C,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
+ {"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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.evaluate = exports.handler = exports.builder = exports.desc = exports.command = void 0;
7
- const repl_1 = __importDefault(require("repl"));
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(constants_1.CLI_EPILOGUE)
9
+ .epilogue(CLI_EPILOGUE)
16
10
  .help();
17
11
  };
18
- exports.handler = (argv) => {
19
- const r = repl_1.default.start({
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 lexer_1.default(evalCmd);
29
- for (let tok = l.nextToken(); tok.Type !== tokens_1.Tokens.EOF; tok = l.nextToken()) {
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 yargs from 'yargs';
2
- interface ValidateArguments extends yargs.Arguments {
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: yargs.Argv<{}>) => yargs.Argv<{}>;
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;AAKzB,UAAU,iBAAkB,SAAQ,KAAK,CAAC,SAAS;IAC/C,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,eAAO,MAAM,OAAO,wBAAwB,CAAA;AAC5C,eAAO,MAAM,IAAI,2BAA2B,CAAA;AAC5C,eAAO,MAAM,OAAO,2CAInB,CAAA;AAED,eAAO,MAAM,OAAO,SAAU,iBAAiB,cAuB9C,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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
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(constants_1.CLI_EPILOGUE)
10
+ .epilogue(CLI_EPILOGUE)
16
11
  .help();
17
12
  };
18
- exports.handler = (argv) => {
13
+ export const handler = (argv) => {
19
14
  const filePath = argv.filePath.startsWith('/')
20
15
  ? argv.filePath
21
- : path_1.default.resolve(process.cwd(), argv.filePath);
22
- if (!fs_1.default.existsSync(filePath)) {
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
- __1.default.parse(filePath);
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\t> ${err.message}`);
30
+ console.error(`⚠️ Invalid CDDL file (${filePath})\n\n${err.message}`);
36
31
  process.exit(1);
37
32
  }
38
33
  };
@@ -1,2 +1,2 @@
1
- export declare const CLI_EPILOGUE = "Copyright 2020 - Christian Bromann";
1
+ export declare const CLI_EPILOGUE = "Copyright 2023 - Christian Bromann";
2
2
  //# sourceMappingURL=constants.d.ts.map
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CLI_EPILOGUE = void 0;
4
- exports.CLI_EPILOGUE = `Copyright 2020 - Christian Bromann`;
1
+ export const CLI_EPILOGUE = `Copyright 2023 - Christian Bromann`;
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO;;;;EAOb"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAUC"}
@@ -1,15 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const yargs_1 = __importDefault(require("yargs"));
7
- const constants_1 = require("./constants");
8
- function default_1() {
9
- const argv = yargs_1.default
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(constants_1.CLI_EPILOGUE);
11
+ .epilogue(CLI_EPILOGUE)
12
+ .demandCommand()
13
+ .help();
13
14
  return argv.argv;
14
15
  }
15
- exports.default = default_1;
@@ -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
@@ -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"}
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- exports.PREDEFINED_IDENTIFIER = [
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,MAAM,MAAM,UAAU,CAAA;;sBAGP,MAAM;;AAD5B,wBAOC;AAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Parser = exports.Lexer = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const lexer_1 = __importDefault(require("./lexer"));
9
- exports.Lexer = lexer_1.default;
10
- const parser_1 = __importDefault(require("./parser"));
11
- exports.Parser = parser_1.default;
12
- exports.default = {
13
- parse: (filePath) => {
14
- const input = fs_1.default.readFileSync(filePath, 'utf-8');
15
- const l = new lexer_1.default(input);
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;
@@ -1 +1 @@
1
- {"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../src/lexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,UAAU,CAAC;AAIzC,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,SAAS,IAAK,KAAK;IA0FnB,OAAO,CAAC,cAAc;IA2BtB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,iBAAiB;IAiCzB,OAAO,CAAC,cAAc;CAKzB"}
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"}