@rightcapital/phpdoc-parser 0.3.3-feature-add-basic-ci.7.0 → 0.3.3-feature-add-basic-ci.8.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/index.d.ts +73 -0
- package/dist/index.js +0 -1
- package/dist/phpdoc-parser/ast/abstract-node-visitor.d.ts +8 -0
- package/dist/phpdoc-parser/ast/abstract-node-visitor.js +18 -0
- package/dist/phpdoc-parser/ast/base-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/base-node.js +27 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-item-node.d.ts +8 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-item-node.js +21 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-node.d.ts +8 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-array-node.js +17 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-false-node.d.ts +5 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-false-node.js +13 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-float-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-float-node.js +17 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-integer-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-integer-node.js +17 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-node.d.ts +25 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-node.js +43 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-null-node.d.ts +5 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-null-node.js +13 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-string-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-string-node.js +17 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-true-node.d.ts +5 -0
- package/dist/phpdoc-parser/ast/const-expr/const-expr-true-node.js +13 -0
- package/dist/phpdoc-parser/ast/const-expr/const-fetch-node.d.ts +8 -0
- package/dist/phpdoc-parser/ast/const-expr/const-fetch-node.js +21 -0
- package/dist/phpdoc-parser/ast/const-expr/quote-aware-const-expr-string-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/const-expr/quote-aware-const-expr-string-node.js +47 -0
- package/dist/phpdoc-parser/ast/node-traverser.d.ts +11 -0
- package/dist/phpdoc-parser/ast/node-traverser.js +216 -0
- package/dist/phpdoc-parser/ast/node-visitor/cloning-visitor.d.ts +5 -0
- package/dist/phpdoc-parser/ast/node-visitor/cloning-visitor.js +14 -0
- package/dist/phpdoc-parser/ast/node-visitor.d.ts +11 -0
- package/dist/phpdoc-parser/ast/node-visitor.js +2 -0
- package/dist/phpdoc-parser/ast/node.d.ts +6 -0
- package/dist/phpdoc-parser/ast/node.js +2 -0
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-method-value-node.d.ts +13 -0
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-method-value-node.js +24 -0
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-property-value-node.d.ts +13 -0
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-property-value-node.js +24 -0
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-value-node.d.ts +12 -0
- package/dist/phpdoc-parser/ast/php-doc/assert-tag-value-node.js +23 -0
- package/dist/phpdoc-parser/ast/php-doc/deprecated-tag-value-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/php-doc/deprecated-tag-value-node.js +17 -0
- package/dist/phpdoc-parser/ast/php-doc/extends-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/extends-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/generic-tag-value-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/php-doc/generic-tag-value-node.js +17 -0
- package/dist/phpdoc-parser/ast/php-doc/implements-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/implements-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/invalid-tag-value-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/php-doc/invalid-tag-value-node.js +33 -0
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-node.d.ts +15 -0
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-node.js +27 -0
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-parameter-node.d.ts +13 -0
- package/dist/phpdoc-parser/ast/php-doc/method-tag-value-parameter-node.js +27 -0
- package/dist/phpdoc-parser/ast/php-doc/mixin-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/mixin-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/param-out-tag-value-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/php-doc/param-out-tag-value-node.js +19 -0
- package/dist/phpdoc-parser/ast/php-doc/param-tag-value-node.d.ts +12 -0
- package/dist/phpdoc-parser/ast/php-doc/param-tag-value-node.js +28 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-child-node.d.ts +4 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-child-node.js +10 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-node.d.ts +32 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-node.js +97 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-node.d.ts +56 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-node.js +90 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-value-node.d.ts +4 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-tag-value-node.js +10 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-text-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/php-doc/php-doc-text-node.js +17 -0
- package/dist/phpdoc-parser/ast/php-doc/property-tag-value-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/php-doc/property-tag-value-node.js +19 -0
- package/dist/phpdoc-parser/ast/php-doc/return-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/return-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/self-out-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/self-out-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/template-tag-value-node.d.ts +11 -0
- package/dist/phpdoc-parser/ast/php-doc/template-tag-value-node.js +24 -0
- package/dist/phpdoc-parser/ast/php-doc/throws-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/throws-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/type-alias-import-tag-value-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/php-doc/type-alias-import-tag-value-node.js +22 -0
- package/dist/phpdoc-parser/ast/php-doc/type-alias-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/type-alias-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/typeless-param-tag-value-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/php-doc/typeless-param-tag-value-node.js +22 -0
- package/dist/phpdoc-parser/ast/php-doc/uses-tag-value-node.d.ts +9 -0
- package/dist/phpdoc-parser/ast/php-doc/uses-tag-value-node.js +18 -0
- package/dist/phpdoc-parser/ast/php-doc/var-tag-value-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/php-doc/var-tag-value-node.js +19 -0
- package/dist/phpdoc-parser/ast/type/array-shape-item-node.d.ts +12 -0
- package/dist/phpdoc-parser/ast/type/array-shape-item-node.js +22 -0
- package/dist/phpdoc-parser/ast/type/array-shape-node.d.ts +14 -0
- package/dist/phpdoc-parser/ast/type/array-shape-node.js +31 -0
- package/dist/phpdoc-parser/ast/type/array-type-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/type/array-type-node.js +25 -0
- package/dist/phpdoc-parser/ast/type/callable-type-node.d.ts +11 -0
- package/dist/phpdoc-parser/ast/type/callable-type-node.js +24 -0
- package/dist/phpdoc-parser/ast/type/callable-type-parameter-node.d.ts +11 -0
- package/dist/phpdoc-parser/ast/type/callable-type-parameter-node.js +26 -0
- package/dist/phpdoc-parser/ast/type/conditional-type-for-parameter-node.d.ts +11 -0
- package/dist/phpdoc-parser/ast/type/conditional-type-for-parameter-node.js +21 -0
- package/dist/phpdoc-parser/ast/type/conditional-type-node.d.ts +11 -0
- package/dist/phpdoc-parser/ast/type/conditional-type-node.js +21 -0
- package/dist/phpdoc-parser/ast/type/const-type-node.d.ts +8 -0
- package/dist/phpdoc-parser/ast/type/const-type-node.js +17 -0
- package/dist/phpdoc-parser/ast/type/generic-type-node.d.ts +15 -0
- package/dist/phpdoc-parser/ast/type/generic-type-node.js +37 -0
- package/dist/phpdoc-parser/ast/type/identifier-type-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/type/identifier-type-node.js +17 -0
- package/dist/phpdoc-parser/ast/type/intersection-type-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/type/intersection-type-node.js +25 -0
- package/dist/phpdoc-parser/ast/type/invalid-type-node.d.ts +10 -0
- package/dist/phpdoc-parser/ast/type/invalid-type-node.js +29 -0
- package/dist/phpdoc-parser/ast/type/nullable-type-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/type/nullable-type-node.js +17 -0
- package/dist/phpdoc-parser/ast/type/object-shape-item-node.d.ts +11 -0
- package/dist/phpdoc-parser/ast/type/object-shape-item-node.js +22 -0
- package/dist/phpdoc-parser/ast/type/object-shape-node.d.ts +8 -0
- package/dist/phpdoc-parser/ast/type/object-shape-node.js +17 -0
- package/dist/phpdoc-parser/ast/type/offset-access-type-node.d.ts +8 -0
- package/dist/phpdoc-parser/ast/type/offset-access-type-node.js +26 -0
- package/dist/phpdoc-parser/ast/type/this-type-node.d.ts +5 -0
- package/dist/phpdoc-parser/ast/type/this-type-node.js +13 -0
- package/dist/phpdoc-parser/ast/type/type-node.d.ts +40 -0
- package/dist/phpdoc-parser/ast/type/type-node.js +64 -0
- package/dist/phpdoc-parser/ast/type/union-type-node.d.ts +7 -0
- package/dist/phpdoc-parser/ast/type/union-type-node.js +25 -0
- package/dist/phpdoc-parser/ast/types.d.ts +13 -0
- package/dist/phpdoc-parser/ast/types.js +18 -0
- package/dist/phpdoc-parser/lexer/lexer.d.ts +46 -0
- package/dist/phpdoc-parser/lexer/lexer.js +143 -0
- package/dist/phpdoc-parser/parser/const-expr-parser.d.ts +16 -0
- package/dist/phpdoc-parser/parser/const-expr-parser.js +146 -0
- package/dist/phpdoc-parser/parser/node-collecting-visitor.d.ts +7 -0
- package/dist/phpdoc-parser/parser/node-collecting-visitor.js +15 -0
- package/dist/phpdoc-parser/parser/parser-exception.d.ts +16 -0
- package/dist/phpdoc-parser/parser/parser-exception.js +44 -0
- package/dist/phpdoc-parser/parser/php-doc-parser.d.ts +47 -0
- package/dist/phpdoc-parser/parser/php-doc-parser.js +558 -0
- package/dist/phpdoc-parser/parser/string-unescaper.d.ts +6 -0
- package/dist/phpdoc-parser/parser/string-unescaper.js +41 -0
- package/dist/phpdoc-parser/parser/token-iterator.d.ts +40 -0
- package/dist/phpdoc-parser/parser/token-iterator.js +215 -0
- package/dist/phpdoc-parser/parser/type-parser.d.ts +41 -0
- package/dist/phpdoc-parser/parser/type-parser.js +576 -0
- package/dist/phpdoc-parser/printer/diff-elem.d.ts +12 -0
- package/dist/phpdoc-parser/printer/diff-elem.js +19 -0
- package/dist/phpdoc-parser/printer/differ.d.ts +10 -0
- package/dist/phpdoc-parser/printer/differ.js +111 -0
- package/dist/phpdoc-parser/printer/printer.d.ts +20 -0
- package/dist/phpdoc-parser/printer/printer.js +612 -0
- package/package.json +2 -2
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringUnescaper = void 0;
|
|
4
|
+
class StringUnescaper {
|
|
5
|
+
static unescapeString(input) {
|
|
6
|
+
const quote = input[0];
|
|
7
|
+
if (quote === "'") {
|
|
8
|
+
return input.slice(1, input.length - 1).replaceAll(/\\([\\\.])/g, '$1');
|
|
9
|
+
}
|
|
10
|
+
return this.parseEscapeSequences(input.slice(1, input.length - 1), '"');
|
|
11
|
+
}
|
|
12
|
+
static parseEscapeSequences(input, quote) {
|
|
13
|
+
input = input.replaceAll(new RegExp(`\\${quote}`, 'g'), quote);
|
|
14
|
+
return input.replaceAll(/\\([\\nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u\{([0-9a-fA-F]+)\})/g, (substring, ...matches) => {
|
|
15
|
+
const firstCaptureGroup = matches[0];
|
|
16
|
+
if (this.REPLACEMENTS[firstCaptureGroup]) {
|
|
17
|
+
return this.REPLACEMENTS[firstCaptureGroup];
|
|
18
|
+
}
|
|
19
|
+
if (firstCaptureGroup[0] === 'x' || firstCaptureGroup[0] === 'X') {
|
|
20
|
+
return String.fromCharCode(parseInt(firstCaptureGroup.slice(1), 16));
|
|
21
|
+
}
|
|
22
|
+
if (firstCaptureGroup[0] === 'u') {
|
|
23
|
+
return String.fromCharCode(parseInt(matches[1], 16));
|
|
24
|
+
}
|
|
25
|
+
return String.fromCharCode(parseInt(firstCaptureGroup, 8));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getType() {
|
|
29
|
+
return 'Scalar_String';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.StringUnescaper = StringUnescaper;
|
|
33
|
+
StringUnescaper.REPLACEMENTS = {
|
|
34
|
+
'\\': '\\',
|
|
35
|
+
n: '\n',
|
|
36
|
+
r: '\r',
|
|
37
|
+
t: '\t',
|
|
38
|
+
f: '\f',
|
|
39
|
+
v: '\v',
|
|
40
|
+
e: '\x1B',
|
|
41
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare class TokenIterator {
|
|
2
|
+
private tokens;
|
|
3
|
+
private index;
|
|
4
|
+
private savePoints;
|
|
5
|
+
private skippedTokenTypes;
|
|
6
|
+
private newline;
|
|
7
|
+
constructor(tokens: Array<[string, string, number]>, index?: number);
|
|
8
|
+
getTokens(): Array<[string, string, number]>;
|
|
9
|
+
getContentBetween(startPos: number, endPos: number): string;
|
|
10
|
+
getTokenCount(): number;
|
|
11
|
+
currentTokenValue(): string;
|
|
12
|
+
currentTokenType(): string;
|
|
13
|
+
currentTokenOffset(): number;
|
|
14
|
+
currentTokenLine(): number;
|
|
15
|
+
currentTokenIndex(): number;
|
|
16
|
+
endIndexOfLastRelevantToken(): number;
|
|
17
|
+
isCurrentTokenValue(tokenValue: string): boolean;
|
|
18
|
+
isCurrentTokenType(...tokenType: string[]): boolean;
|
|
19
|
+
isPrecededByHorizontalWhitespace(): boolean;
|
|
20
|
+
consumeTokenType(tokenType: string): void;
|
|
21
|
+
consumeTokenValue(tokenType: string, tokenValue: string): void;
|
|
22
|
+
tryConsumeTokenValue(tokenValue: string): boolean;
|
|
23
|
+
tryConsumeTokenType(tokenType: string): boolean;
|
|
24
|
+
private detectNewline;
|
|
25
|
+
getSkippedHorizontalWhiteSpaceIfAny(): string;
|
|
26
|
+
joinUntil(...tokenType: string[]): string;
|
|
27
|
+
next(): void;
|
|
28
|
+
private skipIrrelevantTokens;
|
|
29
|
+
addEndOfLineToSkippedTokens(): void;
|
|
30
|
+
removeEndOfLineFromSkippedTokens(): void;
|
|
31
|
+
forwardToTheEnd(): void;
|
|
32
|
+
pushSavePoint(): void;
|
|
33
|
+
dropSavePoint(): void;
|
|
34
|
+
rollback(): void;
|
|
35
|
+
throwError(expectedTokenType: string, expectedTokenValue?: string | null): void;
|
|
36
|
+
hasTokenImmediatelyBefore(pos: number, expectedTokenType: string): boolean;
|
|
37
|
+
hasTokenImmediatelyAfter(pos: number, expectedTokenType: string): boolean;
|
|
38
|
+
getDetectedNewline(): string | null;
|
|
39
|
+
hasParentheses(startPos: number, endPos: number): boolean;
|
|
40
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenIterator = void 0;
|
|
4
|
+
const parser_exception_1 = require("./parser-exception");
|
|
5
|
+
const lexer_1 = require("../lexer/lexer");
|
|
6
|
+
class TokenIterator {
|
|
7
|
+
constructor(tokens, index = 0) {
|
|
8
|
+
this.savePoints = [];
|
|
9
|
+
this.skippedTokenTypes = [lexer_1.Lexer.TOKEN_HORIZONTAL_WS];
|
|
10
|
+
this.newline = null;
|
|
11
|
+
this.tokens = tokens;
|
|
12
|
+
this.index = index;
|
|
13
|
+
this.skipIrrelevantTokens();
|
|
14
|
+
}
|
|
15
|
+
getTokens() {
|
|
16
|
+
return this.tokens;
|
|
17
|
+
}
|
|
18
|
+
getContentBetween(startPos, endPos) {
|
|
19
|
+
if (startPos < 0 || endPos > this.tokens.length) {
|
|
20
|
+
throw new Error('LogicException');
|
|
21
|
+
}
|
|
22
|
+
let content = '';
|
|
23
|
+
for (let i = startPos; i < endPos; i++) {
|
|
24
|
+
content += this.tokens[i][lexer_1.Lexer.VALUE_OFFSET];
|
|
25
|
+
}
|
|
26
|
+
return content;
|
|
27
|
+
}
|
|
28
|
+
getTokenCount() {
|
|
29
|
+
return this.tokens.length;
|
|
30
|
+
}
|
|
31
|
+
currentTokenValue() {
|
|
32
|
+
return this.tokens[this.index][lexer_1.Lexer.VALUE_OFFSET];
|
|
33
|
+
}
|
|
34
|
+
currentTokenType() {
|
|
35
|
+
return this.tokens[this.index][lexer_1.Lexer.TYPE_OFFSET];
|
|
36
|
+
}
|
|
37
|
+
currentTokenOffset() {
|
|
38
|
+
let offset = 0;
|
|
39
|
+
for (let i = 0; i < this.index; i++) {
|
|
40
|
+
offset += this.tokens[i][lexer_1.Lexer.VALUE_OFFSET].length;
|
|
41
|
+
}
|
|
42
|
+
return offset;
|
|
43
|
+
}
|
|
44
|
+
currentTokenLine() {
|
|
45
|
+
return this.tokens[this.index][lexer_1.Lexer.LINE_OFFSET];
|
|
46
|
+
}
|
|
47
|
+
currentTokenIndex() {
|
|
48
|
+
return this.index;
|
|
49
|
+
}
|
|
50
|
+
endIndexOfLastRelevantToken() {
|
|
51
|
+
let endIndex = this.currentTokenIndex();
|
|
52
|
+
endIndex--;
|
|
53
|
+
while (this.skippedTokenTypes.includes(this.tokens[endIndex][lexer_1.Lexer.TYPE_OFFSET])) {
|
|
54
|
+
if (!this.tokens[endIndex - 1]) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
endIndex--;
|
|
58
|
+
}
|
|
59
|
+
return endIndex;
|
|
60
|
+
}
|
|
61
|
+
isCurrentTokenValue(tokenValue) {
|
|
62
|
+
return this.tokens[this.index][lexer_1.Lexer.VALUE_OFFSET] === tokenValue;
|
|
63
|
+
}
|
|
64
|
+
isCurrentTokenType(...tokenType) {
|
|
65
|
+
return tokenType.includes(this.tokens[this.index][lexer_1.Lexer.TYPE_OFFSET]);
|
|
66
|
+
}
|
|
67
|
+
isPrecededByHorizontalWhitespace() {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
return (((_b = (_a = this.tokens[this.index - 1]) === null || _a === void 0 ? void 0 : _a[lexer_1.Lexer.TYPE_OFFSET]) !== null && _b !== void 0 ? _b : -1) ===
|
|
70
|
+
lexer_1.Lexer.TOKEN_HORIZONTAL_WS);
|
|
71
|
+
}
|
|
72
|
+
consumeTokenType(tokenType) {
|
|
73
|
+
if (this.tokens[this.index][lexer_1.Lexer.TYPE_OFFSET] !== tokenType) {
|
|
74
|
+
this.throwError(tokenType);
|
|
75
|
+
}
|
|
76
|
+
if (tokenType === lexer_1.Lexer.TOKEN_PHPDOC_EOL) {
|
|
77
|
+
if (this.newline === null) {
|
|
78
|
+
this.detectNewline();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.index++;
|
|
82
|
+
this.skipIrrelevantTokens();
|
|
83
|
+
}
|
|
84
|
+
consumeTokenValue(tokenType, tokenValue) {
|
|
85
|
+
if (this.tokens[this.index][lexer_1.Lexer.TYPE_OFFSET] !== tokenType ||
|
|
86
|
+
this.tokens[this.index][lexer_1.Lexer.VALUE_OFFSET] !== tokenValue) {
|
|
87
|
+
this.throwError(tokenType, tokenValue);
|
|
88
|
+
}
|
|
89
|
+
this.index++;
|
|
90
|
+
this.skipIrrelevantTokens();
|
|
91
|
+
}
|
|
92
|
+
tryConsumeTokenValue(tokenValue) {
|
|
93
|
+
if (this.tokens[this.index][lexer_1.Lexer.VALUE_OFFSET] !== tokenValue) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
this.index++;
|
|
97
|
+
this.skipIrrelevantTokens();
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
tryConsumeTokenType(tokenType) {
|
|
101
|
+
if (this.tokens[this.index][lexer_1.Lexer.TYPE_OFFSET] !== tokenType) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (tokenType === lexer_1.Lexer.TOKEN_PHPDOC_EOL) {
|
|
105
|
+
if (this.newline === null) {
|
|
106
|
+
this.detectNewline();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.index++;
|
|
110
|
+
this.skipIrrelevantTokens();
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
detectNewline() {
|
|
114
|
+
const value = this.currentTokenValue();
|
|
115
|
+
if (value.substring(0, 2) === '\r\n') {
|
|
116
|
+
this.newline = '\r\n';
|
|
117
|
+
}
|
|
118
|
+
else if (value.substring(0, 1) === '\n') {
|
|
119
|
+
this.newline = '\n';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
getSkippedHorizontalWhiteSpaceIfAny() {
|
|
123
|
+
if (this.index > 0 &&
|
|
124
|
+
this.tokens[this.index - 1][1] === lexer_1.Lexer.TOKEN_HORIZONTAL_WS) {
|
|
125
|
+
return this.tokens[this.index - 1][0];
|
|
126
|
+
}
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
joinUntil(...tokenType) {
|
|
130
|
+
let s = '';
|
|
131
|
+
while (!tokenType.includes(this.tokens[this.index][1])) {
|
|
132
|
+
s += this.tokens[this.index++][0];
|
|
133
|
+
}
|
|
134
|
+
return s;
|
|
135
|
+
}
|
|
136
|
+
next() {
|
|
137
|
+
this.index++;
|
|
138
|
+
this.skipIrrelevantTokens();
|
|
139
|
+
}
|
|
140
|
+
skipIrrelevantTokens() {
|
|
141
|
+
if (this.tokens[this.index] === undefined) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
while (this.skippedTokenTypes.includes(this.tokens[this.index][lexer_1.Lexer.TYPE_OFFSET])) {
|
|
145
|
+
if (this.tokens[this.index + 1] === undefined) {
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
this.index++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
addEndOfLineToSkippedTokens() {
|
|
152
|
+
this.skippedTokenTypes = [
|
|
153
|
+
lexer_1.Lexer.TOKEN_HORIZONTAL_WS,
|
|
154
|
+
lexer_1.Lexer.TOKEN_PHPDOC_EOL,
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
removeEndOfLineFromSkippedTokens() {
|
|
158
|
+
this.skippedTokenTypes = [lexer_1.Lexer.TOKEN_HORIZONTAL_WS];
|
|
159
|
+
}
|
|
160
|
+
forwardToTheEnd() {
|
|
161
|
+
const lastToken = this.tokens.length - 1;
|
|
162
|
+
this.index = lastToken;
|
|
163
|
+
}
|
|
164
|
+
pushSavePoint() {
|
|
165
|
+
this.savePoints.push(this.index);
|
|
166
|
+
}
|
|
167
|
+
dropSavePoint() {
|
|
168
|
+
this.savePoints.pop();
|
|
169
|
+
}
|
|
170
|
+
rollback() {
|
|
171
|
+
const index = this.savePoints.pop();
|
|
172
|
+
this.index = index;
|
|
173
|
+
}
|
|
174
|
+
throwError(expectedTokenType, expectedTokenValue = null) {
|
|
175
|
+
throw new parser_exception_1.ParserException(this.currentTokenValue(), this.currentTokenType(), this.currentTokenOffset(), expectedTokenType, expectedTokenValue, this.currentTokenLine());
|
|
176
|
+
}
|
|
177
|
+
hasTokenImmediatelyBefore(pos, expectedTokenType) {
|
|
178
|
+
const { tokens } = this;
|
|
179
|
+
pos--;
|
|
180
|
+
for (; pos >= 0; pos--) {
|
|
181
|
+
const token = tokens[pos];
|
|
182
|
+
const type = token[1];
|
|
183
|
+
if (type === expectedTokenType) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
if (![lexer_1.Lexer.TOKEN_HORIZONTAL_WS, lexer_1.Lexer.TOKEN_PHPDOC_EOL].includes(type)) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
hasTokenImmediatelyAfter(pos, expectedTokenType) {
|
|
193
|
+
const { tokens } = this;
|
|
194
|
+
pos++;
|
|
195
|
+
for (let c = tokens.length; pos < c; pos++) {
|
|
196
|
+
const token = tokens[pos];
|
|
197
|
+
const type = token[1];
|
|
198
|
+
if (type === expectedTokenType) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (![lexer_1.Lexer.TOKEN_HORIZONTAL_WS, lexer_1.Lexer.TOKEN_PHPDOC_EOL].includes(type)) {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
getDetectedNewline() {
|
|
208
|
+
return this.newline;
|
|
209
|
+
}
|
|
210
|
+
hasParentheses(startPos, endPos) {
|
|
211
|
+
return (this.hasTokenImmediatelyBefore(startPos, lexer_1.Lexer.TOKEN_OPEN_PARENTHESES) &&
|
|
212
|
+
this.hasTokenImmediatelyAfter(endPos, lexer_1.Lexer.TOKEN_CLOSE_PARENTHESES));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.TokenIterator = TokenIterator;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConstExprParser } from './const-expr-parser';
|
|
2
|
+
import { TokenIterator } from './token-iterator';
|
|
3
|
+
import { BaseNode } from '../ast/base-node';
|
|
4
|
+
import { GenericTypeNode } from '../ast/type/generic-type-node';
|
|
5
|
+
import { IdentifierTypeNode } from '../ast/type/identifier-type-node';
|
|
6
|
+
import { TypeNode } from '../ast/type/type-node';
|
|
7
|
+
export declare class TypeParser {
|
|
8
|
+
private constExprParser;
|
|
9
|
+
private quoteAwareConstExprString;
|
|
10
|
+
private useLinesAttributes;
|
|
11
|
+
private useIndexAttributes;
|
|
12
|
+
constructor(constExprParser?: ConstExprParser | null, quoteAwareConstExprString?: boolean, usedAttributes?: {
|
|
13
|
+
lines?: boolean;
|
|
14
|
+
indexes?: boolean;
|
|
15
|
+
});
|
|
16
|
+
parse(tokens: TokenIterator): TypeNode;
|
|
17
|
+
enrichWithAttributes<T extends BaseNode>(tokens: TokenIterator, type: T, startLine: number, startIndex: number): T;
|
|
18
|
+
private subParse;
|
|
19
|
+
private parseAtomic;
|
|
20
|
+
private parseUnion;
|
|
21
|
+
private subParseUnion;
|
|
22
|
+
private parseIntersection;
|
|
23
|
+
private subParseIntersection;
|
|
24
|
+
private parseConditional;
|
|
25
|
+
private parseConditionalForParameter;
|
|
26
|
+
private parseNullable;
|
|
27
|
+
isHtml(tokens: TokenIterator): boolean;
|
|
28
|
+
parseGeneric(tokens: TokenIterator, baseType: IdentifierTypeNode): GenericTypeNode;
|
|
29
|
+
private parseGenericTypeArgument;
|
|
30
|
+
private parseCallable;
|
|
31
|
+
private parseCallableParameter;
|
|
32
|
+
private parseCallableReturnType;
|
|
33
|
+
private tryParseCallable;
|
|
34
|
+
private tryParseArrayOrOffsetAccess;
|
|
35
|
+
private parseArrayShape;
|
|
36
|
+
private parseArrayShapeItem;
|
|
37
|
+
private parseArrayShapeKey;
|
|
38
|
+
private parseObjectShape;
|
|
39
|
+
private parseObjectShapeItem;
|
|
40
|
+
private parseObjectShapeKey;
|
|
41
|
+
}
|