@sdkgen/parser 0.0.0-dev.20231008144512 → 0.0.0-dev.20231221180829

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 (77) hide show
  1. package/.eslintrc.json +3 -0
  2. package/.prettierrc +12 -0
  3. package/dist/spec/lexer.spec.d.ts +1 -0
  4. package/dist/spec/lexer.spec.js +152 -0
  5. package/dist/spec/parser.spec.d.ts +1 -0
  6. package/dist/spec/parser.spec.js +967 -0
  7. package/dist/src/ast.js +355 -0
  8. package/dist/src/compatibility/index.js +211 -0
  9. package/dist/src/helpers.js +23 -0
  10. package/dist/src/index.js +29 -0
  11. package/dist/src/json.js +234 -0
  12. package/dist/src/lexer.js +287 -0
  13. package/dist/src/parser.js +423 -0
  14. package/dist/src/restparser.js +65 -0
  15. package/dist/src/semantic/01_check_multiple_declaration.js +22 -0
  16. package/dist/src/semantic/02_give_struct_and_enum_names.js +61 -0
  17. package/dist/src/semantic/03_match_type_definitions.js +18 -0
  18. package/dist/src/semantic/04_check_dont_return_secret.js +42 -0
  19. package/dist/src/semantic/05_expand_spreads.js +60 -0
  20. package/dist/src/semantic/06_check_empty_struct_or_enum.js +21 -0
  21. package/dist/src/semantic/07_validate_recursive_types.js +49 -0
  22. package/dist/src/semantic/08_collect_struct_and_enum_types.js +25 -0
  23. package/dist/src/semantic/09_validate_annotations.js +125 -0
  24. package/dist/src/semantic/10_check_duplicate_members_on_enum.js +16 -0
  25. package/dist/src/semantic/analyser.js +30 -0
  26. package/dist/src/semantic/transformer.js +50 -0
  27. package/dist/src/semantic/visitor.js +65 -0
  28. package/dist/src/token.js +119 -0
  29. package/dist/src/utils.js +27 -0
  30. package/dist/tsconfig.tsbuildinfo +1 -0
  31. package/package.json +8 -24
  32. package/dist/ast.js +0 -298
  33. package/dist/compatibility/index.js +0 -206
  34. package/dist/helpers.js +0 -20
  35. package/dist/index.js +0 -9
  36. package/dist/json.js +0 -225
  37. package/dist/lexer.js +0 -283
  38. package/dist/parser.js +0 -419
  39. package/dist/restparser.js +0 -59
  40. package/dist/semantic/01_check_multiple_declaration.js +0 -19
  41. package/dist/semantic/02_give_struct_and_enum_names.js +0 -58
  42. package/dist/semantic/03_match_type_definitions.js +0 -15
  43. package/dist/semantic/04_check_dont_return_secret.js +0 -39
  44. package/dist/semantic/05_expand_spreads.js +0 -57
  45. package/dist/semantic/06_check_empty_struct_or_enum.js +0 -18
  46. package/dist/semantic/07_validate_recursive_types.js +0 -46
  47. package/dist/semantic/08_collect_struct_and_enum_types.js +0 -22
  48. package/dist/semantic/09_validate_annotations.js +0 -122
  49. package/dist/semantic/10_check_duplicate_members_on_enum.js +0 -13
  50. package/dist/semantic/analyser.js +0 -27
  51. package/dist/semantic/transformer.js +0 -46
  52. package/dist/semantic/visitor.js +0 -61
  53. package/dist/token.js +0 -93
  54. package/dist/utils.js +0 -25
  55. /package/dist/{ast.d.ts → src/ast.d.ts} +0 -0
  56. /package/dist/{compatibility → src/compatibility}/index.d.ts +0 -0
  57. /package/dist/{helpers.d.ts → src/helpers.d.ts} +0 -0
  58. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  59. /package/dist/{json.d.ts → src/json.d.ts} +0 -0
  60. /package/dist/{lexer.d.ts → src/lexer.d.ts} +0 -0
  61. /package/dist/{parser.d.ts → src/parser.d.ts} +0 -0
  62. /package/dist/{restparser.d.ts → src/restparser.d.ts} +0 -0
  63. /package/dist/{semantic → src/semantic}/01_check_multiple_declaration.d.ts +0 -0
  64. /package/dist/{semantic → src/semantic}/02_give_struct_and_enum_names.d.ts +0 -0
  65. /package/dist/{semantic → src/semantic}/03_match_type_definitions.d.ts +0 -0
  66. /package/dist/{semantic → src/semantic}/04_check_dont_return_secret.d.ts +0 -0
  67. /package/dist/{semantic → src/semantic}/05_expand_spreads.d.ts +0 -0
  68. /package/dist/{semantic → src/semantic}/06_check_empty_struct_or_enum.d.ts +0 -0
  69. /package/dist/{semantic → src/semantic}/07_validate_recursive_types.d.ts +0 -0
  70. /package/dist/{semantic → src/semantic}/08_collect_struct_and_enum_types.d.ts +0 -0
  71. /package/dist/{semantic → src/semantic}/09_validate_annotations.d.ts +0 -0
  72. /package/dist/{semantic → src/semantic}/10_check_duplicate_members_on_enum.d.ts +0 -0
  73. /package/dist/{semantic → src/semantic}/analyser.d.ts +0 -0
  74. /package/dist/{semantic → src/semantic}/transformer.d.ts +0 -0
  75. /package/dist/{semantic → src/semantic}/visitor.d.ts +0 -0
  76. /package/dist/{token.d.ts → src/token.d.ts} +0 -0
  77. /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["@cubos"]
3
+ }
package/.prettierrc ADDED
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,152 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};