extra-parser 0.6.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/README.md +57 -29
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/match-repetitions.d.ts +7 -0
- package/lib/match-repetitions.js +36 -0
- package/lib/match-repetitions.js.map +1 -0
- package/lib/match-sequence.d.ts +4 -14
- package/lib/match-sequence.js +1 -1
- package/lib/match-sequence.js.map +1 -1
- package/lib/types.d.ts +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,40 @@ interface ITokenPattern<Token extends IToken = IToken> {
|
|
|
47
47
|
interface INodePattern<Token extends IToken = IToken, Node extends INode = INode> {
|
|
48
48
|
(tokens: ReadonlyArray<Token>): Awaitable<INodePatternMatch<Node> | Falsy>
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
type MapSequenceToPatterns<
|
|
52
|
+
Sequence extends ReadonlyArray<Token | Node>
|
|
53
|
+
, Token extends IToken = IToken
|
|
54
|
+
, Node extends INode = INode
|
|
55
|
+
> = {
|
|
56
|
+
[Index in keyof Sequence]:
|
|
57
|
+
[Sequence[Index]] extends [infer Element]
|
|
58
|
+
? (
|
|
59
|
+
Element extends Token
|
|
60
|
+
? string
|
|
61
|
+
: Element extends Node
|
|
62
|
+
? INodePattern<Token, Element>
|
|
63
|
+
: never
|
|
64
|
+
)
|
|
65
|
+
: never
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type MapSequenceToMatches<
|
|
69
|
+
Sequence extends ReadonlyArray<Token | Node>
|
|
70
|
+
, Token extends IToken = IToken
|
|
71
|
+
, Node extends INode = INode
|
|
72
|
+
> = {
|
|
73
|
+
[Index in keyof Sequence]:
|
|
74
|
+
[Sequence[Index]] extends [infer Element]
|
|
75
|
+
? (
|
|
76
|
+
Element extends IToken
|
|
77
|
+
? Token
|
|
78
|
+
: Element extends INode
|
|
79
|
+
? INodePatternMatch<Element>
|
|
80
|
+
: never
|
|
81
|
+
)
|
|
82
|
+
: never
|
|
83
|
+
}
|
|
50
84
|
```
|
|
51
85
|
|
|
52
86
|
### tokenize
|
|
@@ -97,36 +131,30 @@ function matchAnyOf<
|
|
|
97
131
|
|
|
98
132
|
#### matchSequence
|
|
99
133
|
```ts
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
: never
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
type MapSequenceToMatches<Sequence extends ReadonlyArray<IToken | INode>> = {
|
|
114
|
-
[Index in keyof Sequence]:
|
|
115
|
-
[Sequence[Index]] extends [infer Element]
|
|
116
|
-
? (
|
|
117
|
-
Element extends IToken
|
|
118
|
-
? IToken
|
|
119
|
-
: Element extends INode
|
|
120
|
-
? INodePatternMatch<Element>
|
|
121
|
-
: never
|
|
122
|
-
)
|
|
123
|
-
: never
|
|
124
|
-
}
|
|
134
|
+
function matchSequence<
|
|
135
|
+
Sequence extends ReadonlyArray<Token | Node>
|
|
136
|
+
, Token extends IToken = IToken
|
|
137
|
+
, Node extends INode = INode
|
|
138
|
+
>(
|
|
139
|
+
patterns: MapSequenceToPatterns<Sequence, Token, Node>
|
|
140
|
+
, tokens: ReadonlyArray<Token>
|
|
141
|
+
): Promise<MapSequenceToMatches<Sequence, Token, Node> | Falsy>
|
|
142
|
+
```
|
|
125
143
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
144
|
+
#### matchRepetitions
|
|
145
|
+
```ts
|
|
146
|
+
function matchRepetitions<
|
|
147
|
+
Sequence extends ReadonlyArray<Token | Node>
|
|
148
|
+
, Token extends IToken = IToken
|
|
149
|
+
, Node extends INode = INode
|
|
150
|
+
>(
|
|
151
|
+
patterns: MapSequenceToPatterns<Sequence, Token, Node>
|
|
152
|
+
, tokens: ReadonlyArray<Token>
|
|
153
|
+
, options?: {
|
|
154
|
+
minimumRepetitions?: number = 1
|
|
155
|
+
maximumRepetitions?: number = Infinity
|
|
156
|
+
}
|
|
157
|
+
): Promise<Flatten<Array<MapSequenceToMatches<Sequence, Token, Node>>> | Falsy>
|
|
130
158
|
```
|
|
131
159
|
|
|
132
160
|
### createTokenPatternFromRegExp
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { IToken, ITokenPattern, ITokenPatternMatch, INode, INodePattern, INodePatternMatch } from './types';
|
|
2
2
|
export * from './tokenize';
|
|
3
3
|
export * from './parse';
|
|
4
4
|
export * from './consume-token';
|
|
5
5
|
export * from './consume-node';
|
|
6
6
|
export { matchSequence } from './match-sequence';
|
|
7
|
+
export * from './match-repetitions';
|
|
7
8
|
export * from './match-any-of';
|
|
8
9
|
export * from './create-token-pattern-from-regexp';
|
|
9
10
|
export * from './create-unary-operator-expression-node-pattern';
|
package/lib/index.js
CHANGED
|
@@ -15,13 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.matchSequence = void 0;
|
|
18
|
-
__exportStar(require("./types"), exports);
|
|
19
18
|
__exportStar(require("./tokenize"), exports);
|
|
20
19
|
__exportStar(require("./parse"), exports);
|
|
21
20
|
__exportStar(require("./consume-token"), exports);
|
|
22
21
|
__exportStar(require("./consume-node"), exports);
|
|
23
22
|
var match_sequence_1 = require("./match-sequence");
|
|
24
23
|
Object.defineProperty(exports, "matchSequence", { enumerable: true, get: function () { return match_sequence_1.matchSequence; } });
|
|
24
|
+
__exportStar(require("./match-repetitions"), exports);
|
|
25
25
|
__exportStar(require("./match-any-of"), exports);
|
|
26
26
|
__exportStar(require("./create-token-pattern-from-regexp"), exports);
|
|
27
27
|
__exportStar(require("./create-unary-operator-expression-node-pattern"), exports);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAQA,6CAA0B;AAC1B,0CAAuB;AACvB,kDAA+B;AAC/B,iDAA8B;AAC9B,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,sDAAmC;AACnC,iDAA8B;AAC9B,qEAAkD;AAClD,kFAA+D;AAC/D,mFAAgE;AAChE,2EAAwD;AACxD,yEAAsD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Falsy } from '@blackglory/prelude';
|
|
2
|
+
import { Flatten } from 'hotypes';
|
|
3
|
+
import { IToken, INode, MapSequenceToPatterns, MapSequenceToMatches } from './types';
|
|
4
|
+
export declare function matchRepetitions<Sequence extends ReadonlyArray<Token | Node>, Token extends IToken = IToken, Node extends INode = INode>(patterns: MapSequenceToPatterns<Sequence, Token, Node>, tokens: ReadonlyArray<Token>, { minimumRepetitions, maximumRepetitions }?: {
|
|
5
|
+
minimumRepetitions?: number;
|
|
6
|
+
maximumRepetitions?: number;
|
|
7
|
+
}): Promise<Flatten<Array<MapSequenceToMatches<Sequence, Token, Node>>> | Falsy>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchRepetitions = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
const match_sequence_1 = require("./match-sequence");
|
|
6
|
+
async function matchRepetitions(patterns, tokens, { minimumRepetitions = 1, maximumRepetitions = Infinity } = {}) {
|
|
7
|
+
(0, prelude_1.assert)(Number.isInteger(minimumRepetitions), 'The minimum repetiions must be an integer');
|
|
8
|
+
(0, prelude_1.assert)(minimumRepetitions >= 0, 'The minimum repetitions must be greater than or equal to 0');
|
|
9
|
+
(0, prelude_1.assert)(Number.isInteger(maximumRepetitions) || maximumRepetitions === Infinity, 'The maxmium repetiions must be an integer or an Infinity');
|
|
10
|
+
(0, prelude_1.assert)(maximumRepetitions >= minimumRepetitions, 'The maximum repetitions must be greater than or equal to the minimum repetitions');
|
|
11
|
+
const results = [];
|
|
12
|
+
const mutableTokens = (0, prelude_1.toArray)(tokens);
|
|
13
|
+
for (let i = 0; i < minimumRepetitions; i++) {
|
|
14
|
+
const matches = await (0, match_sequence_1.matchSequence)(patterns, mutableTokens);
|
|
15
|
+
if ((0, prelude_1.isntFalsy)(matches)) {
|
|
16
|
+
results.push(matches);
|
|
17
|
+
mutableTokens.splice(0, matches.length);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (let i = minimumRepetitions; i < maximumRepetitions; i++) {
|
|
24
|
+
const matches = await (0, match_sequence_1.matchSequence)(patterns, mutableTokens);
|
|
25
|
+
if ((0, prelude_1.isntFalsy)(matches)) {
|
|
26
|
+
results.push(matches);
|
|
27
|
+
mutableTokens.splice(0, matches.length);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return results.flat();
|
|
34
|
+
}
|
|
35
|
+
exports.matchRepetitions = matchRepetitions;
|
|
36
|
+
//# sourceMappingURL=match-repetitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-repetitions.js","sourceRoot":"","sources":["../src/match-repetitions.ts"],"names":[],"mappings":";;;AAAA,iDAAuE;AAGvE,qDAAgD;AAEzC,KAAK,UAAU,gBAAgB,CAKpC,QAAsD,EACtD,MAA4B,EAC5B,EACE,kBAAkB,GAAG,CAAC,EACtB,kBAAkB,GAAG,QAAQ,KAI3B,EAAE;IAEN,IAAA,gBAAM,EAAC,MAAM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DC"}
|
package/lib/match-sequence.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { NonEmptyArray, Falsy } from '@blackglory/prelude';
|
|
2
|
-
import { IToken, INode, INodePattern,
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
] extends [infer Element] ? (Element extends IToken ? string : Element extends INode ? INodePattern<IToken, Element> : never) : never;
|
|
7
|
-
};
|
|
8
|
-
declare type MapSequenceToMatches<Sequence extends ReadonlyArray<IToken | INode>> = {
|
|
9
|
-
[Index in keyof Sequence]: [
|
|
10
|
-
Sequence[Index]
|
|
11
|
-
] extends [infer Element] ? (Element extends IToken ? IToken : Element extends INode ? INodePatternMatch<Element> : never) : never;
|
|
12
|
-
};
|
|
13
|
-
export declare function matchSequence<Sequence extends ReadonlyArray<IToken | INode>>(patterns: MapSequenceToPatterns<Sequence>, tokens: ReadonlyArray<IToken>): Promise<MapSequenceToMatches<Sequence> | Falsy>;
|
|
14
|
-
declare type SubPatterns = [INodePattern<IToken, INode>, string] | NonEmptyArray<string> | NonEmptyArray<INodePattern<IToken, INode>>;
|
|
15
|
-
export declare function splitPatterns<Sequence extends ReadonlyArray<IToken | INode>>(patterns: MapSequenceToPatterns<Sequence>): IterableIterator<SubPatterns>;
|
|
2
|
+
import { IToken, INode, INodePattern, MapSequenceToPatterns, MapSequenceToMatches } from './types';
|
|
3
|
+
export declare function matchSequence<Sequence extends ReadonlyArray<Token | Node>, Token extends IToken = IToken, Node extends INode = INode>(patterns: MapSequenceToPatterns<Sequence, Token, Node>, tokens: ReadonlyArray<Token>): Promise<MapSequenceToMatches<Sequence, Token, Node> | Falsy>;
|
|
4
|
+
declare type SubPatterns<Token extends IToken = IToken, Node extends INode = INode> = [INodePattern<Token, Node>, string] | NonEmptyArray<string> | NonEmptyArray<INodePattern<Token, Node>>;
|
|
5
|
+
export declare function splitPatterns<Sequence extends ReadonlyArray<Token | Node>, Token extends IToken = IToken, Node extends INode = INode>(patterns: MapSequenceToPatterns<Sequence, Token, Node>): IterableIterator<SubPatterns<Token, Node>>;
|
|
16
6
|
export {};
|
package/lib/match-sequence.js
CHANGED
|
@@ -56,7 +56,7 @@ async function matchSequence(patterns, tokens) {
|
|
|
56
56
|
const subMatches = await matchSequence(subPatterns, remainingTokens);
|
|
57
57
|
if ((0, prelude_1.isntFalsy)(subMatches)) {
|
|
58
58
|
const consumed = subMatches
|
|
59
|
-
.map(match => {
|
|
59
|
+
.map((match) => {
|
|
60
60
|
return 'consumed' in match
|
|
61
61
|
? match.consumed
|
|
62
62
|
: 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-sequence.js","sourceRoot":"","sources":["../src/match-sequence.ts"],"names":[],"mappings":";;;AAAA,iDAO4B;AAC5B,yDAAkD;
|
|
1
|
+
{"version":3,"file":"match-sequence.js","sourceRoot":"","sources":["../src/match-sequence.ts"],"names":[],"mappings":";;;AAAA,iDAO4B;AAC5B,yDAAkD;AASlD,mDAA8C;AAC9C,iDAA4C;AAWrC,KAAK,UAAU,aAAa,CAKjC,QAAsD,EACtD,MAA4B;IAE5B,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE;QAC1B,MAAM,OAAO,GAAiB,EAAE,CAAA;QAEhC,MAAM,aAAa,GAAG,IAAA,iBAAO,EAAC,MAAM,CAAC,CAAA;QACrC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,KAAK,GAAG,IAAA,4BAAY,EAAC,OAAO,EAAE,aAAa,CAAC,CAAA;YAClD,IAAI,IAAA,mBAAS,EAAC,KAAK,CAAC,EAAE;gBACpB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;aACpB;iBAAM;gBACL,OAAM;aACP;SACF;QAED,OAAO,OAAsD,CAAA;KAC9D;SAAM,IAAI,cAAc,CAAc,QAAQ,CAAC,EAAE;QAChD,MAAM,OAAO,GAAmC,EAAE,CAAA;QAElD,MAAM,aAAa,GAAG,IAAA,iBAAO,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M,CAAC,CAAC,CAE7B,CAAA;aACF;iBAAM;gBACL,MAAM,eAAe,CAAC,MAAM,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC,CAG/C,CAAA;aACF;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;SACpC;KACF;AACH,CAAC;AAjCD,sCAiCC;AAED,SAAS,YAAY,CAAC,GAA2B;IAC/C,OAAO,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AAC/B,CAAC;AAED,SAAS,WAAW,CAAC,GAAY;IAC/B,OAAO,IAAA,kBAAQ,EAAC,GAAG,CAAC,CAAA;AACtB,CAAC;AAED,SAAS,cAAc,CACrB,GAA2B;IAE3B,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;AACjC,CAAC;AAED,SAAS,aAAa,CACpB,GAAY;IAEZ,OAAO,IAAA,oBAAU,EAAC,GAAG,CAAC,CAAA;AACxB,CAAC;AAED,SAAS,qBAAqB,CAC5B,GAA2B;IAE3B,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC;WAChB,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;WACrB,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAC5B,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -20,3 +20,13 @@ export interface ITokenPattern<Token extends IToken = IToken> {
|
|
|
20
20
|
export interface INodePattern<Token extends IToken = IToken, Node extends INode = INode> {
|
|
21
21
|
(tokens: ReadonlyArray<Token>): Awaitable<INodePatternMatch<Node> | Falsy>;
|
|
22
22
|
}
|
|
23
|
+
export declare type MapSequenceToPatterns<Sequence extends ReadonlyArray<Token | Node>, Token extends IToken = IToken, Node extends INode = INode> = {
|
|
24
|
+
[Index in keyof Sequence]: [
|
|
25
|
+
Sequence[Index]
|
|
26
|
+
] extends [infer Element] ? (Element extends Token ? string : Element extends Node ? INodePattern<Token, Element> : never) : never;
|
|
27
|
+
};
|
|
28
|
+
export declare type MapSequenceToMatches<Sequence extends ReadonlyArray<Token | Node>, Token extends IToken = IToken, Node extends INode = INode> = {
|
|
29
|
+
[Index in keyof Sequence]: [
|
|
30
|
+
Sequence[Index]
|
|
31
|
+
] extends [infer Element] ? (Element extends IToken ? Token : Element extends INode ? INodePatternMatch<Element> : never) : never;
|
|
32
|
+
};
|