@sdkgen/parser 1.6.2 → 2.0.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.
- package/dist/spec/lexer.spec.js +1 -3
- package/dist/spec/parser.spec.js +226 -30
- package/dist/src/ast.d.ts +17 -15
- package/dist/src/ast.js +23 -21
- package/dist/src/compatibility/index.js +17 -7
- package/dist/src/json.d.ts +9 -17
- package/dist/src/json.js +97 -60
- package/dist/src/lexer.js +1 -7
- package/dist/src/parser.js +92 -40
- package/dist/src/semantic/{06_give_struct_and_enum_names.d.ts → 02_give_struct_and_enum_names.d.ts} +0 -0
- package/dist/src/semantic/{06_give_struct_and_enum_names.js → 02_give_struct_and_enum_names.js} +6 -1
- package/dist/src/semantic/{02_match_type_definitions.d.ts → 03_match_type_definitions.d.ts} +0 -0
- package/dist/src/semantic/{02_match_type_definitions.js → 03_match_type_definitions.js} +0 -0
- package/dist/src/semantic/04_check_dont_return_secret.d.ts +1 -0
- package/dist/src/semantic/04_check_dont_return_secret.js +6 -1
- package/dist/src/semantic/05_expand_spreads.d.ts +9 -0
- package/dist/src/semantic/05_expand_spreads.js +60 -0
- package/dist/src/semantic/{07_check_empty_struct_or_enum.d.ts → 06_check_empty_struct_or_enum.d.ts} +0 -0
- package/dist/src/semantic/{07_check_empty_struct_or_enum.js → 06_check_empty_struct_or_enum.js} +1 -1
- package/dist/src/semantic/07_validate_recursive_types.d.ts +8 -0
- package/dist/src/semantic/07_validate_recursive_types.js +49 -0
- package/dist/src/semantic/{10_validate_annotations.d.ts → 09_validate_annotations.d.ts} +0 -0
- package/dist/src/semantic/{10_validate_annotations.js → 09_validate_annotations.js} +1 -1
- package/dist/src/semantic/analyser.js +12 -14
- package/dist/src/semantic/visitor.js +19 -3
- package/dist/src/token.d.ts +1 -4
- package/dist/src/token.js +4 -10
- package/dist/tsconfig.tsbuildinfo +1 -2191
- package/package.json +6 -6
- package/dist/src/semantic/03_check_no_recursive_types.d.ts +0 -7
- package/dist/src/semantic/03_check_no_recursive_types.js +0 -36
- package/dist/src/semantic/05_check_naming_for_getters_returning_bool.d.ts +0 -5
- package/dist/src/semantic/05_check_naming_for_getters_returning_bool.js +0 -21
- package/dist/src/semantic/09_apply_struct_spreads.d.ts +0 -7
- package/dist/src/semantic/09_apply_struct_spreads.js +0 -42
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidateRecursiveTypes = void 0;
|
|
4
|
+
const ast_1 = require("../ast");
|
|
5
|
+
const visitor_1 = require("./visitor");
|
|
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;
|
|
File without changes
|
|
@@ -55,7 +55,7 @@ class ValidateAnnotationsVisitor extends visitor_1.Visitor {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
else if (node instanceof ast_1.
|
|
58
|
+
else if (node instanceof ast_1.FunctionOperation) {
|
|
59
59
|
for (const annotation of node.annotations) {
|
|
60
60
|
if (annotation instanceof ast_1.DescriptionAnnotation) {
|
|
61
61
|
// Ok
|
|
@@ -3,28 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.analyse = void 0;
|
|
4
4
|
const ast_1 = require("../ast");
|
|
5
5
|
const _01_check_multiple_declaration_1 = require("./01_check_multiple_declaration");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const _02_give_struct_and_enum_names_1 = require("./02_give_struct_and_enum_names");
|
|
7
|
+
const _03_match_type_definitions_1 = require("./03_match_type_definitions");
|
|
8
8
|
const _04_check_dont_return_secret_1 = require("./04_check_dont_return_secret");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const _05_expand_spreads_1 = require("./05_expand_spreads");
|
|
10
|
+
const _06_check_empty_struct_or_enum_1 = require("./06_check_empty_struct_or_enum");
|
|
11
|
+
const _07_validate_recursive_types_1 = require("./07_validate_recursive_types");
|
|
12
12
|
const _08_collect_struct_and_enum_types_1 = require("./08_collect_struct_and_enum_types");
|
|
13
|
-
const
|
|
14
|
-
const _10_validate_annotations_1 = require("./10_validate_annotations");
|
|
13
|
+
const _09_validate_annotations_1 = require("./09_validate_annotations");
|
|
15
14
|
function analyse(root) {
|
|
16
15
|
if (!root.errors.some(error => error.name === "Fatal")) {
|
|
17
16
|
root.errors.push(new ast_1.ErrorNode("Fatal", new ast_1.VoidPrimitiveType()));
|
|
18
17
|
}
|
|
19
18
|
new _01_check_multiple_declaration_1.CheckMultipleDeclarationVisitor(root).process();
|
|
20
|
-
new
|
|
21
|
-
new
|
|
19
|
+
new _02_give_struct_and_enum_names_1.GiveStructAndEnumNamesVisitor(root).process();
|
|
20
|
+
new _03_match_type_definitions_1.MatchTypeDefinitionsVisitor(root).process();
|
|
22
21
|
new _04_check_dont_return_secret_1.CheckDontReturnSecretVisitor(root).process();
|
|
23
|
-
new
|
|
24
|
-
new
|
|
25
|
-
new
|
|
22
|
+
new _05_expand_spreads_1.ExpandSpreadsVisitor(root).process();
|
|
23
|
+
new _06_check_empty_struct_or_enum_1.CheckEmptyStructOrEnumVisitor(root).process();
|
|
24
|
+
new _07_validate_recursive_types_1.ValidateRecursiveTypes(root).process();
|
|
26
25
|
new _08_collect_struct_and_enum_types_1.CollectStructAndEnumTypesVisitor(root).process();
|
|
27
|
-
new
|
|
28
|
-
new _10_validate_annotations_1.ValidateAnnotationsVisitor(root).process();
|
|
26
|
+
new _09_validate_annotations_1.ValidateAnnotationsVisitor(root).process();
|
|
29
27
|
}
|
|
30
28
|
exports.analyse = analyse;
|
|
@@ -21,10 +21,13 @@ class Visitor {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
visit(node) {
|
|
24
|
-
if (node instanceof ast_1.
|
|
24
|
+
if (node instanceof ast_1.FunctionOperation) {
|
|
25
25
|
for (const arg of node.args) {
|
|
26
26
|
this.visit(arg);
|
|
27
27
|
}
|
|
28
|
+
for (const arg of node.fieldsAndSpreads) {
|
|
29
|
+
this.visit(arg);
|
|
30
|
+
}
|
|
28
31
|
this.visit(node.returnType);
|
|
29
32
|
}
|
|
30
33
|
else if (node instanceof ast_1.Field || node instanceof ast_1.TypeDefinition) {
|
|
@@ -34,8 +37,18 @@ class Visitor {
|
|
|
34
37
|
for (const field of node.fields) {
|
|
35
38
|
this.visit(field);
|
|
36
39
|
}
|
|
37
|
-
for (const
|
|
38
|
-
this.visit(
|
|
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);
|
|
39
52
|
}
|
|
40
53
|
}
|
|
41
54
|
else if (node instanceof ast_1.ArrayType || node instanceof ast_1.OptionalType) {
|
|
@@ -44,6 +57,9 @@ class Visitor {
|
|
|
44
57
|
else if (node instanceof ast_1.ErrorNode) {
|
|
45
58
|
this.visit(node.dataType);
|
|
46
59
|
}
|
|
60
|
+
else if (node instanceof ast_1.Spread) {
|
|
61
|
+
this.visit(node.typeReference);
|
|
62
|
+
}
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
exports.Visitor = Visitor;
|
package/dist/src/token.d.ts
CHANGED
|
@@ -48,10 +48,7 @@ export declare class TypeKeywordToken extends Token {
|
|
|
48
48
|
export declare class EnumKeywordToken extends Token {
|
|
49
49
|
maybeAsIdentifier(): IdentifierToken;
|
|
50
50
|
}
|
|
51
|
-
export declare class
|
|
52
|
-
maybeAsIdentifier(): IdentifierToken;
|
|
53
|
-
}
|
|
54
|
-
export declare class FunctionKeywordToken extends Token {
|
|
51
|
+
export declare class FnKeywordToken extends Token {
|
|
55
52
|
maybeAsIdentifier(): IdentifierToken;
|
|
56
53
|
}
|
|
57
54
|
export declare class ErrorKeywordToken extends Token {
|
package/dist/src/token.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrimitiveTypeToken = exports.FalseKeywordToken = exports.TrueKeywordToken = exports.ErrorKeywordToken = exports.
|
|
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
4
|
class TokenLocation {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.filename = "?";
|
|
@@ -87,18 +87,12 @@ class EnumKeywordToken extends Token {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
exports.EnumKeywordToken = EnumKeywordToken;
|
|
90
|
-
class
|
|
90
|
+
class FnKeywordToken extends Token {
|
|
91
91
|
maybeAsIdentifier() {
|
|
92
|
-
return new IdentifierToken("
|
|
92
|
+
return new IdentifierToken("fn");
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
exports.
|
|
96
|
-
class FunctionKeywordToken extends Token {
|
|
97
|
-
maybeAsIdentifier() {
|
|
98
|
-
return new IdentifierToken(this.value);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.FunctionKeywordToken = FunctionKeywordToken;
|
|
95
|
+
exports.FnKeywordToken = FnKeywordToken;
|
|
102
96
|
class ErrorKeywordToken extends Token {
|
|
103
97
|
maybeAsIdentifier() {
|
|
104
98
|
return new IdentifierToken("error");
|