@sdkgen/parser 2.3.2 → 2.5.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 (72) hide show
  1. package/dist/{src/ast.d.ts → ast.d.ts} +4 -0
  2. package/dist/{src/ast.js → ast.js} +10 -13
  3. package/dist/compatibility/index.js +210 -0
  4. package/dist/helpers.js +24 -0
  5. package/dist/index.js +17 -0
  6. package/dist/{src/json.d.ts → json.d.ts} +3 -0
  7. package/dist/json.js +235 -0
  8. package/dist/{src/lexer.js → lexer.js} +26 -25
  9. package/dist/parser.js +430 -0
  10. package/dist/restparser.js +63 -0
  11. package/dist/semantic/01_check_multiple_declaration.js +23 -0
  12. package/dist/semantic/02_give_struct_and_enum_names.js +62 -0
  13. package/dist/semantic/03_match_type_definitions.js +19 -0
  14. package/dist/semantic/04_check_dont_return_secret.js +43 -0
  15. package/dist/semantic/05_expand_spreads.js +61 -0
  16. package/dist/semantic/06_check_empty_struct_or_enum.js +22 -0
  17. package/dist/semantic/07_validate_recursive_types.js +50 -0
  18. package/dist/semantic/08_collect_struct_and_enum_types.js +26 -0
  19. package/dist/{src/semantic → semantic}/09_validate_annotations.js +4 -0
  20. package/dist/semantic/10_check_duplicate_members_on_enum.js +17 -0
  21. package/dist/{src/semantic → semantic}/analyser.js +1 -0
  22. package/dist/semantic/transformer.js +51 -0
  23. package/dist/semantic/visitor.js +66 -0
  24. package/dist/{src/token.js → token.js} +1 -0
  25. package/dist/utils.js +28 -0
  26. package/package.json +24 -8
  27. package/.eslintrc.json +0 -3
  28. package/.prettierrc +0 -12
  29. package/dist/spec/lexer.spec.d.ts +0 -1
  30. package/dist/spec/lexer.spec.js +0 -152
  31. package/dist/spec/parser.spec.d.ts +0 -1
  32. package/dist/spec/parser.spec.js +0 -967
  33. package/dist/src/compatibility/index.js +0 -211
  34. package/dist/src/helpers.js +0 -23
  35. package/dist/src/index.js +0 -29
  36. package/dist/src/json.js +0 -234
  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/10_check_duplicate_members_on_enum.js +0 -16
  48. package/dist/src/semantic/transformer.js +0 -50
  49. package/dist/src/semantic/visitor.js +0 -65
  50. package/dist/src/utils.js +0 -27
  51. package/dist/tsconfig.tsbuildinfo +0 -1
  52. /package/dist/{src/compatibility → compatibility}/index.d.ts +0 -0
  53. /package/dist/{src/helpers.d.ts → helpers.d.ts} +0 -0
  54. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  55. /package/dist/{src/lexer.d.ts → lexer.d.ts} +0 -0
  56. /package/dist/{src/parser.d.ts → parser.d.ts} +0 -0
  57. /package/dist/{src/restparser.d.ts → restparser.d.ts} +0 -0
  58. /package/dist/{src/semantic → semantic}/01_check_multiple_declaration.d.ts +0 -0
  59. /package/dist/{src/semantic → semantic}/02_give_struct_and_enum_names.d.ts +0 -0
  60. /package/dist/{src/semantic → semantic}/03_match_type_definitions.d.ts +0 -0
  61. /package/dist/{src/semantic → semantic}/04_check_dont_return_secret.d.ts +0 -0
  62. /package/dist/{src/semantic → semantic}/05_expand_spreads.d.ts +0 -0
  63. /package/dist/{src/semantic → semantic}/06_check_empty_struct_or_enum.d.ts +0 -0
  64. /package/dist/{src/semantic → semantic}/07_validate_recursive_types.d.ts +0 -0
  65. /package/dist/{src/semantic → semantic}/08_collect_struct_and_enum_types.d.ts +0 -0
  66. /package/dist/{src/semantic → semantic}/09_validate_annotations.d.ts +0 -0
  67. /package/dist/{src/semantic → semantic}/10_check_duplicate_members_on_enum.d.ts +0 -0
  68. /package/dist/{src/semantic → semantic}/analyser.d.ts +0 -0
  69. /package/dist/{src/semantic → semantic}/transformer.d.ts +0 -0
  70. /package/dist/{src/semantic → semantic}/visitor.d.ts +0 -0
  71. /package/dist/{src/token.d.ts → token.d.ts} +0 -0
  72. /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
@@ -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 {};