@sdkgen/parser 0.0.0-dev.20231002144112 → 0.0.0-dev.20231002175619

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 (100) hide show
  1. package/dist/ast.js +298 -0
  2. package/dist/compatibility/index.js +206 -0
  3. package/dist/helpers.js +20 -0
  4. package/dist/index.js +9 -0
  5. package/dist/json.js +225 -0
  6. package/dist/lexer.js +283 -0
  7. package/dist/parser.js +419 -0
  8. package/dist/restparser.js +59 -0
  9. package/dist/semantic/01_check_multiple_declaration.js +19 -0
  10. package/dist/semantic/02_give_struct_and_enum_names.js +58 -0
  11. package/dist/semantic/03_match_type_definitions.js +15 -0
  12. package/dist/semantic/04_check_dont_return_secret.js +39 -0
  13. package/dist/semantic/05_expand_spreads.js +57 -0
  14. package/dist/semantic/06_check_empty_struct_or_enum.js +18 -0
  15. package/dist/semantic/07_validate_recursive_types.js +46 -0
  16. package/dist/semantic/08_collect_struct_and_enum_types.js +22 -0
  17. package/dist/semantic/09_validate_annotations.js +122 -0
  18. package/dist/semantic/10_check_duplicate_members_on_enum.js +13 -0
  19. package/dist/semantic/analyser.js +27 -0
  20. package/dist/semantic/transformer.js +46 -0
  21. package/dist/semantic/visitor.js +61 -0
  22. package/dist/token.js +93 -0
  23. package/dist/utils.js +25 -0
  24. package/package.json +10 -3
  25. package/.eslintrc.json +0 -3
  26. package/.prettierrc +0 -12
  27. package/dist/spec/lexer.spec.d.ts +0 -1
  28. package/dist/spec/lexer.spec.js +0 -152
  29. package/dist/spec/parser.spec.d.ts +0 -1
  30. package/dist/spec/parser.spec.js +0 -967
  31. package/dist/src/ast.js +0 -355
  32. package/dist/src/compatibility/index.js +0 -211
  33. package/dist/src/helpers.js +0 -23
  34. package/dist/src/index.js +0 -29
  35. package/dist/src/json.js +0 -234
  36. package/dist/src/lexer.js +0 -287
  37. package/dist/src/parser.js +0 -423
  38. package/dist/src/restparser.js +0 -65
  39. package/dist/src/semantic/01_check_multiple_declaration.js +0 -22
  40. package/dist/src/semantic/02_give_struct_and_enum_names.js +0 -61
  41. package/dist/src/semantic/03_match_type_definitions.js +0 -18
  42. package/dist/src/semantic/04_check_dont_return_secret.js +0 -42
  43. package/dist/src/semantic/05_expand_spreads.js +0 -60
  44. package/dist/src/semantic/06_check_empty_struct_or_enum.js +0 -21
  45. package/dist/src/semantic/07_validate_recursive_types.js +0 -49
  46. package/dist/src/semantic/08_collect_struct_and_enum_types.js +0 -25
  47. package/dist/src/semantic/09_validate_annotations.js +0 -125
  48. package/dist/src/semantic/10_check_duplicate_members_on_enum.js +0 -16
  49. package/dist/src/semantic/analyser.js +0 -30
  50. package/dist/src/semantic/transformer.js +0 -50
  51. package/dist/src/semantic/visitor.js +0 -65
  52. package/dist/src/token.js +0 -119
  53. package/dist/src/utils.js +0 -27
  54. package/dist/tsconfig.tsbuildinfo +0 -1
  55. package/src/ast.ts +0 -273
  56. package/src/compatibility/index.ts +0 -273
  57. package/src/helpers.ts +0 -28
  58. package/src/index.ts +0 -8
  59. package/src/json.ts +0 -350
  60. package/src/lexer.ts +0 -343
  61. package/src/parser.ts +0 -604
  62. package/src/restparser.ts +0 -81
  63. package/src/semantic/01_check_multiple_declaration.ts +0 -21
  64. package/src/semantic/02_give_struct_and_enum_names.ts +0 -57
  65. package/src/semantic/03_match_type_definitions.ts +0 -19
  66. package/src/semantic/04_check_dont_return_secret.ts +0 -40
  67. package/src/semantic/05_expand_spreads.ts +0 -67
  68. package/src/semantic/06_check_empty_struct_or_enum.ts +0 -21
  69. package/src/semantic/07_validate_recursive_types.ts +0 -47
  70. package/src/semantic/08_collect_struct_and_enum_types.ts +0 -23
  71. package/src/semantic/09_validate_annotations.ts +0 -158
  72. package/src/semantic/10_check_duplicate_members_on_enum.ts +0 -15
  73. package/src/semantic/analyser.ts +0 -29
  74. package/src/semantic/transformer.ts +0 -41
  75. package/src/semantic/visitor.ts +0 -60
  76. package/src/token.ts +0 -92
  77. package/src/utils.ts +0 -63
  78. /package/dist/{src/ast.d.ts → ast.d.ts} +0 -0
  79. /package/dist/{src/compatibility → compatibility}/index.d.ts +0 -0
  80. /package/dist/{src/helpers.d.ts → helpers.d.ts} +0 -0
  81. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  82. /package/dist/{src/json.d.ts → json.d.ts} +0 -0
  83. /package/dist/{src/lexer.d.ts → lexer.d.ts} +0 -0
  84. /package/dist/{src/parser.d.ts → parser.d.ts} +0 -0
  85. /package/dist/{src/restparser.d.ts → restparser.d.ts} +0 -0
  86. /package/dist/{src/semantic → semantic}/01_check_multiple_declaration.d.ts +0 -0
  87. /package/dist/{src/semantic → semantic}/02_give_struct_and_enum_names.d.ts +0 -0
  88. /package/dist/{src/semantic → semantic}/03_match_type_definitions.d.ts +0 -0
  89. /package/dist/{src/semantic → semantic}/04_check_dont_return_secret.d.ts +0 -0
  90. /package/dist/{src/semantic → semantic}/05_expand_spreads.d.ts +0 -0
  91. /package/dist/{src/semantic → semantic}/06_check_empty_struct_or_enum.d.ts +0 -0
  92. /package/dist/{src/semantic → semantic}/07_validate_recursive_types.d.ts +0 -0
  93. /package/dist/{src/semantic → semantic}/08_collect_struct_and_enum_types.d.ts +0 -0
  94. /package/dist/{src/semantic → semantic}/09_validate_annotations.d.ts +0 -0
  95. /package/dist/{src/semantic → semantic}/10_check_duplicate_members_on_enum.d.ts +0 -0
  96. /package/dist/{src/semantic → semantic}/analyser.d.ts +0 -0
  97. /package/dist/{src/semantic → semantic}/transformer.d.ts +0 -0
  98. /package/dist/{src/semantic → semantic}/visitor.d.ts +0 -0
  99. /package/dist/{src/token.d.ts → token.d.ts} +0 -0
  100. /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
