@sdkgen/parser 0.0.0-dev.20231002135133 → 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 (77) 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/dist/{src/ast.d.ts → ast.d.ts} +0 -0
  56. /package/dist/{src/compatibility → compatibility}/index.d.ts +0 -0
  57. /package/dist/{src/helpers.d.ts → helpers.d.ts} +0 -0
  58. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  59. /package/dist/{src/json.d.ts → json.d.ts} +0 -0
  60. /package/dist/{src/lexer.d.ts → lexer.d.ts} +0 -0
  61. /package/dist/{src/parser.d.ts → parser.d.ts} +0 -0
  62. /package/dist/{src/restparser.d.ts → restparser.d.ts} +0 -0
  63. /package/dist/{src/semantic → semantic}/01_check_multiple_declaration.d.ts +0 -0
  64. /package/dist/{src/semantic → semantic}/02_give_struct_and_enum_names.d.ts +0 -0
  65. /package/dist/{src/semantic → semantic}/03_match_type_definitions.d.ts +0 -0
  66. /package/dist/{src/semantic → semantic}/04_check_dont_return_secret.d.ts +0 -0
  67. /package/dist/{src/semantic → semantic}/05_expand_spreads.d.ts +0 -0
  68. /package/dist/{src/semantic → semantic}/06_check_empty_struct_or_enum.d.ts +0 -0
  69. /package/dist/{src/semantic → semantic}/07_validate_recursive_types.d.ts +0 -0
  70. /package/dist/{src/semantic → semantic}/08_collect_struct_and_enum_types.d.ts +0 -0
  71. /package/dist/{src/semantic → semantic}/09_validate_annotations.d.ts +0 -0
  72. /package/dist/{src/semantic → semantic}/10_check_duplicate_members_on_enum.d.ts +0 -0
  73. /package/dist/{src/semantic → semantic}/analyser.d.ts +0 -0
  74. /package/dist/{src/semantic → semantic}/transformer.d.ts +0 -0
  75. /package/dist/{src/semantic → semantic}/visitor.d.ts +0 -0
  76. /package/dist/{src/token.d.ts → token.d.ts} +0 -0
  77. /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExpandSpreadsVisitor = void 0;
