cddl 0.15.0 → 0.17.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 (46) hide show
  1. package/LICENSE +1 -1
  2. package/build/parser.d.ts.map +1 -1
  3. package/build/parser.js +26 -2
  4. package/package.json +5 -1
  5. package/.release-it.ts +0 -10
  6. package/docs/README.md +0 -47
  7. package/docs/arrays.md +0 -356
  8. package/docs/ast-structure.md +0 -166
  9. package/docs/basic-types.md +0 -243
  10. package/docs/cddl-cheatsheet.md +0 -231
  11. package/docs/comments.md +0 -307
  12. package/docs/groups.md +0 -351
  13. package/docs/operators.md +0 -466
  14. package/docs/properties.md +0 -334
  15. package/docs/ranges.md +0 -339
  16. package/docs/references.md +0 -340
  17. package/docs/variables.md +0 -335
  18. package/src/ast.ts +0 -180
  19. package/src/cli/commands/repl.ts +0 -33
  20. package/src/cli/commands/validate.ts +0 -44
  21. package/src/cli/constants.ts +0 -1
  22. package/src/cli/index.ts +0 -18
  23. package/src/constants.ts +0 -16
  24. package/src/index.ts +0 -12
  25. package/src/lexer.ts +0 -238
  26. package/src/parser.ts +0 -967
  27. package/src/tokens.ts +0 -50
  28. package/src/utils.ts +0 -96
  29. package/tests/__snapshots__/complex_types.test.ts.snap +0 -80
  30. package/tests/__snapshots__/examples.test.ts.snap +0 -1077
  31. package/tests/__snapshots__/group-choices.test.ts.snap +0 -278
  32. package/tests/__snapshots__/parser.test.ts.snap +0 -3045
  33. package/tests/__snapshots__/webdriver-local.test.ts.snap +0 -11192
  34. package/tests/__snapshots__/webdriver-remote.test.ts.snap +0 -16350
  35. package/tests/commands/repl.test.ts +0 -52
  36. package/tests/commands/validate.test.ts +0 -66
  37. package/tests/complex_types.test.ts +0 -18
  38. package/tests/examples.test.ts +0 -25
  39. package/tests/group-choices.test.ts +0 -103
  40. package/tests/lexer.test.ts +0 -63
  41. package/tests/module.test.ts +0 -21
  42. package/tests/parser.test.ts +0 -44
  43. package/tests/utils.test.ts +0 -211
  44. package/tests/webdriver-local.test.ts +0 -15
  45. package/tests/webdriver-remote.test.ts +0 -15
  46. package/tsconfig.json +0 -11
