@rightcapital/phpdoc-parser 0.6.2-renovate-lock-file-maintenance.2572.1.0 → 0.6.2
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/package.json +5 -4
- package/dist/index.d.ts +0 -85
- package/dist/index.js +0 -182
- package/dist/phpdoc-parser/ast/abstract-node-visitor.d.ts +0 -8
- package/dist/phpdoc-parser/ast/abstract-node-visitor.js +0 -18
- package/dist/phpdoc-parser/ast/base-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/base-node.js +0 -27
- package/dist/phpdoc-parser/ast/comment.d.ts +0 -7
- package/dist/phpdoc-parser/ast/comment.js +0 -14
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-item-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-item-node.js +0 -21
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-node.js +0 -17
- package/dist/phpdoc-parser/ast/const-expr/const-expr-false-node.d.ts +0 -5
- package/dist/phpdoc-parser/ast/const-expr/const-expr-false-node.js +0 -13
- package/dist/phpdoc-parser/ast/const-expr/const-expr-float-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/const-expr/const-expr-float-node.js +0 -17
- package/dist/phpdoc-parser/ast/const-expr/const-expr-integer-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/const-expr/const-expr-integer-node.js +0 -17
- package/dist/phpdoc-parser/ast/const-expr/const-expr-node.d.ts +0 -23
- package/dist/phpdoc-parser/ast/const-expr/const-expr-node.js +0 -40
- package/dist/phpdoc-parser/ast/const-expr/const-expr-null-node.d.ts +0 -5
- package/dist/phpdoc-parser/ast/const-expr/const-expr-null-node.js +0 -13
- package/dist/phpdoc-parser/ast/const-expr/const-expr-string-node.d.ts +0 -11
- package/dist/phpdoc-parser/ast/const-expr/const-expr-string-node.js +0 -48
- package/dist/phpdoc-parser/ast/const-expr/const-expr-true-node.d.ts +0 -5
- package/dist/phpdoc-parser/ast/const-expr/const-expr-true-node.js +0 -13
- package/dist/phpdoc-parser/ast/const-expr/const-fetch-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/const-expr/const-fetch-node.js +0 -21
- package/dist/phpdoc-parser/ast/node-traverser.d.ts +0 -11
- package/dist/phpdoc-parser/ast/node-traverser.js +0 -216
- package/dist/phpdoc-parser/ast/node-visitor/cloning-visitor.d.ts +0 -5
- package/dist/phpdoc-parser/ast/node-visitor/cloning-visitor.js +0 -14
- package/dist/phpdoc-parser/ast/node-visitor.d.ts +0 -11
- package/dist/phpdoc-parser/ast/node-visitor.js +0 -2
- package/dist/phpdoc-parser/ast/node.d.ts +0 -6
- package/dist/phpdoc-parser/ast/node.js +0 -2
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-method-value-node.d.ts +0 -13
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-method-value-node.js +0 -24
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-property-value-node.d.ts +0 -13
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-property-value-node.js +0 -24
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-value-node.d.ts +0 -12
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-value-node.js +0 -23
- package/dist/phpdoc-parser/ast/php-doc/deprecated-tag-value-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/php-doc/deprecated-tag-value-node.js +0 -17
- package/dist/phpdoc-parser/ast/php-doc/extends-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/extends-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/generic-tag-value-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/php-doc/generic-tag-value-node.js +0 -17
- package/dist/phpdoc-parser/ast/php-doc/helpers.d.ts +0 -48
- package/dist/phpdoc-parser/ast/php-doc/helpers.js +0 -99
- package/dist/phpdoc-parser/ast/php-doc/implements-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/implements-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/invalid-tag-value-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/php-doc/invalid-tag-value-node.js +0 -33
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-node.d.ts +0 -15
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-node.js +0 -27
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-parameter-node.d.ts +0 -13
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-parameter-node.js +0 -27
- package/dist/phpdoc-parser/ast/php-doc/mixin-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/mixin-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/param-closure-this-tag-value-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/php-doc/param-closure-this-tag-value-node.js +0 -19
- package/dist/phpdoc-parser/ast/php-doc/param-immediately-invoked-callable-tag-value-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/php-doc/param-immediately-invoked-callable-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/param-later-invoked-callable-tag-value-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/php-doc/param-later-invoked-callable-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/param-out-tag-value-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/php-doc/param-out-tag-value-node.js +0 -19
- package/dist/phpdoc-parser/ast/php-doc/param-tag-value-node.d.ts +0 -12
- package/dist/phpdoc-parser/ast/php-doc/param-tag-value-node.js +0 -28
- package/dist/phpdoc-parser/ast/php-doc/php-doc-child-node.d.ts +0 -4
- package/dist/phpdoc-parser/ast/php-doc/php-doc-child-node.js +0 -10
- package/dist/phpdoc-parser/ast/php-doc/php-doc-node.d.ts +0 -36
- package/dist/phpdoc-parser/ast/php-doc/php-doc-node.js +0 -111
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-value-node.d.ts +0 -4
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-value-node.js +0 -10
- package/dist/phpdoc-parser/ast/php-doc/php-doc-text-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/php-doc/php-doc-text-node.js +0 -17
- package/dist/phpdoc-parser/ast/php-doc/property-tag-value-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/php-doc/property-tag-value-node.js +0 -19
- package/dist/phpdoc-parser/ast/php-doc/pure-unless-callable-is-impure-tag-value-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/php-doc/pure-unless-callable-is-impure-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/require-extends-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/require-extends-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/require-implements-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/require-implements-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/return-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/return-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/sealed-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/sealed-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/self-out-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/self-out-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/template-tag-value-node.d.ts +0 -12
- package/dist/phpdoc-parser/ast/php-doc/template-tag-value-node.js +0 -26
- package/dist/phpdoc-parser/ast/php-doc/throws-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/throws-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/type-alias-import-tag-value-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/php-doc/type-alias-import-tag-value-node.js +0 -22
- package/dist/phpdoc-parser/ast/php-doc/type-alias-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/type-alias-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/typeless-param-tag-value-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/php-doc/typeless-param-tag-value-node.js +0 -22
- package/dist/phpdoc-parser/ast/php-doc/uses-tag-value-node.d.ts +0 -9
- package/dist/phpdoc-parser/ast/php-doc/uses-tag-value-node.js +0 -18
- package/dist/phpdoc-parser/ast/php-doc/var-tag-value-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/php-doc/var-tag-value-node.js +0 -19
- package/dist/phpdoc-parser/ast/type/array-shape-item-node.d.ts +0 -13
- package/dist/phpdoc-parser/ast/type/array-shape-item-node.js +0 -22
- package/dist/phpdoc-parser/ast/type/array-shape-node.d.ts +0 -20
- package/dist/phpdoc-parser/ast/type/array-shape-node.js +0 -41
- package/dist/phpdoc-parser/ast/type/array-shape-unsealed-type-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/type/array-shape-unsealed-type-node.js +0 -21
- package/dist/phpdoc-parser/ast/type/array-type-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/type/array-type-node.js +0 -25
- package/dist/phpdoc-parser/ast/type/callable-type-node.d.ts +0 -13
- package/dist/phpdoc-parser/ast/type/callable-type-node.js +0 -26
- package/dist/phpdoc-parser/ast/type/callable-type-parameter-node.d.ts +0 -11
- package/dist/phpdoc-parser/ast/type/callable-type-parameter-node.js +0 -26
- package/dist/phpdoc-parser/ast/type/conditional-type-for-parameter-node.d.ts +0 -11
- package/dist/phpdoc-parser/ast/type/conditional-type-for-parameter-node.js +0 -21
- package/dist/phpdoc-parser/ast/type/conditional-type-node.d.ts +0 -11
- package/dist/phpdoc-parser/ast/type/conditional-type-node.js +0 -21
- package/dist/phpdoc-parser/ast/type/const-type-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/type/const-type-node.js +0 -17
- package/dist/phpdoc-parser/ast/type/generic-type-node.d.ts +0 -15
- package/dist/phpdoc-parser/ast/type/generic-type-node.js +0 -37
- package/dist/phpdoc-parser/ast/type/identifier-type-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/type/identifier-type-node.js +0 -17
- package/dist/phpdoc-parser/ast/type/intersection-type-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/type/intersection-type-node.js +0 -25
- package/dist/phpdoc-parser/ast/type/invalid-type-node.d.ts +0 -10
- package/dist/phpdoc-parser/ast/type/invalid-type-node.js +0 -29
- package/dist/phpdoc-parser/ast/type/nullable-type-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/type/nullable-type-node.js +0 -17
- package/dist/phpdoc-parser/ast/type/object-shape-item-node.d.ts +0 -11
- package/dist/phpdoc-parser/ast/type/object-shape-item-node.js +0 -22
- package/dist/phpdoc-parser/ast/type/object-shape-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/type/object-shape-node.js +0 -17
- package/dist/phpdoc-parser/ast/type/offset-access-type-node.d.ts +0 -8
- package/dist/phpdoc-parser/ast/type/offset-access-type-node.js +0 -26
- package/dist/phpdoc-parser/ast/type/this-type-node.d.ts +0 -5
- package/dist/phpdoc-parser/ast/type/this-type-node.js +0 -13
- package/dist/phpdoc-parser/ast/type/type-node.d.ts +0 -40
- package/dist/phpdoc-parser/ast/type/type-node.js +0 -64
- package/dist/phpdoc-parser/ast/type/union-type-node.d.ts +0 -7
- package/dist/phpdoc-parser/ast/type/union-type-node.js +0 -25
- package/dist/phpdoc-parser/ast/types.d.ts +0 -14
- package/dist/phpdoc-parser/ast/types.js +0 -19
- package/dist/phpdoc-parser/lexer/lexer.d.ts +0 -82
- package/dist/phpdoc-parser/lexer/lexer.js +0 -146
- package/dist/phpdoc-parser/parser/const-expr-parser.d.ts +0 -14
- package/dist/phpdoc-parser/parser/const-expr-parser.js +0 -132
- package/dist/phpdoc-parser/parser/node-collecting-visitor.d.ts +0 -7
- package/dist/phpdoc-parser/parser/node-collecting-visitor.js +0 -15
- package/dist/phpdoc-parser/parser/parser-exception.d.ts +0 -16
- package/dist/phpdoc-parser/parser/parser-exception.js +0 -44
- package/dist/phpdoc-parser/parser/php-doc-parser.d.ts +0 -49
- package/dist/phpdoc-parser/parser/php-doc-parser.js +0 -604
- package/dist/phpdoc-parser/parser/string-unescaper.d.ts +0 -6
- package/dist/phpdoc-parser/parser/string-unescaper.js +0 -41
- package/dist/phpdoc-parser/parser/token-iterator.d.ts +0 -44
- package/dist/phpdoc-parser/parser/token-iterator.js +0 -243
- package/dist/phpdoc-parser/parser/type-parser.d.ts +0 -47
- package/dist/phpdoc-parser/parser/type-parser.js +0 -706
- package/dist/phpdoc-parser/parser-config.d.ts +0 -10
- package/dist/phpdoc-parser/parser-config.js +0 -12
- package/dist/phpdoc-parser/printer/diff-elem.d.ts +0 -12
- package/dist/phpdoc-parser/printer/diff-elem.js +0 -19
- package/dist/phpdoc-parser/printer/differ.d.ts +0 -10
- package/dist/phpdoc-parser/printer/differ.js +0 -111
- package/dist/phpdoc-parser/printer/printer.d.ts +0 -20
- package/dist/phpdoc-parser/printer/printer.js +0 -612
- package/dist/phpdoc-parser/transpiler/helpers.d.ts +0 -10
- package/dist/phpdoc-parser/transpiler/helpers.js +0 -73
- package/dist/phpdoc-parser/transpiler/php-doc-to-typescript-type-transpiler.d.ts +0 -26
- package/dist/phpdoc-parser/transpiler/php-doc-to-typescript-type-transpiler.js +0 -122
|
@@ -1,706 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypeParser = void 0;
|
|
4
|
-
const const_expr_array_node_1 = require("../ast/const-expr/const-expr-array-node");
|
|
5
|
-
const const_expr_integer_node_1 = require("../ast/const-expr/const-expr-integer-node");
|
|
6
|
-
const const_expr_string_node_1 = require("../ast/const-expr/const-expr-string-node");
|
|
7
|
-
const const_fetch_node_1 = require("../ast/const-expr/const-fetch-node");
|
|
8
|
-
const template_tag_value_node_1 = require("../ast/php-doc/template-tag-value-node");
|
|
9
|
-
const array_shape_item_node_1 = require("../ast/type/array-shape-item-node");
|
|
10
|
-
const array_shape_node_1 = require("../ast/type/array-shape-node");
|
|
11
|
-
const array_shape_unsealed_type_node_1 = require("../ast/type/array-shape-unsealed-type-node");
|
|
12
|
-
const array_type_node_1 = require("../ast/type/array-type-node");
|
|
13
|
-
const callable_type_node_1 = require("../ast/type/callable-type-node");
|
|
14
|
-
const callable_type_parameter_node_1 = require("../ast/type/callable-type-parameter-node");
|
|
15
|
-
const conditional_type_for_parameter_node_1 = require("../ast/type/conditional-type-for-parameter-node");
|
|
16
|
-
const conditional_type_node_1 = require("../ast/type/conditional-type-node");
|
|
17
|
-
const const_type_node_1 = require("../ast/type/const-type-node");
|
|
18
|
-
const generic_type_node_1 = require("../ast/type/generic-type-node");
|
|
19
|
-
const identifier_type_node_1 = require("../ast/type/identifier-type-node");
|
|
20
|
-
const intersection_type_node_1 = require("../ast/type/intersection-type-node");
|
|
21
|
-
const nullable_type_node_1 = require("../ast/type/nullable-type-node");
|
|
22
|
-
const object_shape_item_node_1 = require("../ast/type/object-shape-item-node");
|
|
23
|
-
const object_shape_node_1 = require("../ast/type/object-shape-node");
|
|
24
|
-
const offset_access_type_node_1 = require("../ast/type/offset-access-type-node");
|
|
25
|
-
const this_type_node_1 = require("../ast/type/this-type-node");
|
|
26
|
-
const union_type_node_1 = require("../ast/type/union-type-node");
|
|
27
|
-
const types_1 = require("../ast/types");
|
|
28
|
-
const lexer_1 = require("../lexer/lexer");
|
|
29
|
-
const parser_exception_1 = require("./parser-exception");
|
|
30
|
-
const string_unescaper_1 = require("./string-unescaper");
|
|
31
|
-
class TypeParser {
|
|
32
|
-
constructor(constExprParser = null, usedAttributes = {}) {
|
|
33
|
-
var _a, _b;
|
|
34
|
-
this.constExprParser = constExprParser;
|
|
35
|
-
this.useLinesAttributes = (_a = usedAttributes.lines) !== null && _a !== void 0 ? _a : false;
|
|
36
|
-
this.useIndexAttributes = (_b = usedAttributes.indexes) !== null && _b !== void 0 ? _b : false;
|
|
37
|
-
}
|
|
38
|
-
parse(tokens) {
|
|
39
|
-
var _a;
|
|
40
|
-
const startLine = tokens.currentTokenLine();
|
|
41
|
-
const startIndex = tokens.currentTokenIndex();
|
|
42
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_NULLABLE)) {
|
|
43
|
-
return this.parseNullable(tokens);
|
|
44
|
-
}
|
|
45
|
-
let type = this.parseAtomic(tokens);
|
|
46
|
-
tokens.pushSavePoint();
|
|
47
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
48
|
-
let enrichedType = null;
|
|
49
|
-
try {
|
|
50
|
-
enrichedType = this.enrichTypeOnUnionOrIntersection(tokens, type);
|
|
51
|
-
}
|
|
52
|
-
catch (_b) {
|
|
53
|
-
enrichedType = null;
|
|
54
|
-
}
|
|
55
|
-
if (enrichedType !== null) {
|
|
56
|
-
type = enrichedType;
|
|
57
|
-
tokens.dropSavePoint();
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
tokens.rollback();
|
|
61
|
-
type = (_a = this.enrichTypeOnUnionOrIntersection(tokens, type)) !== null && _a !== void 0 ? _a : type;
|
|
62
|
-
}
|
|
63
|
-
return this.enrichWithAttributes(tokens, type, startLine, startIndex);
|
|
64
|
-
}
|
|
65
|
-
enrichTypeOnUnionOrIntersection(tokens, type) {
|
|
66
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_UNION)) {
|
|
67
|
-
return this.parseUnion(tokens, type);
|
|
68
|
-
}
|
|
69
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_INTERSECTION)) {
|
|
70
|
-
return this.parseIntersection(tokens, type);
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
enrichWithAttributes(tokens, type, startLine, startIndex) {
|
|
75
|
-
if (this.useLinesAttributes) {
|
|
76
|
-
type.setAttribute(types_1.Attribute.START_LINE, startLine);
|
|
77
|
-
type.setAttribute(types_1.Attribute.END_LINE, tokens.currentTokenLine());
|
|
78
|
-
}
|
|
79
|
-
tokens.flushComments();
|
|
80
|
-
if (this.useIndexAttributes) {
|
|
81
|
-
type.setAttribute(types_1.Attribute.START_INDEX, startIndex);
|
|
82
|
-
type.setAttribute(types_1.Attribute.END_INDEX, tokens.endIndexOfLastRelevantToken());
|
|
83
|
-
}
|
|
84
|
-
return type;
|
|
85
|
-
}
|
|
86
|
-
parseTemplateTagValue(tokens, parseDescription) {
|
|
87
|
-
const name = tokens.currentTokenValue();
|
|
88
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER);
|
|
89
|
-
let upperBound = null;
|
|
90
|
-
let lowerBound = null;
|
|
91
|
-
if (tokens.tryConsumeTokenValue('of') ||
|
|
92
|
-
tokens.tryConsumeTokenValue('as')) {
|
|
93
|
-
upperBound = this.parse(tokens);
|
|
94
|
-
}
|
|
95
|
-
if (tokens.tryConsumeTokenValue('super')) {
|
|
96
|
-
lowerBound = this.parse(tokens);
|
|
97
|
-
}
|
|
98
|
-
let defaultValue = null;
|
|
99
|
-
if (tokens.tryConsumeTokenValue('=')) {
|
|
100
|
-
defaultValue = this.parse(tokens);
|
|
101
|
-
}
|
|
102
|
-
let description = '';
|
|
103
|
-
if (parseDescription) {
|
|
104
|
-
description = parseDescription(tokens);
|
|
105
|
-
}
|
|
106
|
-
if (name === '') {
|
|
107
|
-
throw new Error('Template tag name cannot be empty.');
|
|
108
|
-
}
|
|
109
|
-
return new template_tag_value_node_1.TemplateTagValueNode(name, upperBound, description, defaultValue, lowerBound);
|
|
110
|
-
}
|
|
111
|
-
subParse(tokens) {
|
|
112
|
-
const startLine = tokens.currentTokenLine();
|
|
113
|
-
const startIndex = tokens.currentTokenIndex();
|
|
114
|
-
let type;
|
|
115
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_NULLABLE)) {
|
|
116
|
-
type = this.parseNullable(tokens);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
type = this.parseAtomic(tokens);
|
|
120
|
-
if (tokens.isCurrentTokenValue('is')) {
|
|
121
|
-
type = this.parseConditional(tokens, type);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
125
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_UNION)) {
|
|
126
|
-
type = this.subParseUnion(tokens, type);
|
|
127
|
-
}
|
|
128
|
-
else if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_INTERSECTION)) {
|
|
129
|
-
type = this.subParseIntersection(tokens, type);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return this.enrichWithAttributes(tokens, type, startLine, startIndex);
|
|
134
|
-
}
|
|
135
|
-
parseAtomic(tokens) {
|
|
136
|
-
const startLine = tokens.currentTokenLine();
|
|
137
|
-
const startIndex = tokens.currentTokenIndex();
|
|
138
|
-
let type;
|
|
139
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_OPEN_PARENTHESES)) {
|
|
140
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
141
|
-
type = this.subParse(tokens);
|
|
142
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
143
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_PARENTHESES);
|
|
144
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
145
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, type);
|
|
146
|
-
}
|
|
147
|
-
return this.enrichWithAttributes(tokens, type, startLine, startIndex);
|
|
148
|
-
}
|
|
149
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_THIS_VARIABLE)) {
|
|
150
|
-
type = new this_type_node_1.ThisTypeNode();
|
|
151
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
152
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, this.enrichWithAttributes(tokens, type, startLine, startIndex));
|
|
153
|
-
}
|
|
154
|
-
return this.enrichWithAttributes(tokens, type, startLine, startIndex);
|
|
155
|
-
}
|
|
156
|
-
const currentTokenValue = tokens.currentTokenValue();
|
|
157
|
-
tokens.pushSavePoint();
|
|
158
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER)) {
|
|
159
|
-
const identifierTypeNode = new identifier_type_node_1.IdentifierTypeNode(currentTokenValue);
|
|
160
|
-
type = identifierTypeNode;
|
|
161
|
-
if (!tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_DOUBLE_COLON)) {
|
|
162
|
-
tokens.dropSavePoint();
|
|
163
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET)) {
|
|
164
|
-
tokens.pushSavePoint();
|
|
165
|
-
const isHtml = this.isHtml(tokens);
|
|
166
|
-
tokens.rollback();
|
|
167
|
-
if (isHtml) {
|
|
168
|
-
return this.enrichWithAttributes(tokens, type, startLine, startIndex);
|
|
169
|
-
}
|
|
170
|
-
const origType = type;
|
|
171
|
-
type = this.tryParseCallable(tokens, identifierTypeNode, true);
|
|
172
|
-
if (type === origType) {
|
|
173
|
-
type = this.parseGeneric(tokens, identifierTypeNode);
|
|
174
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
175
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, type);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
else if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_PARENTHESES)) {
|
|
180
|
-
type = this.tryParseCallable(tokens, identifierTypeNode, false);
|
|
181
|
-
}
|
|
182
|
-
else if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
183
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, type);
|
|
184
|
-
}
|
|
185
|
-
else if ([
|
|
186
|
-
'array',
|
|
187
|
-
'list',
|
|
188
|
-
'non-empty-array',
|
|
189
|
-
'non-empty-list',
|
|
190
|
-
'object',
|
|
191
|
-
].includes(identifierTypeNode.name) &&
|
|
192
|
-
tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_CURLY_BRACKET) &&
|
|
193
|
-
!tokens.isPrecededByHorizontalWhitespace()) {
|
|
194
|
-
if (identifierTypeNode.name === 'object') {
|
|
195
|
-
type = this.parseObjectShape(tokens);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
type = this.parseArrayShape(tokens, type, identifierTypeNode.name);
|
|
199
|
-
}
|
|
200
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
201
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, this.enrichWithAttributes(tokens, type, startLine, startIndex));
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return this.enrichWithAttributes(tokens, type, startLine, startIndex);
|
|
205
|
-
}
|
|
206
|
-
tokens.rollback();
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
tokens.dropSavePoint();
|
|
210
|
-
}
|
|
211
|
-
const exception = new parser_exception_1.ParserException(tokens.currentTokenValue(), tokens.currentTokenType(), tokens.currentTokenOffset(), lexer_1.Lexer.TOKEN_IDENTIFIER, null, tokens.currentTokenLine());
|
|
212
|
-
if (this.constExprParser === null) {
|
|
213
|
-
throw exception;
|
|
214
|
-
}
|
|
215
|
-
try {
|
|
216
|
-
const constExpr = this.constExprParser.parse(tokens);
|
|
217
|
-
if (constExpr instanceof const_expr_array_node_1.ConstExprArrayNode) {
|
|
218
|
-
throw exception;
|
|
219
|
-
}
|
|
220
|
-
return this.enrichWithAttributes(tokens, new const_type_node_1.ConstTypeNode(constExpr), startLine, startIndex);
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
exception.cause = error;
|
|
224
|
-
throw exception;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
parseUnion(tokens, type) {
|
|
228
|
-
const types = [type];
|
|
229
|
-
while (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_UNION)) {
|
|
230
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
231
|
-
types.push(this.parseAtomic(tokens));
|
|
232
|
-
}
|
|
233
|
-
return new union_type_node_1.UnionTypeNode(types);
|
|
234
|
-
}
|
|
235
|
-
subParseUnion(tokens, type) {
|
|
236
|
-
const types = [type];
|
|
237
|
-
while (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_UNION)) {
|
|
238
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
239
|
-
types.push(this.parseAtomic(tokens));
|
|
240
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
241
|
-
}
|
|
242
|
-
return new union_type_node_1.UnionTypeNode(types);
|
|
243
|
-
}
|
|
244
|
-
parseIntersection(tokens, type) {
|
|
245
|
-
const types = [type];
|
|
246
|
-
while (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_INTERSECTION)) {
|
|
247
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
248
|
-
types.push(this.parseAtomic(tokens));
|
|
249
|
-
}
|
|
250
|
-
return new intersection_type_node_1.IntersectionTypeNode(types);
|
|
251
|
-
}
|
|
252
|
-
subParseIntersection(tokens, type) {
|
|
253
|
-
const types = [type];
|
|
254
|
-
while (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_INTERSECTION)) {
|
|
255
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
256
|
-
types.push(this.parseAtomic(tokens));
|
|
257
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
258
|
-
}
|
|
259
|
-
return new intersection_type_node_1.IntersectionTypeNode(types);
|
|
260
|
-
}
|
|
261
|
-
parseConditional(tokens, subjectType) {
|
|
262
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER);
|
|
263
|
-
let negated = false;
|
|
264
|
-
if (tokens.isCurrentTokenValue('not')) {
|
|
265
|
-
negated = true;
|
|
266
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER);
|
|
267
|
-
}
|
|
268
|
-
const targetType = this.parse(tokens);
|
|
269
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
270
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_NULLABLE);
|
|
271
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
272
|
-
const ifType = this.parse(tokens);
|
|
273
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
274
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_COLON);
|
|
275
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
276
|
-
const elseType = this.subParse(tokens);
|
|
277
|
-
return new conditional_type_node_1.ConditionalTypeNode(subjectType, targetType, ifType, elseType, negated);
|
|
278
|
-
}
|
|
279
|
-
parseConditionalForParameter(tokens, parameterName) {
|
|
280
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_VARIABLE);
|
|
281
|
-
tokens.consumeTokenValue(lexer_1.Lexer.TOKEN_IDENTIFIER, 'is');
|
|
282
|
-
let negated = false;
|
|
283
|
-
if (tokens.isCurrentTokenValue('not')) {
|
|
284
|
-
negated = true;
|
|
285
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER);
|
|
286
|
-
}
|
|
287
|
-
const targetType = this.parse(tokens);
|
|
288
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
289
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_NULLABLE);
|
|
290
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
291
|
-
const ifType = this.parse(tokens);
|
|
292
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
293
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_COLON);
|
|
294
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
295
|
-
const elseType = this.subParse(tokens);
|
|
296
|
-
return new conditional_type_for_parameter_node_1.ConditionalTypeForParameterNode(parameterName, targetType, ifType, elseType, negated);
|
|
297
|
-
}
|
|
298
|
-
parseNullable(tokens) {
|
|
299
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_NULLABLE);
|
|
300
|
-
const type = this.parseAtomic(tokens);
|
|
301
|
-
return new nullable_type_node_1.NullableTypeNode(type);
|
|
302
|
-
}
|
|
303
|
-
isHtml(tokens) {
|
|
304
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET);
|
|
305
|
-
if (!tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER)) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
const htmlTagName = tokens.currentTokenValue();
|
|
309
|
-
tokens.next();
|
|
310
|
-
if (!tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_ANGLE_BRACKET)) {
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
while (!tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_END)) {
|
|
314
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET) &&
|
|
315
|
-
tokens.currentTokenValue().includes(`/${htmlTagName}>`)) {
|
|
316
|
-
return true;
|
|
317
|
-
}
|
|
318
|
-
tokens.next();
|
|
319
|
-
}
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
parseGeneric(tokens, baseType) {
|
|
323
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET);
|
|
324
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
325
|
-
const genericTypes = [];
|
|
326
|
-
const variances = [];
|
|
327
|
-
const [genericType, variance] = this.parseGenericTypeArgument(tokens);
|
|
328
|
-
genericTypes.push(genericType);
|
|
329
|
-
variances.push(variance);
|
|
330
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
331
|
-
while (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_COMMA)) {
|
|
332
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
333
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_ANGLE_BRACKET)) {
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
const [genericTypeToAddInWhileLoop, varianceToAddInWhileLoop] = this.parseGenericTypeArgument(tokens);
|
|
337
|
-
genericTypes.push(genericTypeToAddInWhileLoop);
|
|
338
|
-
variances.push(varianceToAddInWhileLoop);
|
|
339
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
340
|
-
}
|
|
341
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
342
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_ANGLE_BRACKET);
|
|
343
|
-
const type = new generic_type_node_1.GenericTypeNode(baseType, genericTypes, variances);
|
|
344
|
-
const startLine = baseType.getAttribute(types_1.Attribute.START_LINE);
|
|
345
|
-
const startIndex = baseType.getAttribute(types_1.Attribute.START_INDEX);
|
|
346
|
-
if (startLine !== null && startIndex !== null) {
|
|
347
|
-
return this.enrichWithAttributes(tokens, type, baseType.getAttribute(types_1.Attribute.START_LINE), baseType.getAttribute(types_1.Attribute.START_INDEX));
|
|
348
|
-
}
|
|
349
|
-
return type;
|
|
350
|
-
}
|
|
351
|
-
parseGenericTypeArgument(tokens) {
|
|
352
|
-
const startLine = tokens.currentTokenLine();
|
|
353
|
-
const startIndex = tokens.currentTokenIndex();
|
|
354
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_WILDCARD)) {
|
|
355
|
-
return [
|
|
356
|
-
this.enrichWithAttributes(tokens, new identifier_type_node_1.IdentifierTypeNode('mixed'), startLine, startIndex),
|
|
357
|
-
generic_type_node_1.GenericTypeNode.VARIANCE_BIVARIANT,
|
|
358
|
-
];
|
|
359
|
-
}
|
|
360
|
-
let variance;
|
|
361
|
-
if (tokens.tryConsumeTokenValue('contravariant')) {
|
|
362
|
-
variance = generic_type_node_1.GenericTypeNode.VARIANCE_CONTRAVARIANT;
|
|
363
|
-
}
|
|
364
|
-
else if (tokens.tryConsumeTokenValue('covariant')) {
|
|
365
|
-
variance = generic_type_node_1.GenericTypeNode.VARIANCE_COVARIANT;
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
variance = generic_type_node_1.GenericTypeNode.VARIANCE_INVARIANT;
|
|
369
|
-
}
|
|
370
|
-
const type = this.parse(tokens);
|
|
371
|
-
return [type, variance];
|
|
372
|
-
}
|
|
373
|
-
parseCallable(tokens, identifier, hasTemplate) {
|
|
374
|
-
const templates = hasTemplate ? this.parseCallableTemplates(tokens) : [];
|
|
375
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_PARENTHESES);
|
|
376
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
377
|
-
const parameters = [];
|
|
378
|
-
if (!tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_CLOSE_PARENTHESES)) {
|
|
379
|
-
parameters.push(this.parseCallableParameter(tokens));
|
|
380
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
381
|
-
while (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_COMMA)) {
|
|
382
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
383
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_CLOSE_PARENTHESES)) {
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
parameters.push(this.parseCallableParameter(tokens));
|
|
387
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_PARENTHESES);
|
|
391
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_COLON);
|
|
392
|
-
const startLine = tokens.currentTokenLine();
|
|
393
|
-
const startIndex = tokens.currentTokenIndex();
|
|
394
|
-
const returnType = this.enrichWithAttributes(tokens, this.parseCallableReturnType(tokens), startLine, startIndex);
|
|
395
|
-
return new callable_type_node_1.CallableTypeNode(identifier, parameters, returnType, templates);
|
|
396
|
-
}
|
|
397
|
-
parseCallableTemplates(tokens) {
|
|
398
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET);
|
|
399
|
-
const templates = [];
|
|
400
|
-
let isFirst = true;
|
|
401
|
-
while (isFirst || tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_COMMA)) {
|
|
402
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
403
|
-
if (!isFirst &&
|
|
404
|
-
tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_CLOSE_ANGLE_BRACKET)) {
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
isFirst = false;
|
|
408
|
-
templates.push(this.parseCallableTemplateArgument(tokens));
|
|
409
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
410
|
-
}
|
|
411
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_ANGLE_BRACKET);
|
|
412
|
-
return templates;
|
|
413
|
-
}
|
|
414
|
-
parseCallableTemplateArgument(tokens) {
|
|
415
|
-
const startLine = tokens.currentTokenLine();
|
|
416
|
-
const startIndex = tokens.currentTokenIndex();
|
|
417
|
-
return this.enrichWithAttributes(tokens, this.parseTemplateTagValue(tokens), startLine, startIndex);
|
|
418
|
-
}
|
|
419
|
-
parseCallableParameter(tokens) {
|
|
420
|
-
const startLine = tokens.currentTokenLine();
|
|
421
|
-
const startIndex = tokens.currentTokenIndex();
|
|
422
|
-
const type = this.parse(tokens);
|
|
423
|
-
const isReference = tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_REFERENCE);
|
|
424
|
-
const isVariadic = tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_VARIADIC);
|
|
425
|
-
let parameterName = '';
|
|
426
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_VARIABLE)) {
|
|
427
|
-
parameterName = tokens.currentTokenValue();
|
|
428
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_VARIABLE);
|
|
429
|
-
}
|
|
430
|
-
const isOptional = tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_EQUAL);
|
|
431
|
-
return this.enrichWithAttributes(tokens, new callable_type_parameter_node_1.CallableTypeParameterNode(type, isReference, isVariadic, parameterName, isOptional), startLine, startIndex);
|
|
432
|
-
}
|
|
433
|
-
parseCallableReturnType(tokens) {
|
|
434
|
-
const startLine = tokens.currentTokenLine();
|
|
435
|
-
const startIndex = tokens.currentTokenIndex();
|
|
436
|
-
let type;
|
|
437
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_NULLABLE)) {
|
|
438
|
-
return this.parseNullable(tokens);
|
|
439
|
-
}
|
|
440
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_OPEN_PARENTHESES)) {
|
|
441
|
-
type = this.parse(tokens);
|
|
442
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_PARENTHESES);
|
|
443
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
444
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, type);
|
|
445
|
-
}
|
|
446
|
-
return type;
|
|
447
|
-
}
|
|
448
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_THIS_VARIABLE)) {
|
|
449
|
-
type = new this_type_node_1.ThisTypeNode();
|
|
450
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
451
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, this.enrichWithAttributes(tokens, type, startLine, startIndex));
|
|
452
|
-
}
|
|
453
|
-
return type;
|
|
454
|
-
}
|
|
455
|
-
const currentTokenValue = tokens.currentTokenValue();
|
|
456
|
-
tokens.pushSavePoint();
|
|
457
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER)) {
|
|
458
|
-
type = new identifier_type_node_1.IdentifierTypeNode(currentTokenValue);
|
|
459
|
-
if (!tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_DOUBLE_COLON)) {
|
|
460
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET)) {
|
|
461
|
-
type = this.parseGeneric(tokens, this.enrichWithAttributes(tokens, type, startLine, startIndex));
|
|
462
|
-
}
|
|
463
|
-
else if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
464
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, this.enrichWithAttributes(tokens, type, startLine, startIndex));
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
tokens.rollback();
|
|
469
|
-
}
|
|
470
|
-
return type;
|
|
471
|
-
}
|
|
472
|
-
tokens.dropSavePoint();
|
|
473
|
-
const exception = new parser_exception_1.ParserException(tokens.currentTokenValue(), tokens.currentTokenType(), tokens.currentTokenOffset(), lexer_1.Lexer.TOKEN_IDENTIFIER, null, tokens.currentTokenLine());
|
|
474
|
-
if (this.constExprParser === null) {
|
|
475
|
-
throw exception;
|
|
476
|
-
}
|
|
477
|
-
if (this.constExprParser === null) {
|
|
478
|
-
throw exception;
|
|
479
|
-
}
|
|
480
|
-
try {
|
|
481
|
-
const constExpr = this.constExprParser.parse(tokens);
|
|
482
|
-
if (constExpr instanceof const_expr_array_node_1.ConstExprArrayNode) {
|
|
483
|
-
throw exception;
|
|
484
|
-
}
|
|
485
|
-
type = new const_type_node_1.ConstTypeNode(constExpr);
|
|
486
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
487
|
-
type = this.tryParseArrayOrOffsetAccess(tokens, this.enrichWithAttributes(tokens, type, startLine, startIndex));
|
|
488
|
-
}
|
|
489
|
-
return type;
|
|
490
|
-
}
|
|
491
|
-
catch (e) {
|
|
492
|
-
if (e instanceof Error) {
|
|
493
|
-
throw exception;
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
throw e;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
tryParseCallable(tokens, identifier, hasTemplate) {
|
|
501
|
-
try {
|
|
502
|
-
tokens.pushSavePoint();
|
|
503
|
-
const type = this.parseCallable(tokens, identifier, hasTemplate);
|
|
504
|
-
tokens.dropSavePoint();
|
|
505
|
-
return type;
|
|
506
|
-
}
|
|
507
|
-
catch (e) {
|
|
508
|
-
if (e instanceof parser_exception_1.ParserException) {
|
|
509
|
-
tokens.rollback();
|
|
510
|
-
return identifier;
|
|
511
|
-
}
|
|
512
|
-
throw e;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
tryParseArrayOrOffsetAccess(tokens, type) {
|
|
516
|
-
try {
|
|
517
|
-
while (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET)) {
|
|
518
|
-
tokens.pushSavePoint();
|
|
519
|
-
const canBeOffsetAccessType = !tokens.isPrecededByHorizontalWhitespace();
|
|
520
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_SQUARE_BRACKET);
|
|
521
|
-
if (canBeOffsetAccessType &&
|
|
522
|
-
!tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_CLOSE_SQUARE_BRACKET)) {
|
|
523
|
-
const offset = this.parse(tokens);
|
|
524
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_SQUARE_BRACKET);
|
|
525
|
-
tokens.dropSavePoint();
|
|
526
|
-
type = new offset_access_type_node_1.OffsetAccessTypeNode(type, offset);
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_SQUARE_BRACKET);
|
|
530
|
-
tokens.dropSavePoint();
|
|
531
|
-
type = new array_type_node_1.ArrayTypeNode(type);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
catch (e) {
|
|
536
|
-
if (e instanceof parser_exception_1.ParserException) {
|
|
537
|
-
tokens.rollback();
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
throw e;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
return type;
|
|
544
|
-
}
|
|
545
|
-
parseArrayShape(tokens, type, kind) {
|
|
546
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_CURLY_BRACKET);
|
|
547
|
-
const items = [];
|
|
548
|
-
let sealed = true;
|
|
549
|
-
let unsealedType = null;
|
|
550
|
-
let done = false;
|
|
551
|
-
do {
|
|
552
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
553
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_CURLY_BRACKET)) {
|
|
554
|
-
return new array_shape_node_1.ArrayShapeNode(items, true, kind);
|
|
555
|
-
}
|
|
556
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_VARIADIC)) {
|
|
557
|
-
sealed = false;
|
|
558
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
559
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET)) {
|
|
560
|
-
if (kind === array_shape_node_1.ArrayShapeNodeKind.ARRAY ||
|
|
561
|
-
kind === array_shape_node_1.ArrayShapeNodeKind.NON_EMPTY_ARRAY) {
|
|
562
|
-
unsealedType = this.parseArrayShapeUnsealedType(tokens);
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
unsealedType = this.parseListShapeUnsealedType(tokens);
|
|
566
|
-
}
|
|
567
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
568
|
-
}
|
|
569
|
-
tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_COMMA);
|
|
570
|
-
break;
|
|
571
|
-
}
|
|
572
|
-
items.push(this.parseArrayShapeItem(tokens));
|
|
573
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
574
|
-
if (!tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_COMMA)) {
|
|
575
|
-
done = true;
|
|
576
|
-
}
|
|
577
|
-
} while (!done);
|
|
578
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
579
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_CURLY_BRACKET);
|
|
580
|
-
if (sealed) {
|
|
581
|
-
return new array_shape_node_1.ArrayShapeNode(items, true, kind);
|
|
582
|
-
}
|
|
583
|
-
return new array_shape_node_1.ArrayShapeNode(items, false, kind, unsealedType);
|
|
584
|
-
}
|
|
585
|
-
parseArrayShapeItem(tokens) {
|
|
586
|
-
const startLine = tokens.currentTokenLine();
|
|
587
|
-
const startIndex = tokens.currentTokenIndex();
|
|
588
|
-
try {
|
|
589
|
-
tokens.pushSavePoint();
|
|
590
|
-
const key = this.parseArrayShapeKey(tokens);
|
|
591
|
-
const optional = tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_NULLABLE);
|
|
592
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_COLON);
|
|
593
|
-
const value = this.parse(tokens);
|
|
594
|
-
tokens.dropSavePoint();
|
|
595
|
-
return this.enrichWithAttributes(tokens, new array_shape_item_node_1.ArrayShapeItemNode(key, optional, value), startLine, startIndex);
|
|
596
|
-
}
|
|
597
|
-
catch (e) {
|
|
598
|
-
if (e instanceof parser_exception_1.ParserException) {
|
|
599
|
-
tokens.rollback();
|
|
600
|
-
const value = this.parse(tokens);
|
|
601
|
-
return this.enrichWithAttributes(tokens, new array_shape_item_node_1.ArrayShapeItemNode(null, false, value), startLine, startIndex);
|
|
602
|
-
}
|
|
603
|
-
throw e;
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
parseArrayShapeKey(tokens) {
|
|
607
|
-
const startLine = tokens.currentTokenLine();
|
|
608
|
-
const startIndex = tokens.currentTokenIndex();
|
|
609
|
-
let key;
|
|
610
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_INTEGER)) {
|
|
611
|
-
key = new const_expr_integer_node_1.ConstExprIntegerNode(tokens.currentTokenValue().replaceAll('_', ''));
|
|
612
|
-
tokens.next();
|
|
613
|
-
}
|
|
614
|
-
else if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
|
|
615
|
-
key = new const_expr_string_node_1.ConstExprStringNode(string_unescaper_1.StringUnescaper.unescapeString(tokens.currentTokenValue()), const_expr_string_node_1.ConstExprStringNode.SINGLE_QUOTED);
|
|
616
|
-
tokens.next();
|
|
617
|
-
}
|
|
618
|
-
else if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
|
|
619
|
-
key = new const_expr_string_node_1.ConstExprStringNode(string_unescaper_1.StringUnescaper.unescapeString(tokens.currentTokenValue()), const_expr_string_node_1.ConstExprStringNode.DOUBLE_QUOTED);
|
|
620
|
-
tokens.next();
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
const identifier = tokens.currentTokenValue();
|
|
624
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER);
|
|
625
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_DOUBLE_COLON)) {
|
|
626
|
-
const classConstantName = tokens.currentTokenValue();
|
|
627
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER);
|
|
628
|
-
key = new const_fetch_node_1.ConstFetchNode(identifier, classConstantName);
|
|
629
|
-
}
|
|
630
|
-
else {
|
|
631
|
-
key = new identifier_type_node_1.IdentifierTypeNode(identifier);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
return this.enrichWithAttributes(tokens, key, startLine, startIndex);
|
|
635
|
-
}
|
|
636
|
-
parseArrayShapeUnsealedType(tokens) {
|
|
637
|
-
const startLine = tokens.currentTokenLine();
|
|
638
|
-
const startIndex = tokens.currentTokenIndex();
|
|
639
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET);
|
|
640
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
641
|
-
let valueType = this.parse(tokens);
|
|
642
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
643
|
-
let keyType = null;
|
|
644
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_COMMA)) {
|
|
645
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
646
|
-
keyType = valueType;
|
|
647
|
-
valueType = this.parse(tokens);
|
|
648
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
649
|
-
}
|
|
650
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_ANGLE_BRACKET);
|
|
651
|
-
return this.enrichWithAttributes(tokens, new array_shape_unsealed_type_node_1.ArrayShapeUnsealedTypeNode(valueType, keyType), startLine, startIndex);
|
|
652
|
-
}
|
|
653
|
-
parseListShapeUnsealedType(tokens) {
|
|
654
|
-
const startLine = tokens.currentTokenLine();
|
|
655
|
-
const startIndex = tokens.currentTokenIndex();
|
|
656
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_ANGLE_BRACKET);
|
|
657
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
658
|
-
const valueType = this.parse(tokens);
|
|
659
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
660
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_ANGLE_BRACKET);
|
|
661
|
-
return this.enrichWithAttributes(tokens, new array_shape_unsealed_type_node_1.ArrayShapeUnsealedTypeNode(valueType, null), startLine, startIndex);
|
|
662
|
-
}
|
|
663
|
-
parseObjectShape(tokens) {
|
|
664
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_OPEN_CURLY_BRACKET);
|
|
665
|
-
const items = [];
|
|
666
|
-
do {
|
|
667
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
668
|
-
if (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_CURLY_BRACKET)) {
|
|
669
|
-
return new object_shape_node_1.ObjectShapeNode(items);
|
|
670
|
-
}
|
|
671
|
-
items.push(this.parseObjectShapeItem(tokens));
|
|
672
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
673
|
-
} while (tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_COMMA));
|
|
674
|
-
tokens.skipNewLineTokensAndConsumeComments();
|
|
675
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_CLOSE_CURLY_BRACKET);
|
|
676
|
-
return new object_shape_node_1.ObjectShapeNode(items);
|
|
677
|
-
}
|
|
678
|
-
parseObjectShapeItem(tokens) {
|
|
679
|
-
const startLine = tokens.currentTokenLine();
|
|
680
|
-
const startIndex = tokens.currentTokenIndex();
|
|
681
|
-
const key = this.parseObjectShapeKey(tokens);
|
|
682
|
-
const optional = tokens.tryConsumeTokenType(lexer_1.Lexer.TOKEN_NULLABLE);
|
|
683
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_COLON);
|
|
684
|
-
const value = this.parse(tokens);
|
|
685
|
-
return this.enrichWithAttributes(tokens, new object_shape_item_node_1.ObjectShapeItemNode(key, optional, value), startLine, startIndex);
|
|
686
|
-
}
|
|
687
|
-
parseObjectShapeKey(tokens) {
|
|
688
|
-
const startLine = tokens.currentTokenLine();
|
|
689
|
-
const startIndex = tokens.currentTokenIndex();
|
|
690
|
-
let key;
|
|
691
|
-
if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
|
|
692
|
-
key = new const_expr_string_node_1.ConstExprStringNode(string_unescaper_1.StringUnescaper.unescapeString(tokens.currentTokenValue()), const_expr_string_node_1.ConstExprStringNode.SINGLE_QUOTED);
|
|
693
|
-
tokens.next();
|
|
694
|
-
}
|
|
695
|
-
else if (tokens.isCurrentTokenType(lexer_1.Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
|
|
696
|
-
key = new const_expr_string_node_1.ConstExprStringNode(string_unescaper_1.StringUnescaper.unescapeString(tokens.currentTokenValue()), const_expr_string_node_1.ConstExprStringNode.DOUBLE_QUOTED);
|
|
697
|
-
tokens.next();
|
|
698
|
-
}
|
|
699
|
-
else {
|
|
700
|
-
key = new identifier_type_node_1.IdentifierTypeNode(tokens.currentTokenValue());
|
|
701
|
-
tokens.consumeTokenType(lexer_1.Lexer.TOKEN_IDENTIFIER);
|
|
702
|
-
}
|
|
703
|
-
return this.enrichWithAttributes(tokens, key, startLine, startIndex);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
exports.TypeParser = TypeParser;
|