4
- const visitor_1 = require("./visitor");
5
- const ast_1 = require("../ast");
6
- class ExpandSpreadsVisitor extends visitor_1.Visitor {
7
- constructor() {
8
- super(...arguments);
9
- /*
10
- * Here we may visit the same struct multiple times
11
- * We must make sure we only process each one once
12
- */
13
- this.processed = new Set();
14
- }
15
- expandSpread(fields, fieldsAndSpreads) {
16
- const fieldIndex = new Map();
17
- for (const fieldOrSpread of fieldsAndSpreads) {
18
- let fieldsToAdd;
19
- if (fieldOrSpread instanceof ast_1.Field) {
20
- fieldsToAdd = [fieldOrSpread];
21
- }
22
- else {
23
- const struct = fieldOrSpread.typeReference.type;
24
- if (!(struct instanceof ast_1.StructType)) {
25
- throw new visitor_1.SemanticError(`A spread operator can't refer to something that is not a struct, in '${fieldOrSpread.typeReference.name}' at ${fieldOrSpread.location}.`);
26
- }
27
- this.visit(struct); // Recursion!
28
- fieldsToAdd = struct.fields;
29
- }
30
- for (const field of fieldsToAdd) {
31
- const index = fieldIndex.get(field.name);
32
- if (index) {
33
- fields[index] = field;
34
- }
35
- else {
36
- fieldIndex.set(field.name, fields.length);
37
- fields.push(field);
38
- }
39
- }
40
- }
41
- }
42
- visit(node) {
43
- if (node instanceof ast_1.StructType) {
44
- if (this.processed.has(node)) {
45
- return;
46
- }
47
- this.processed.add(node);
48
- }
49
- super.visit(node);
50
- if (node instanceof ast_1.StructType) {
51
- this.expandSpread(node.fields, node.fieldsAndSpreads);
52
- node.fieldsAndSpreads = [];
53
- }
54
- else if (node instanceof ast_1.FunctionOperation) {
55
- this.expandSpread(node.args, node.fieldsAndSpreads);
56
- node.fieldsAndSpreads = [];
57
- }
58
- }
59
- }
60
- exports.ExpandSpreadsVisitor = ExpandSpreadsVisitor;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckEmptyStructOrEnumVisitor = void 0;
4
- const visitor_1 = require("./visitor");
5
- const ast_1 = require("../ast");
6
- class CheckEmptyStructOrEnumVisitor extends visitor_1.Visitor {
7
- visit(node) {
8
- super.visit(node);
9
- if (node instanceof ast_1.EnumType) {
10
- if (node.values.length === 0) {
11
- throw new visitor_1.SemanticError(`Enum '${node.name}' at ${node.location} is empty`);
12
- }
13
- }
14
- if (node instanceof ast_1.StructType) {
15
- if (node.fields.length === 0) {
16
- throw new visitor_1.SemanticError(`Struct '${node.name}' at ${node.location} is empty`);
17
- }
18
- }
19
- }
20
- }
21
- exports.CheckEmptyStructOrEnumVisitor = CheckEmptyStructOrEnumVisitor;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidateRecursiveTypes = void 0;
4
- const visitor_1 = require("./visitor");
5
- const ast_1 = require("../ast");
6
- class ValidateRecursiveTypes extends visitor_1.Visitor {
7
- visit(node) {
8
- super.visit(node);
9
- if (node instanceof ast_1.TypeDefinition && this.isRecursiveType(node, node.type)) {
10
- if (!(node.type instanceof ast_1.StructType || node.type instanceof ast_1.EnumType)) {
11
- throw new visitor_1.SemanticError(`Type '${node.name}' at ${node.location} is recursive but is not an struct`);
12
- }
13
- if (this.isInfinitelyRecursiveType(node, node.type)) {
14
- throw new visitor_1.SemanticError(`Type '${node.name}' at ${node.location} is infinitely recursive`);
15
- }
16
- }
17
- }
18
- isRecursiveType(node, type) {
19
- if (type instanceof ast_1.TypeReference) {
20
- return node.name === type.name;
21
- }
22
- else if (type instanceof ast_1.ArrayType) {
23
- return this.isRecursiveType(node, type.base);
24
- }
25
- else if (type instanceof ast_1.OptionalType) {
26
- return this.isRecursiveType(node, type.base);
27
- }
28
- else if (type instanceof ast_1.StructType) {
29
- return type.fields.some(field => this.isRecursiveType(node, field.type));
30
- }
31
- else if (type instanceof ast_1.EnumType) {
32
- return type.values.some(value => value.struct && this.isRecursiveType(node, value.struct));
33
- }
34
- return false;
35
- }
36
- isInfinitelyRecursiveType(node, type) {
37
- if (type instanceof ast_1.TypeReference) {
38
- return type.name === node.name;
39
- }
40
- else if (type instanceof ast_1.StructType) {
41
- return type.fields.some(field => this.isInfinitelyRecursiveType(node, field.type));
42
- }
43
- else if (type instanceof ast_1.EnumType) {
44
- return type.values.every(value => value.struct && this.isInfinitelyRecursiveType(node, value.struct));
45
- }
46
- return false;
47
- }
48
- }
49
- exports.ValidateRecursiveTypes = ValidateRecursiveTypes;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CollectStructAndEnumTypesVisitor = void 0;
4
- const visitor_1 = require("./visitor");
5
- const ast_1 = require("../ast");
6
- class CollectStructAndEnumTypesVisitor extends visitor_1.Visitor {
7
- constructor() {
8
- super(...arguments);
9
- this.visited = new Set();
10
- }
11
- visit(node) {
12
- super.visit(node);
13
- if (this.visited.has(node)) {
14
- return;
15
- }
16
- this.visited.add(node);
17
- if (node instanceof ast_1.StructType) {
18
- this.root.structTypes.push(node);
19
- }
20
- else if (node instanceof ast_1.EnumType) {
21
- this.root.enumTypes.push(node);
22
- }
23
- }
24
- }
25
- exports.CollectStructAndEnumTypesVisitor = CollectStructAndEnumTypesVisitor;
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidateAnnotationsVisitor = void 0;
4
- const visitor_1 = require("./visitor");
5
- const ast_1 = require("../ast");
6
- function isRestEncodable(type) {
7
- return (type instanceof ast_1.BoolPrimitiveType ||
8
- type instanceof ast_1.IntPrimitiveType ||
9
- type instanceof ast_1.UIntPrimitiveType ||
10
- type instanceof ast_1.BigIntPrimitiveType ||
11
- type instanceof ast_1.FloatPrimitiveType ||
12
- type instanceof ast_1.StringPrimitiveType ||
13
- type instanceof ast_1.DatePrimitiveType ||
14
- type instanceof ast_1.DateTimePrimitiveType ||
15
- type instanceof ast_1.MoneyPrimitiveType ||
16
- type instanceof ast_1.DecimalPrimitiveType ||
17
- type instanceof ast_1.CpfPrimitiveType ||
18
- type instanceof ast_1.CnpjPrimitiveType ||
19
- type instanceof ast_1.UuidPrimitiveType ||
20
- type instanceof ast_1.HexPrimitiveType ||
21
- type instanceof ast_1.Base64PrimitiveType ||
22
- type instanceof ast_1.EnumType);
23
- }
24
- function extractRealType(type) {
25
- return type instanceof ast_1.TypeReference ? extractRealType(type.type) : type;
26
- }
27
- class ValidateAnnotationsVisitor extends visitor_1.Visitor {
28
- visit(node) {
29
- if (node instanceof ast_1.EnumValue) {
30
- for (const annotation of node.annotations) {
31
- if (annotation instanceof ast_1.DescriptionAnnotation) {
32
- // Ok
33
- }
34
- else {
35
- throw new visitor_1.SemanticError(`Cannot have @${annotation.constructor.name.replace("Annotation", "").toLowerCase()} at ${annotation.location}`);
36
- }
37
- }
38
- }
39
- else if (node instanceof ast_1.TypeDefinition) {
40
- for (const annotation of node.annotations) {
41
- if (annotation instanceof ast_1.DescriptionAnnotation) {
42
- // Ok
43
- }
44
- else {
45
- throw new visitor_1.SemanticError(`Cannot have @${annotation.constructor.name.replace("Annotation", "").toLowerCase()} at ${annotation.location}`);
46
- }
47
- }
48
- }
49
- else if (node instanceof ast_1.Field) {
50
- for (const annotation of node.annotations) {
51
- if (annotation instanceof ast_1.DescriptionAnnotation) {
52
- // Ok
53
- }
54
- else {
55
- throw new visitor_1.SemanticError(`Cannot have @${annotation.constructor.name.replace("Annotation", "").toLowerCase()} at ${annotation.location}`);
56
- }
57
- }
58
- }
59
- else if (node instanceof ast_1.FunctionOperation) {
60
- for (const annotation of node.annotations) {
61
- if (annotation instanceof ast_1.DescriptionAnnotation) {
62
- // Ok
63
- }
64
- else if (annotation instanceof ast_1.ThrowsAnnotation) {
65
- if (!this.root.errors.some(error => error.name === annotation.error)) {
66
- throw new visitor_1.SemanticError(`Unknown error type '${annotation.error}' at ${annotation.location}`);
67
- }
68
- }
69
- else if (annotation instanceof ast_1.RestAnnotation) {
70
- const allVariables = [...annotation.pathVariables, ...annotation.queryVariables, ...annotation.headers.values()];
71
- if (allVariables.length !== new Set(allVariables).size) {
72
- throw new visitor_1.SemanticError(`Arguments must appear only once for rest annotation at ${annotation.location}`);
73
- }
74
- for (const name of allVariables) {
75
- const arg = node.args.find(x => x.name === name);
76
- if (!arg) {
77
- throw new visitor_1.SemanticError(`Argument '${name}' not found at ${annotation.location}`);
78
- }
79
- if (annotation.pathVariables.includes(name) && arg.type instanceof ast_1.OptionalType) {
80
- throw new visitor_1.SemanticError(`The path argument '${name}' can't be nullable at ${annotation.location}`);
81
- }
82
- const baseType = arg.type instanceof ast_1.OptionalType ? arg.type.base : arg.type;
83
- if (!isRestEncodable(extractRealType(baseType))) {
84
- throw new visitor_1.SemanticError(`Argument '${name}' can't have type '${arg.type.name}' for rest annotation at ${annotation.location}`);
85
- }
86
- }
87
- for (const arg of node.args) {
88
- if (!allVariables.includes(arg.name) && annotation.bodyVariable !== arg.name) {
89
- throw new visitor_1.SemanticError(`Argument '${arg.name}' is missing from the rest annotation at ${annotation.location}`);
90
- }
91
- const queryAndPathVariables = [...annotation.pathVariables, ...annotation.queryVariables];
92
- if (annotation.method === "GET" && queryAndPathVariables.includes(arg.name) && arg.secret) {
93
- throw new visitor_1.SemanticError(`Argument marked as secret cannot be used in the path or query parts of a GET endpoint at ${annotation.location}`);
94
- }
95
- }
96
- if (annotation.method === "GET" && node.returnType instanceof ast_1.VoidPrimitiveType) {
97
- throw new visitor_1.SemanticError(`A GET rest endpoint must return something at ${annotation.location}`);
98
- }
99
- }
100
- else if (annotation instanceof ast_1.HiddenAnnotation) {
101
- // Ok
102
- }
103
- else {
104
- throw new visitor_1.SemanticError(`Cannot have @${annotation.constructor.name.replace("Annotation", "").toLowerCase()} at ${annotation.location}`);
105
- }
106
- }
107
- }
108
- else if (node instanceof ast_1.ErrorNode) {
109
- for (const annotation of node.annotations) {
110
- if (annotation instanceof ast_1.StatusCodeAnnotation) {
111
- if (annotation.statusCode < 400 || annotation.statusCode > 599) {
112
- throw new visitor_1.SemanticError(`Error status code can only be 4xx or 5xx at ${annotation.location}`);
113
- }
114
- }
115
- else {
116
- throw new visitor_1.SemanticError(`Cannot have @${annotation.constructor.name.replace("Annotation", "").toLowerCase()} at ${annotation.location}`);
117
- }
118
- }
119
- if (node.annotations.filter(ann => ann instanceof ast_1.StatusCodeAnnotation).length > 1) {
120
- throw new visitor_1.SemanticError(`Can't provide more than one status code at ${node.location}`);
121
- }
122
- }
123
- }
124
- }
125
- exports.ValidateAnnotationsVisitor = ValidateAnnotationsVisitor;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckDuplicatedMembersOnEnumVisitor = void 0;
4
- const visitor_1 = require("./visitor");
5
- const ast_1 = require("../ast");
6
- class CheckDuplicatedMembersOnEnumVisitor extends visitor_1.Visitor {
7
- visit(node) {
8
- super.visit(node);
9
- if (node instanceof ast_1.EnumType) {
10
- if (node.values.length !== new Set(node.values.map(x => x.value)).size) {
11
- throw new visitor_1.SemanticError(`Enum '${node.name}' at ${node.location} has duplicated members`);
12
- }
13
- }
14
- }
15
- }
16
- exports.CheckDuplicatedMembersOnEnumVisitor = CheckDuplicatedMembersOnEnumVisitor;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyse = void 0;
4
- const _01_check_multiple_declaration_1 = require("./01_check_multiple_declaration");
5
- const _02_give_struct_and_enum_names_1 = require("./02_give_struct_and_enum_names");
6
- const _03_match_type_definitions_1 = require("./03_match_type_definitions");
7
- const _04_check_dont_return_secret_1 = require("./04_check_dont_return_secret");
8
- const _05_expand_spreads_1 = require("./05_expand_spreads");
9
- const _06_check_empty_struct_or_enum_1 = require("./06_check_empty_struct_or_enum");
10
- const _07_validate_recursive_types_1 = require("./07_validate_recursive_types");
11
- const _08_collect_struct_and_enum_types_1 = require("./08_collect_struct_and_enum_types");
12
- const _09_validate_annotations_1 = require("./09_validate_annotations");
13
- const _10_check_duplicate_members_on_enum_1 = require("./10_check_duplicate_members_on_enum");
14
- const ast_1 = require("../ast");
15
- function analyse(root) {
16
- if (!root.errors.some(error => error.name === "Fatal")) {
17
- root.errors.push(new ast_1.ErrorNode("Fatal", new ast_1.VoidPrimitiveType()));
18
- }
19
- new _01_check_multiple_declaration_1.CheckMultipleDeclarationVisitor(root).process();
20
- new _02_give_struct_and_enum_names_1.GiveStructAndEnumNamesTransformer(root).process();
21
- new _03_match_type_definitions_1.MatchTypeDefinitionsVisitor(root).process();
22
- new _04_check_dont_return_secret_1.CheckDontReturnSecretVisitor(root).process();
23
- new _05_expand_spreads_1.ExpandSpreadsVisitor(root).process();
24
- new _06_check_empty_struct_or_enum_1.CheckEmptyStructOrEnumVisitor(root).process();
25
- new _07_validate_recursive_types_1.ValidateRecursiveTypes(root).process();
26
- new _08_collect_struct_and_enum_types_1.CollectStructAndEnumTypesVisitor(root).process();
27
- new _09_validate_annotations_1.ValidateAnnotationsVisitor(root).process();
28
- new _10_check_duplicate_members_on_enum_1.CheckDuplicatedMembersOnEnumVisitor(root).process();
29
- }
30
- exports.analyse = analyse;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Transformer = exports.SemanticError = void 0;
4
- const ast_1 = require("../ast");
5
- class SemanticError extends Error {
6
- }
7
- exports.SemanticError = SemanticError;
8
- class Transformer {
9
- constructor(root) {
10
- this.root = root;
11
- }
12
- process() {
13
- this.root.errors = this.root.errors.map(x => this.transform(x));
14
- this.root.typeDefinitions = this.root.typeDefinitions.map(x => this.transform(x));
15
- this.root.operations = this.root.operations.map(x => this.transform(x));
16
- }
17
- transform(node) {
18
- if (node instanceof ast_1.FunctionOperation) {
19
- node.args = node.args.map(x => this.transform(x));
20
- node.fieldsAndSpreads = node.fieldsAndSpreads.map(x => this.transform(x));
21
- node.returnType = this.transform(node.returnType);
22
- }
23
- else if (node instanceof ast_1.Field || node instanceof ast_1.TypeDefinition) {
24
- node.type = this.transform(node.type);
25
- }
26
- else if (node instanceof ast_1.StructType) {
27
- node.fields = node.fields.map(x => this.transform(x));
28
- node.fieldsAndSpreads = node.fieldsAndSpreads.map(x => this.transform(x));
29
- }
30
- else if (node instanceof ast_1.EnumType) {
31
- node.values = node.values.map(x => this.transform(x));
32
- }
33
- else if (node instanceof ast_1.EnumValue) {
34
- if (node.struct) {
35
- node.struct = this.transform(node.struct);
36
- }
37
- }
38
- else if (node instanceof ast_1.ArrayType || node instanceof ast_1.OptionalType) {
39
- node.base = this.transform(node.base);
40
- }
41
- else if (node instanceof ast_1.ErrorNode) {
42
- node.dataType = this.transform(node.dataType);
43
- }
44
- else if (node instanceof ast_1.Spread) {
45
- node.typeReference = this.transform(node.typeReference);
46
- }
47
- return node;
48
- }
49
- }
50
- exports.Transformer = Transformer;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Visitor = exports.SemanticError = void 0;
4
- const ast_1 = require("../ast");
5
- class SemanticError extends Error {
6
- }
7
- exports.SemanticError = SemanticError;
8
- class Visitor {
9
- constructor(root) {
10
- this.root = root;
11
- }
12
- process() {
13
- for (const error of this.root.errors) {
14
- this.visit(error);
15
- }
16
- for (const typeDefinition of this.root.typeDefinitions) {
17
- this.visit(typeDefinition);
18
- }
19
- for (const operation of this.root.operations) {
20
- this.visit(operation);
21
- }
22
- }
23
- visit(node) {
24
- if (node instanceof ast_1.FunctionOperation) {
25
- for (const arg of node.args) {
26
- this.visit(arg);
27
- }
28
- for (const arg of node.fieldsAndSpreads) {
29
- this.visit(arg);
30
- }
31
- this.visit(node.returnType);
32
- }
33
- else if (node instanceof ast_1.Field || node instanceof ast_1.TypeDefinition) {
34
- this.visit(node.type);
35
- }
36
- else if (node instanceof ast_1.StructType) {
37
- for (const field of node.fields) {
38
- this.visit(field);
39
- }
40
- for (const field of node.fieldsAndSpreads) {
41
- this.visit(field);
42
- }
43
- }
44
- else if (node instanceof ast_1.EnumType) {
45
- for (const enumValue of node.values) {
46
- this.visit(enumValue);
47
- }
48
- }
49
- else if (node instanceof ast_1.EnumValue) {
50
- if (node.struct) {
51
- this.visit(node.struct);
52
- }
53
- }
54
- else if (node instanceof ast_1.ArrayType || node instanceof ast_1.OptionalType) {
55
- this.visit(node.base);
56
- }
57
- else if (node instanceof ast_1.ErrorNode) {
58
- this.visit(node.dataType);
59
- }
60
- else if (node instanceof ast_1.Spread) {
61
- this.visit(node.typeReference);
62
- }
63
- }
64
- }
65
- exports.Visitor = Visitor;
package/dist/src/token.js DELETED
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrimitiveTypeToken = exports.FalseKeywordToken = exports.TrueKeywordToken = exports.ErrorKeywordToken = exports.FnKeywordToken = exports.EnumKeywordToken = exports.TypeKeywordToken = exports.ImportKeywordToken = exports.AnnotationToken = exports.SpreadSymbolToken = exports.CommaSymbolToken = exports.ArraySymbolToken = exports.OptionalSymbolToken = exports.ColonSymbolToken = exports.ParensCloseSymbolToken = exports.ParensOpenSymbolToken = exports.CurlyCloseSymbolToken = exports.CurlyOpenSymbolToken = exports.ExclamationMarkSymbolToken = exports.EqualSymbolToken = exports.StringLiteralToken = exports.IdentifierToken = exports.Token = exports.TokenLocation = void 0;
4
- class TokenLocation {
5
- constructor() {
6
- this.filename = "?";
7
- this.line = 0;
8
- this.column = 0;
9
- }
10
- toString() {
11
- return `${this.filename}:${this.line}:${this.column}`;
12
- }
13
- }
14
- exports.TokenLocation = TokenLocation;
15
- class Token {
16
- constructor(value = "") {
17
- this.value = value;
18
- this.location = new TokenLocation();
19
- Object.defineProperty(this, "location", { enumerable: false });
20
- }
21
- maybeAsIdentifier() {
22
- return this;
23
- }
24
- toString() {
25
- const name = this.constructor.name.replace("Token", "");
26
- return this.value === "" ? name : `${name}(${JSON.stringify(this.value)})`;
27
- }
28
- }
29
- exports.Token = Token;
30
- class IdentifierToken extends Token {
31
- }
32
- exports.IdentifierToken = IdentifierToken;
33
- class StringLiteralToken extends Token {
34
- }
35
- exports.StringLiteralToken = StringLiteralToken;
36
- class EqualSymbolToken extends Token {
37
- }
38
- exports.EqualSymbolToken = EqualSymbolToken;
39
- class ExclamationMarkSymbolToken extends Token {
40
- }
41
- exports.ExclamationMarkSymbolToken = ExclamationMarkSymbolToken;
42
- class CurlyOpenSymbolToken extends Token {
43
- }
44
- exports.CurlyOpenSymbolToken = CurlyOpenSymbolToken;
45
- class CurlyCloseSymbolToken extends Token {
46
- }
47
- exports.CurlyCloseSymbolToken = CurlyCloseSymbolToken;
48
- class ParensOpenSymbolToken extends Token {
49
- }
50
- exports.ParensOpenSymbolToken = ParensOpenSymbolToken;
51
- class ParensCloseSymbolToken extends Token {
52
- }
53
- exports.ParensCloseSymbolToken = ParensCloseSymbolToken;
54
- class ColonSymbolToken extends Token {
55
- }
56
- exports.ColonSymbolToken = ColonSymbolToken;
57
- class OptionalSymbolToken extends Token {
58
- }
59
- exports.OptionalSymbolToken = OptionalSymbolToken;
60
- class ArraySymbolToken extends Token {
61
- }
62
- exports.ArraySymbolToken = ArraySymbolToken;
63
- class CommaSymbolToken extends Token {
64
- }
65
- exports.CommaSymbolToken = CommaSymbolToken;
66
- class SpreadSymbolToken extends Token {
67
- }
68
- exports.SpreadSymbolToken = SpreadSymbolToken;
69
- class AnnotationToken extends Token {
70
- }
71
- exports.AnnotationToken = AnnotationToken;
72
- class ImportKeywordToken extends Token {
73
- maybeAsIdentifier() {
74
- return new IdentifierToken("import");
75
- }
76
- }
77
- exports.ImportKeywordToken = ImportKeywordToken;
78
- class TypeKeywordToken extends Token {
79
- maybeAsIdentifier() {
80
- return new IdentifierToken("type");
81
- }
82
- }
83
- exports.TypeKeywordToken = TypeKeywordToken;
84
- class EnumKeywordToken extends Token {
85
- maybeAsIdentifier() {
86
- return new IdentifierToken("enum");
87
- }
88
- }
89
- exports.EnumKeywordToken = EnumKeywordToken;
90
- class FnKeywordToken extends Token {
91
- maybeAsIdentifier() {
92
- return new IdentifierToken("fn");
93
- }
94
- }
95
- exports.FnKeywordToken = FnKeywordToken;
96
- class ErrorKeywordToken extends Token {
97
- maybeAsIdentifier() {
98
- return new IdentifierToken("error");
99
- }
100
- }
101
- exports.ErrorKeywordToken = ErrorKeywordToken;
102
- class TrueKeywordToken extends Token {
103
- maybeAsIdentifier() {
104
- return new IdentifierToken("true");
105
- }
106
- }
107
- exports.TrueKeywordToken = TrueKeywordToken;
108
- class FalseKeywordToken extends Token {
109
- maybeAsIdentifier() {
110
- return new IdentifierToken("false");
111
- }
112
- }
113
- exports.FalseKeywordToken = FalseKeywordToken;
114
- class PrimitiveTypeToken extends Token {
115
- maybeAsIdentifier() {
116
- return new IdentifierToken(this.value);
117
- }
118
- }
119
- exports.PrimitiveTypeToken = PrimitiveTypeToken;
package/dist/src/utils.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.primitiveToAstClass = void 0;
4
- const ast_1 = require("./ast");
5
- exports.primitiveToAstClass = new Map();
6
- exports.primitiveToAstClass.set("string", ast_1.StringPrimitiveType);
7
- exports.primitiveToAstClass.set("int", ast_1.IntPrimitiveType);
8
- exports.primitiveToAstClass.set("uint", ast_1.UIntPrimitiveType);
9
- exports.primitiveToAstClass.set("date", ast_1.DatePrimitiveType);
10
- exports.primitiveToAstClass.set("datetime", ast_1.DateTimePrimitiveType);
11
- exports.primitiveToAstClass.set("float", ast_1.FloatPrimitiveType);
12
- exports.primitiveToAstClass.set("bigint", ast_1.BigIntPrimitiveType);
13
- exports.primitiveToAstClass.set("bool", ast_1.BoolPrimitiveType);
14
- exports.primitiveToAstClass.set("bytes", ast_1.BytesPrimitiveType);
15
- exports.primitiveToAstClass.set("money", ast_1.MoneyPrimitiveType);
16
- exports.primitiveToAstClass.set("decimal", ast_1.DecimalPrimitiveType);
17
- exports.primitiveToAstClass.set("cpf", ast_1.CpfPrimitiveType);
18
- exports.primitiveToAstClass.set("cnpj", ast_1.CnpjPrimitiveType);
19
- exports.primitiveToAstClass.set("email", ast_1.EmailPrimitiveType);
20
- exports.primitiveToAstClass.set("html", ast_1.HtmlPrimitiveType);
21
- exports.primitiveToAstClass.set("url", ast_1.UrlPrimitiveType);
22
- exports.primitiveToAstClass.set("uuid", ast_1.UuidPrimitiveType);
23
- exports.primitiveToAstClass.set("hex", ast_1.HexPrimitiveType);
24
- exports.primitiveToAstClass.set("base64", ast_1.Base64PrimitiveType);
25
- exports.primitiveToAstClass.set("xml", ast_1.XmlPrimitiveType);
26
- exports.primitiveToAstClass.set("json", ast_1.JsonPrimitiveType);
27
- exports.primitiveToAstClass.set("void", ast_1.VoidPrimitiveType);