package/src/tokens.ts DELETED
@@ -1,50 +0,0 @@
1
- export type TokenType = string
2
-
3
- export type Token = {
4
- Type: TokenType
5
- Literal: string
6
- }
7
-
8
- export enum Tokens {
9
- ILLEGAL = 'ILLEGAL',
10
- EOF = 'EOF',
11
- NL = '\n',
12
- SPACE = ' ',
13
- UNDERSCORE = '_',
14
- DOLLAR = '$',
15
- ATSIGN = '@',
16
- CARET = '^',
17
- HASH = '#',
18
- TILDE = '~',
19
-
20
- // Identifiers + literals,
21
- IDENT = 'IDENT',
22
- INT = 'INT',
23
- COMMENT = 'COMMENT',
24
- STRING = 'STRING',
25
- NUMBER = 'NUMBER',
26
- FLOAT = 'FLOAT',
27
-
28
- // Operators,
29
- ASSIGN = '=',
30
- PLUS = '+',
31
- MINUS = '-',
32
- SLASH = '/',
33
- QUEST = '?',
34
- ASTERISK = '*',
35
-
36
- // Delimiters,
37
- COMMA = ',',
38
- DOT = '.',
39
- COLON = ':',
40
- SEMICOLON = ';',
41
- LPAREN = '(',
42
- RPAREN = ')',
43
- LBRACE = '{',
44
- RBRACE = '}',
45
- LBRACK = '[',
46
- RBRACK = ']',
47
- LT = '<',
48
- GT = '>',
49
- QUOT = '"'
50
- }
package/src/utils.ts DELETED
@@ -1,96 +0,0 @@
1
- import camelcase from 'camelcase'
2
-
3
- import type {
4
- Assignment,
5
- Array as CDDLArray,
6
- Group,
7
- NativeTypeWithOperator,
8
- Property,
9
- PropertyReference,
10
- Variable
11
- } from './ast.js'
12
-
13
- import { Tokens, Token } from './tokens.js'
14
-
15
- export function isLetter (ch: string): boolean {
16
- return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z'
17
- }
18
-
19
- export function isAlphabeticCharacter (ch: string): boolean {
20
- return isLetter(ch) || ch === Tokens.ATSIGN || ch === Tokens.UNDERSCORE || ch === Tokens.DOLLAR
21
- }
22
-
23
- export function isDigit (ch: string): boolean {
24
- return !isNaN(ch as unknown as number) && ch !== Tokens.NL && ch !== Tokens.SPACE
25
- }
26
-
27
- export function hasSpecialNumberCharacter (ch: number) {
28
- return (
29
- ch === Tokens.MINUS.charCodeAt(0) ||
30
- ch === Tokens.DOT.charCodeAt(0) ||
31
- ch === 'x'.charCodeAt(0) ||
32
- ch === 'b'.charCodeAt(0)
33
- )
34
- }
35
-
36
- export function parseNumberValue (token: Token): string | number {
37
- if (token.Type === Tokens.FLOAT) {
38
- return parseFloat(token.Literal)
39
- }
40
-
41
- if (
42
- token.Literal.includes('x') ||
43
- token.Literal.includes('b')
44
- ) {
45
- return token.Literal
46
- }
47
-
48
- return parseInt(token.Literal, 10)
49
- }
50
-
51
- export function pascalCase (name: string) {
52
- return camelcase(name, { pascalCase: true })
53
- }
54
-
55
- export function isVariable (assignment: Assignment): assignment is Variable {
56
- return assignment.Type === 'variable'
57
- }
58
-
59
- export function isGroup (t: any): t is Group {
60
- return t && t.Type === 'group'
61
- }
62
-
63
- export function isCDDLArray (t: any): t is CDDLArray {
64
- return t && t.Type === 'array'
65
- }
66
-
67
- export function isProperty (t: any): t is Property {
68
- return t && typeof t.Name === 'string' && typeof t.HasCut === 'boolean'
69
- }
70
-
71
- export function isUnNamedProperty (t: any): t is Property & { Name: '' } {
72
- return isProperty(t) && t.Name === ''
73
- }
74
-
75
- export function isNamedGroupReference (t: any): t is PropertyReference & { Value: string } {
76
- return isGroup(t) && isPropertyReference(t) && typeof t.Value === 'string'
77
- }
78
-
79
- export function isPropertyReference (t: any): t is PropertyReference {
80
- return t && typeof t === 'object' && 'Value' in t
81
- }
82
-
83
- export function isNativeTypeWithOperator (t: any): t is NativeTypeWithOperator {
84
- return t && typeof t.Type === 'object' && 'Operator' in t
85
- }
86
-
87
- export function isRange (t: any): boolean {
88
- return t && typeof t.Type === 'object' && (t.Type as any).Type === 'range'
89
- }
90
-
91
- export function isLiteralWithValue (t: any): t is {
92
- Type: 'literal'
93
- Value: unknown
94
- } {
95
- return t && t.Type === 'literal' && 'Value' in t
96
- }
@@ -1,80 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`complex types > can parse complex types correctly 1`] = `
4
- {
5
- "Comments": [],
6
- "IsChoiceAddition": false,
7
- "Name": "LocalValue",
8
- "PropertyType": [
9
- {
10
- "Type": "group",
11
- "Unwrapped": false,
12
- "Value": "ArrayLocalValue",
13
- },
14
- {
15
- "Comments": [],
16
- "IsChoiceAddition": false,
17
- "Name": "",
18
- "Properties": [
19
- {
20
- "Comments": [],
21
- "HasCut": false,
22
- "Name": "",
23
- "Occurrence": {
24
- "m": 1,
25
- "n": 1,
26
- },
27
- "Type": [
28
- {
29
- "Type": "group",
30
- "Unwrapped": false,
31
- "Value": "DateLocalValue",
32
- },
33
- ],
34
- },
35
- ],
36
- "Type": "group",
37
- },
38
- {
39
- "Type": "group",
40
- "Unwrapped": false,
41
- "Value": "MapLocalValue",
42
- },
43
- {
44
- "Type": "group",
45
- "Unwrapped": false,
46
- "Value": "ObjectLocalValue",
47
- },
48
- {
49
- "Comments": [],
50
- "IsChoiceAddition": false,
51
- "Name": "",
52
- "Properties": [
53
- {
54
- "Comments": [],
55
- "HasCut": false,
56
- "Name": "",
57
- "Occurrence": {
58
- "m": 1,
59
- "n": 1,
60
- },
61
- "Type": [
62
- {
63
- "Type": "group",
64
- "Unwrapped": false,
65
- "Value": "RegExpLocalValue",
66
- },
67
- ],
68
- },
69
- ],
70
- "Type": "group",
71
- },
72
- {
73
- "Type": "group",
74
- "Unwrapped": false,
75
- "Value": "SetLocalValue",
76
- },
77
- ],
78
- "Type": "variable",
79
- }
80
- `;