package/package.json CHANGED
@@ -1,8 +1,15 @@
1
1
  {
2
2
  "name": "@sdkgen/parser",
3
- "version": "0.0.0-dev.20231002144112",
3
+ "version": "0.0.0-dev.20231002175619",
4
4
  "description": "",
5
- "main": "src/index.ts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "directories": {
8
+ "lib": "dist"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
6
13
  "scripts": {
7
14
  "test": "jest --passWithNoTests",
8
15
  "eslint:fix": "eslint --fix '{src,spec}/**/*.ts'",
@@ -47,5 +54,5 @@
47
54
  "/node_modules/"
48
55
  ]
49
56
  },
50
- "gitHead": "85c11927f0704a14da62d908005ec99c2e3b199f"
57
+ "gitHead": "611061fbde3388caebebe076bf41ad78518cbbb0"
51
58
  }
package/.eslintrc.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["@cubos"]
3
- }
package/.prettierrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "arrowParens": "avoid",
3
- "bracketSpacing": true,
4
- "endOfLine": "lf",
5
- "parser": "typescript",
6
- "printWidth": 150,
7
- "semi": true,
8
- "singleQuote": false,
9
- "tabWidth": 2,
10
- "trailingComma": "all",
11
- "useTabs": false
12
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,152 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const lexer_1 = require("../src/lexer");
4
- const token_1 = require("../src/token");
5
- function itLexes(source, expectedTokens) {
6
- test(`lexes ${JSON.stringify(source)} as [${expectedTokens.join(", ")}]`, () => {
7
- const lexer = new lexer_1.Lexer(source);
8
- let tokens = [];
9
- for (;;) {
10
- const token = lexer.nextToken();
11
- if (!token) {
12
- break;
13
- }
14
- tokens.push(token);
15
- }
16
- tokens = tokens.map((token, i) => (expectedTokens[i] instanceof token_1.IdentifierToken ? token.maybeAsIdentifier() : token));
17
- expect(tokens.join(", ")).toEqual(expectedTokens.join(", "));
18
- });
19
- }
20
- function itDoesntLex(source, message) {
21
- test(`doesn't lex ${JSON.stringify(source)}`, () => {
22
- const lexer = new lexer_1.Lexer(source);
23
- expect(() => {
24
- while (lexer.nextToken()) {
25
- //
26
- }
27
- }).toThrowError(message);
28
- });
29
- }
30
- describe(lexer_1.Lexer, () => {
31
- itLexes("", []);
32
- itLexes("type", [new token_1.TypeKeywordToken()]);
33
- itDoesntLex("23", 'Unexpected character "2" at -:1:1');
34
- itDoesntLex("2a", 'Unexpected character "2" at -:1:1');
35
- itLexes("type2", [new token_1.IdentifierToken("type2")]);
36
- itLexes("aaa", [new token_1.IdentifierToken("aaa")]);
37
- itLexes("...aaa", [new token_1.SpreadSymbolToken(), new token_1.IdentifierToken("aaa")]);
38
- itLexes("a b c", [new token_1.IdentifierToken("a"), new token_1.IdentifierToken("b"), new token_1.IdentifierToken("c")]);
39
- itLexes("aa_bb", [new token_1.IdentifierToken("aa_bb")]);
40
- itLexes("type type", [new token_1.TypeKeywordToken(), new token_1.TypeKeywordToken()]);
41
- itLexes("enum", [new token_1.EnumKeywordToken()]);
42
- itLexes("error", [new token_1.ErrorKeywordToken()]);
43
- itLexes("import", [new token_1.ImportKeywordToken()]);
44
- itLexes("Get", [new token_1.IdentifierToken("Get")]);
45
- itLexes("fn", [new token_1.FnKeywordToken()]);
46
- itLexes("enuma", [new token_1.IdentifierToken("enuma")]);
47
- itLexes("errorh", [new token_1.IdentifierToken("errorh")]);
48
- for (const kw of ["enum", "type", "error", "import", "get", "function", "fn", "true", "false"]) {
49
- itLexes(kw, [new token_1.IdentifierToken(kw)]);
50
- }
51
- for (const primitive of lexer_1.Lexer.PRIMITIVES) {
52
- itLexes(primitive, [new token_1.PrimitiveTypeToken(primitive)]);
53
- itLexes(primitive, [new token_1.IdentifierToken(primitive)]);
54
- itLexes(`${primitive}a`, [new token_1.IdentifierToken(`${primitive}a`)]);
55
- }
56
- itLexes("err", [new token_1.IdentifierToken("err")]);
57
- itLexes("{", [new token_1.CurlyOpenSymbolToken()]);
58
- itLexes("{{", [new token_1.CurlyOpenSymbolToken(), new token_1.CurlyOpenSymbolToken()]);
59
- itLexes("}{", [new token_1.CurlyCloseSymbolToken(), new token_1.CurlyOpenSymbolToken()]);
60
- itLexes(" } { ", [new token_1.CurlyCloseSymbolToken(), new token_1.CurlyOpenSymbolToken()]);
61
- itLexes("({!:?,=})", [
62
- new token_1.ParensOpenSymbolToken(),
63
- new token_1.CurlyOpenSymbolToken(),
64
- new token_1.ExclamationMarkSymbolToken(),
65
- new token_1.ColonSymbolToken(),
66
- new token_1.OptionalSymbolToken(),
67
- new token_1.CommaSymbolToken(),
68
- new token_1.EqualSymbolToken(),
69
- new token_1.CurlyCloseSymbolToken(),
70
- new token_1.ParensCloseSymbolToken(),
71
- ]);
72
- itLexes(" [][] ", [new token_1.ArraySymbolToken(), new token_1.ArraySymbolToken()]);
73
- itLexes("nice[]", [new token_1.IdentifierToken("nice"), new token_1.ArraySymbolToken()]);
74
- itLexes("nice\n[]", [new token_1.IdentifierToken("nice"), new token_1.ArraySymbolToken()]);
75
- itDoesntLex("[", "Unexpected end of file");
76
- itLexes("type Str string", [new token_1.TypeKeywordToken(), new token_1.IdentifierToken("Str"), new token_1.PrimitiveTypeToken("string")]);
77
- itLexes('"ab"', [new token_1.StringLiteralToken("ab")]);
78
- itLexes('""', [new token_1.StringLiteralToken("")]);
79
- itLexes('"aa\\nbb"', [new token_1.StringLiteralToken("aa\nbb")]);
80
- itLexes('"aa\\bb"', [new token_1.StringLiteralToken("aabb")]);
81
- itLexes('"\'"', [new token_1.StringLiteralToken("'")]);
82
- itLexes('"\\n\\t\\""', [new token_1.StringLiteralToken('\n\t"')]);
83
- itLexes('"/* */"', [new token_1.StringLiteralToken("/* */")]);
84
- itLexes("//hmmm", []);
85
- itLexes("x//hmmm", [new token_1.IdentifierToken("x")]);
86
- itLexes("a//hmmm\nb", [new token_1.IdentifierToken("a"), new token_1.IdentifierToken("b")]);
87
- itLexes("a // hmmm \n b", [new token_1.IdentifierToken("a"), new token_1.IdentifierToken("b")]);
88
- itLexes("// héýça\n z", [new token_1.IdentifierToken("z")]);
89
- itDoesntLex("2", 'Unexpected character "2" at -:1:1');
90
- itDoesntLex("\n2", 'Unexpected character "2" at -:2:1');
91
- itDoesntLex("//\n2", 'Unexpected character "2" at -:2:1');
92
- itDoesntLex("//\n 2", 'Unexpected character "2" at -:2:2');
93
- itDoesntLex("//x\n2", 'Unexpected character "2" at -:2:1');
94
- itDoesntLex("//x\n 2", 'Unexpected character "2" at -:2:2');
95
- itDoesntLex("/*\n*/3", 'Unexpected character "3" at -:2:3');
96
- itDoesntLex("/*\n\n\n\n*/ 2", 'Unexpected character "2" at -:5:4');
97
- itDoesntLex("/*a*/\n2", 'Unexpected character "2" at -:2:1');
98
- itDoesntLex("/*a*/\n 2", 'Unexpected character "2" at -:2:2');
99
- itDoesntLex("/*\n", "Unexpected end of file");
100
- itDoesntLex("/* *", "Unexpected end of file");
101
- itDoesntLex("/* \tae\n\n", "Unexpected end of file");
102
- itDoesntLex("/*", "Unexpected end of file");
103
- itDoesntLex("/*", "Unexpected end of file");
104
- itDoesntLex("/* dsvibwi", "Unexpected end of file");
105
- itDoesntLex("/* cdibweic *", "Unexpected end of file");
106
- itDoesntLex("/* cdibweic *a", "Unexpected end of file");
107
- itDoesntLex("/* * /", "Unexpected end of file");
108
- itDoesntLex("/* * /", "Unexpected end of file");
109
- itDoesntLex("/* * /", "Unexpected end of file");
110
- itDoesntLex("/*/", "Unexpected end of file");
111
- itDoesntLex("/* /", "Unexpected end of file");
112
- itDoesntLex("/* * /", "Unexpected end of file");
113
- itDoesntLex("/* * * * /", "Unexpected end of file");
114
- itDoesntLex("/* *a/", "Unexpected end of file");
115
- itLexes("/*\n*/", []);
116
- itLexes("/* * * * * */", []);
117
- itLexes("/* * ***_ */", []);
118
- itLexes("/**/", []);
119
- itLexes("/***/", []);
120
- itLexes("/****/", []);
121
- itLexes("/*****/", []);
122
- itLexes("/******/", []);
123
- itLexes("/*******/", []);
124
- itLexes("/********/", []);
125
- itLexes("/****aas ********/", []);
126
- itLexes("/*******a ********/", []);
127
- itLexes("/**********/", []);
128
- itLexes("/************/", []);
129
- itLexes("/*************/", []);
130
- itLexes("/**************/", []);
131
- itLexes("/***************/", []);
132
- itLexes("/*a */", []);
133
- itLexes("/*a \n*/", []);
134
- itLexes("/*a \n\n\n\n\n*/", []);
135
- itLexes("/**a*/", []);
136
- itLexes("/*a**/", []);
137
- itLexes("/* */", []);
138
- itLexes("/*a*/b/*c*/", [new token_1.IdentifierToken("b")]);
139
- itLexes("/* đðđ\n */u", [new token_1.IdentifierToken("u")]);
140
- itLexes("c/* a*/", [new token_1.IdentifierToken("c")]);
141
- itLexes("/* bce */a", [new token_1.IdentifierToken("a")]);
142
- itLexes("b/* baed */c", [new token_1.IdentifierToken("b"), new token_1.IdentifierToken("c")]);
143
- itLexes("/* \n\nb */a", [new token_1.IdentifierToken("a")]);
144
- itLexes("/* */a", [new token_1.IdentifierToken("a")]);
145
- itLexes("@aa bb cc", [new token_1.AnnotationToken("aa bb cc")]);
146
- itLexes(" @ ", [new token_1.AnnotationToken("")]);
147
- itLexes("@", [new token_1.AnnotationToken("")]);
148
- itLexes(" @ aa bb cc ", [new token_1.AnnotationToken("aa bb cc")]);
149
- itLexes(" @ aa bb \n cc ", [new token_1.AnnotationToken("aa bb"), new token_1.IdentifierToken("cc")]);
150
- itLexes(" @ aa bb \\ \n cc ", [new token_1.AnnotationToken("aa bb cc")]);
151
- itLexes("@\\\n cc ", [new token_1.AnnotationToken("cc")]);
152
- });
@@ -1 +0,0 @@
1
- export {};