extra-parser 0.5.0 → 0.6.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/README.md +164 -13
- package/lib/consume-node.d.ts +3 -0
- package/lib/consume-node.js +13 -0
- package/lib/consume-node.js.map +1 -0
- package/lib/consume-token.d.ts +3 -0
- package/lib/consume-token.js +12 -0
- package/lib/consume-token.js.map +1 -0
- package/lib/create-binary-operator-expression-node-pattern.d.ts +12 -0
- package/lib/create-binary-operator-expression-node-pattern.js +27 -0
- package/lib/create-binary-operator-expression-node-pattern.js.map +1 -0
- package/lib/create-grouped-expression-node-pattern.d.ts +6 -0
- package/lib/create-grouped-expression-node-pattern.js +23 -0
- package/lib/create-grouped-expression-node-pattern.js.map +1 -0
- package/lib/create-token-pattern-from-regexp.js +2 -2
- package/lib/create-token-pattern-from-regexp.js.map +1 -1
- package/lib/create-unary-operator-expression-node-pattern.d.ts +10 -0
- package/lib/create-unary-operator-expression-node-pattern.js +25 -0
- package/lib/create-unary-operator-expression-node-pattern.js.map +1 -0
- package/lib/create-value-expression-node-pattern.d.ts +10 -0
- package/lib/create-value-expression-node-pattern.js +22 -0
- package/lib/create-value-expression-node-pattern.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -1
- package/lib/match-any-of.d.ts +3 -0
- package/lib/match-any-of.js +14 -0
- package/lib/match-any-of.js.map +1 -0
- package/lib/match-sequence.d.ts +16 -0
- package/lib/match-sequence.js +120 -0
- package/lib/match-sequence.js.map +1 -0
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +1 -1
- package/lib/parse.js.map +1 -1
- package/lib/tokenize.d.ts +1 -1
- package/lib/tokenize.js +1 -1
- package/lib/tokenize.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# extra-parser
|
|
2
|
+
A functional parser toolkit.
|
|
3
|
+
|
|
2
4
|
## Install
|
|
3
5
|
```sh
|
|
4
6
|
npm install --save extra-parser
|
|
@@ -6,6 +8,17 @@ npm install --save extra-parser
|
|
|
6
8
|
yarn add extra-parser
|
|
7
9
|
```
|
|
8
10
|
|
|
11
|
+
## FAQ
|
|
12
|
+
### Why are functions asynchronous?
|
|
13
|
+
Some parsers make heavy use of recursion,
|
|
14
|
+
and most JavaScript engines do not support tail-call optimization,
|
|
15
|
+
which leads to the possibility of stack overflow in programs.
|
|
16
|
+
|
|
17
|
+
Asynchronous functions are an escape route:
|
|
18
|
+
developers can change recursive functions to asynchronous recursive functions
|
|
19
|
+
to get their programs out of stack overflow problems
|
|
20
|
+
without significantly reducing readability.
|
|
21
|
+
|
|
9
22
|
## API
|
|
10
23
|
```ts
|
|
11
24
|
interface IToken {
|
|
@@ -39,19 +52,83 @@ interface INodePattern<Token extends IToken = IToken, Node extends INode = INode
|
|
|
39
52
|
### tokenize
|
|
40
53
|
```ts
|
|
41
54
|
function tokenize<Token extends IToken = IToken>(
|
|
42
|
-
|
|
43
|
-
,
|
|
55
|
+
patterns: Array<ITokenPattern<Token>>
|
|
56
|
+
, text: string
|
|
44
57
|
): AsyncIterableIterator<Token>
|
|
45
58
|
```
|
|
46
59
|
|
|
47
60
|
### parse
|
|
48
61
|
```ts
|
|
49
62
|
function parse<Token extends IToken = IToken, Node extends INode = INode>(
|
|
50
|
-
|
|
51
|
-
,
|
|
63
|
+
patterns: Array<INodePattern<Token, Node>>
|
|
64
|
+
, tokens: Token[]
|
|
52
65
|
): AsyncIterableIterator<Node>
|
|
53
66
|
```
|
|
54
67
|
|
|
68
|
+
### consumeNode
|
|
69
|
+
```ts
|
|
70
|
+
function consumeNode<
|
|
71
|
+
Token extends IToken = IToken
|
|
72
|
+
, Node extends INode = INode
|
|
73
|
+
>(
|
|
74
|
+
nodePattern: INodePattern<Token, Node>
|
|
75
|
+
, tokens: Token[]
|
|
76
|
+
): Promise<INodePatternMatch<Node> | Falsy>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### consumeToken
|
|
80
|
+
```ts
|
|
81
|
+
function consumeToken<Token extends IToken = IToken>(
|
|
82
|
+
tokenType: string
|
|
83
|
+
, tokens: Token[]
|
|
84
|
+
): Token | Falsy
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### matchAnyOf
|
|
88
|
+
```ts
|
|
89
|
+
function matchAnyOf<
|
|
90
|
+
Token extends IToken = IToken
|
|
91
|
+
, Node extends INode = INode
|
|
92
|
+
>(
|
|
93
|
+
nodePatterns: ReadonlyArray<INodePattern<Token, Node>>
|
|
94
|
+
, tokens: ReadonlyArray<Token>
|
|
95
|
+
): Promise<INodePatternMatch<Node> | Falsy>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### matchSequence
|
|
99
|
+
```ts
|
|
100
|
+
type MapSequenceToPatterns<Sequence extends ReadonlyArray<IToken | INode>> = {
|
|
101
|
+
[Index in keyof Sequence]:
|
|
102
|
+
[Sequence[Index]] extends [infer Element]
|
|
103
|
+
? (
|
|
104
|
+
Element extends IToken
|
|
105
|
+
? string
|
|
106
|
+
: Element extends INode
|
|
107
|
+
? INodePattern<IToken, Element>
|
|
108
|
+
: never
|
|
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
|
+
}
|
|
125
|
+
|
|
126
|
+
function matchSequence<Sequence extends ReadonlyArray<IToken | INode>>(
|
|
127
|
+
patterns: MapSequenceToPatterns<Sequence>
|
|
128
|
+
, tokens: ReadonlyArray<IToken>
|
|
129
|
+
): Promise<MapSequenceToMatches<Sequence> | Falsy>
|
|
130
|
+
```
|
|
131
|
+
|
|
55
132
|
### createTokenPatternFromRegExp
|
|
56
133
|
```ts
|
|
57
134
|
function createTokenPatternFromRegExp<Token extends IToken>(
|
|
@@ -60,13 +137,87 @@ function createTokenPatternFromRegExp<Token extends IToken>(
|
|
|
60
137
|
): ITokenPattern<IToken>
|
|
61
138
|
```
|
|
62
139
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
140
|
+
### createUnaryOperatorExpressionNodePattern
|
|
141
|
+
```ts
|
|
142
|
+
interface IUnaryOperatorExpressionNode<
|
|
143
|
+
NodeType extends string
|
|
144
|
+
, RightNode extends INode
|
|
145
|
+
> extends INode {
|
|
146
|
+
nodeType: NodeType
|
|
147
|
+
right: RightNode
|
|
148
|
+
}
|
|
68
149
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
150
|
+
function createUnaryOperatorExpressionNodePattern<
|
|
151
|
+
Token extends IToken
|
|
152
|
+
, Node extends IUnaryOperatorExpressionNode<string, RightNode>
|
|
153
|
+
, RightNode extends INode
|
|
154
|
+
>(params: {
|
|
155
|
+
nodeType: Node['nodeType']
|
|
156
|
+
leftTokenType: string
|
|
157
|
+
rightNodePattern: INodePattern<Token, RightNode>
|
|
158
|
+
}): INodePattern<
|
|
159
|
+
Token
|
|
160
|
+
, IUnaryOperatorExpressionNode<Node['nodeType'], Node['right']>
|
|
161
|
+
>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### createBinaryOperatorExpressionNodePattern
|
|
165
|
+
```ts
|
|
166
|
+
interface IBinaryOperatorExpressionNode<
|
|
167
|
+
NodeType extends string
|
|
168
|
+
, LeftNode extends INode
|
|
169
|
+
, RightNode extends INode
|
|
170
|
+
> extends INode {
|
|
171
|
+
nodeType: NodeType
|
|
172
|
+
left: LeftNode
|
|
173
|
+
right: RightNode
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function createBinaryOperatorExpressionNodePattern<
|
|
177
|
+
Token extends IToken
|
|
178
|
+
, Node extends IBinaryOperatorExpressionNode<string, LeftNode, RightNode>
|
|
179
|
+
, LeftNode extends INode
|
|
180
|
+
, RightNode extends INode
|
|
181
|
+
>(params: {
|
|
182
|
+
nodeType: Node['nodeType']
|
|
183
|
+
centerTokenType: string
|
|
184
|
+
leftNodePattern: INodePattern<Token, LeftNode>
|
|
185
|
+
rightNodePattern: INodePattern<Token, RightNode>
|
|
186
|
+
}): INodePattern<
|
|
187
|
+
Token
|
|
188
|
+
, IBinaryOperatorExpressionNode<Node['nodeType'], Node['left'], Node['right']>
|
|
189
|
+
>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### createGroupedExpressionNodePattern
|
|
193
|
+
```ts
|
|
194
|
+
function createGroupedExpressionNodePattern<
|
|
195
|
+
Token extends IToken
|
|
196
|
+
, CenterNode extends INode
|
|
197
|
+
>(params: {
|
|
198
|
+
leftTokenType: string
|
|
199
|
+
rightTokenType: string
|
|
200
|
+
centerNodePattern: INodePattern<Token, CenterNode>
|
|
201
|
+
}): INodePattern<Token, CenterNode>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### createValueExpressionNodePattern
|
|
205
|
+
```ts
|
|
206
|
+
interface IValueExpressionNode<
|
|
207
|
+
NodeType extends string
|
|
208
|
+
, Value
|
|
209
|
+
> extends INode {
|
|
210
|
+
nodeType: NodeType
|
|
211
|
+
value: Value
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function createValueExpressionNodePattern<
|
|
215
|
+
Token extends IToken
|
|
216
|
+
, Node extends IValueExpressionNode<string, Value>
|
|
217
|
+
, Value
|
|
218
|
+
>(params: {
|
|
219
|
+
nodeType: Node['nodeType']
|
|
220
|
+
valueTokenType: string
|
|
221
|
+
transformValue: (value: string) => Value
|
|
222
|
+
}): INodePattern<Token, IValueExpressionNode<Node['nodeType'], Node['value']>>
|
|
223
|
+
```
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Falsy } from '@blackglory/prelude';
|
|
2
|
+
import { IToken, INode, INodePattern, INodePatternMatch } from './types';
|
|
3
|
+
export declare function consumeNode<Token extends IToken = IToken, Node extends INode = INode>(nodePattern: INodePattern<Token, Node>, tokens: Token[]): Promise<INodePatternMatch<Node> | Falsy>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.consumeNode = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
async function consumeNode(nodePattern, tokens) {
|
|
6
|
+
const match = await nodePattern(tokens);
|
|
7
|
+
if ((0, prelude_1.isntFalsy)(match)) {
|
|
8
|
+
tokens.splice(0, match.consumed);
|
|
9
|
+
return match;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.consumeNode = consumeNode;
|
|
13
|
+
//# sourceMappingURL=consume-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consume-node.js","sourceRoot":"","sources":["../src/consume-node.ts"],"names":[],"mappings":";;;AAAA,iDAAsD;AAQ/C,KAAK,UAAU,WAAW,CAI/B,WAAsC,EACtC,MAAe;IAEf,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAA;IAEvC,IAAI,IAAA,mBAAS,EAAC,KAAK,CAAC,EAAE;QACpB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;QAChC,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAbD,kCAaC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.consumeToken = void 0;
|
|
4
|
+
function consumeToken(tokenType, tokens) {
|
|
5
|
+
const firstToken = tokens[0];
|
|
6
|
+
if (firstToken && firstToken.tokenType === tokenType) {
|
|
7
|
+
tokens.shift();
|
|
8
|
+
return firstToken;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.consumeToken = consumeToken;
|
|
12
|
+
//# sourceMappingURL=consume-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consume-token.js","sourceRoot":"","sources":["../src/consume-token.ts"],"names":[],"mappings":";;;AAQA,SAAgB,YAAY,CAC1B,SAAiB,EACjB,MAAe;IAEf,MAAM,UAAU,GAAuB,MAAM,CAAC,CAAC,CAAC,CAAA;IAEhD,IAAI,UAAU,IAAI,UAAU,CAAC,SAAS,KAAK,SAAS,EAAE;QACpD,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,OAAO,UAAmB,CAAA;KAC3B;AACH,CAAC;AAVD,oCAUC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IToken, INode, INodePattern } from './types';
|
|
2
|
+
export interface IBinaryOperatorExpressionNode<NodeType extends string, LeftNode extends INode, RightNode extends INode> extends INode {
|
|
3
|
+
nodeType: NodeType;
|
|
4
|
+
left: LeftNode;
|
|
5
|
+
right: RightNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function createBinaryOperatorExpressionNodePattern<Token extends IToken, Node extends IBinaryOperatorExpressionNode<string, LeftNode, RightNode>, LeftNode extends INode, RightNode extends INode>({ nodeType, centerTokenType, rightNodePattern, leftNodePattern }: {
|
|
8
|
+
nodeType: Node['nodeType'];
|
|
9
|
+
centerTokenType: string;
|
|
10
|
+
leftNodePattern: INodePattern<Token, LeftNode>;
|
|
11
|
+
rightNodePattern: INodePattern<Token, RightNode>;
|
|
12
|
+
}): INodePattern<Token, IBinaryOperatorExpressionNode<Node['nodeType'], Node['left'], Node['right']>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBinaryOperatorExpressionNodePattern = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
const match_sequence_1 = require("./match-sequence");
|
|
6
|
+
function createBinaryOperatorExpressionNodePattern({ nodeType, centerTokenType, rightNodePattern, leftNodePattern }) {
|
|
7
|
+
return async (tokens) => {
|
|
8
|
+
const matches = await (0, match_sequence_1.matchSequence)([
|
|
9
|
+
leftNodePattern,
|
|
10
|
+
centerTokenType,
|
|
11
|
+
rightNodePattern
|
|
12
|
+
], tokens);
|
|
13
|
+
if ((0, prelude_1.isntFalsy)(matches)) {
|
|
14
|
+
const [leftMatch, token, rightMatch] = matches;
|
|
15
|
+
return {
|
|
16
|
+
consumed: leftMatch.consumed + 1 + rightMatch.consumed,
|
|
17
|
+
node: {
|
|
18
|
+
nodeType,
|
|
19
|
+
left: leftMatch.node,
|
|
20
|
+
right: rightMatch.node
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.createBinaryOperatorExpressionNodePattern = createBinaryOperatorExpressionNodePattern;
|
|
27
|
+
//# sourceMappingURL=create-binary-operator-expression-node-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-binary-operator-expression-node-pattern.js","sourceRoot":"","sources":["../src/create-binary-operator-expression-node-pattern.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAE/C,qDAAgD;AAYhD,SAAgB,yCAAyC,CAKvD,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAK/D;IAIC,OAAO,KAAK,EAAC,MAAM,EAAC,EAAE;QACpB,MAAM,OAAO,GAAG,MAAM,IAAA,8BAAa,EACjC;YACE,eAAiD;YACjD,eAAe;YACf,gBAAmD;SACpD,EACD,MAAM,CACP,CAAA;QACD,IAAI,IAAA,mBAAS,EAAC,OAAO,CAAC,EAAE;YACtB,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,UAAU,CAAC,GAAG,OAAO,CAAA;YAC9C,OAAO;gBACL,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,CAAC,GAAG,UAAU,CAAC,QAAQ;gBACtD,IAAI,EAAE;oBACJ,QAAQ;oBACR,IAAI,EAAE,SAAS,CAAC,IAAoB;oBACpC,KAAK,EAAE,UAAU,CAAC,IAAqB;iBACxC;aACF,CAAA;SACF;IACH,CAAC,CAAA;AACH,CAAC;AAnCD,8FAmCC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IToken, INode, INodePattern } from './types';
|
|
2
|
+
export declare function createGroupedExpressionNodePattern<Token extends IToken, CenterNode extends INode>({ leftTokenType, rightTokenType, centerNodePattern }: {
|
|
3
|
+
leftTokenType: string;
|
|
4
|
+
rightTokenType: string;
|
|
5
|
+
centerNodePattern: INodePattern<Token, CenterNode>;
|
|
6
|
+
}): INodePattern<Token, CenterNode>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGroupedExpressionNodePattern = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
const match_sequence_1 = require("./match-sequence");
|
|
6
|
+
function createGroupedExpressionNodePattern({ leftTokenType, rightTokenType, centerNodePattern }) {
|
|
7
|
+
return async (tokens) => {
|
|
8
|
+
const matches = await (0, match_sequence_1.matchSequence)([
|
|
9
|
+
leftTokenType,
|
|
10
|
+
centerNodePattern,
|
|
11
|
+
rightTokenType
|
|
12
|
+
], tokens);
|
|
13
|
+
if ((0, prelude_1.isntFalsy)(matches)) {
|
|
14
|
+
const [leftToken, nodeMatch, rightToken] = matches;
|
|
15
|
+
return {
|
|
16
|
+
consumed: 1 + nodeMatch.consumed + 1,
|
|
17
|
+
node: nodeMatch.node
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.createGroupedExpressionNodePattern = createGroupedExpressionNodePattern;
|
|
23
|
+
//# sourceMappingURL=create-grouped-expression-node-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-grouped-expression-node-pattern.js","sourceRoot":"","sources":["../src/create-grouped-expression-node-pattern.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAE/C,qDAAgD;AAEhD,SAAgB,kCAAkC,CAGhD,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAInD;IACC,OAAO,KAAK,EAAC,MAAM,EAAC,EAAE;QACpB,MAAM,OAAO,GAAG,MAAM,IAAA,8BAAa,EACjC;YACE,aAAa;YACb,iBAAqD;YACrD,cAAc;SACf,EACD,MAAM,CACP,CAAA;QACD,IAAI,IAAA,mBAAS,EAAC,OAAO,CAAC,EAAE;YACtB,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,GAAG,OAAO,CAAA;YAClD,OAAO;gBACL,QAAQ,EAAE,CAAC,GAAG,SAAS,CAAC,QAAQ,GAAG,CAAC;gBACpC,IAAI,EAAE,SAAS,CAAC,IAAkB;aACnC,CAAA;SACF;IACH,CAAC,CAAA;AACH,CAAC;AAzBD,gFAyBC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTokenPatternFromRegExp = void 0;
|
|
4
|
-
const
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
5
|
function createTokenPatternFromRegExp(tokenType, regExp) {
|
|
6
6
|
const startsWithRegExp = convertToStartsWithRegExp(regExp);
|
|
7
7
|
return (text) => {
|
|
8
8
|
const result = startsWithRegExp.exec(text);
|
|
9
|
-
if ((0,
|
|
9
|
+
if ((0, prelude_1.isntNull)(result)) {
|
|
10
10
|
const [matchedText] = result;
|
|
11
11
|
return {
|
|
12
12
|
consumed: matchedText.length,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-token-pattern-from-regexp.js","sourceRoot":"","sources":["../src/create-token-pattern-from-regexp.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"create-token-pattern-from-regexp.js","sourceRoot":"","sources":["../src/create-token-pattern-from-regexp.ts"],"names":[],"mappings":";;;AAAA,iDAAqD;AAGrD,SAAgB,4BAA4B,CAC1C,SAA6B,EAC7B,MAAc;IAEd,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAE1D,OAAO,CAAC,IAAY,EAAsC,EAAE;QAC1D,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1C,IAAI,IAAA,kBAAQ,EAAC,MAAM,CAAC,EAAE;YACpB,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,CAAA;YAC5B,OAAO;gBACL,QAAQ,EAAE,WAAW,CAAC,MAAM;gBAC5B,KAAK,EAAE;oBACL,SAAS,EAAE,SAAS;oBACpB,KAAK,EAAE,WAAW;iBACnB;aACF,CAAA;SACF;aAAM;YACL,OAAO,KAAK,CAAA;SACb;IACH,CAAC,CAAA;AACH,CAAC;AArBD,oEAqBC;AAED,SAAS,yBAAyB,CAAC,EAAU;IAC3C,OAAO,IAAI,MAAM,CACf,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EACvD,EAAE,CAAC,KAAK,CACT,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IToken, INode, INodePattern } from './types';
|
|
2
|
+
export interface IUnaryOperatorExpressionNode<NodeType extends string, RightNode extends INode> extends INode {
|
|
3
|
+
nodeType: NodeType;
|
|
4
|
+
right: RightNode;
|
|
5
|
+
}
|
|
6
|
+
export declare function createUnaryOperatorExpressionNodePattern<Token extends IToken, Node extends IUnaryOperatorExpressionNode<string, RightNode>, RightNode extends INode>({ leftTokenType, nodeType, rightNodePattern }: {
|
|
7
|
+
nodeType: Node['nodeType'];
|
|
8
|
+
leftTokenType: string;
|
|
9
|
+
rightNodePattern: INodePattern<Token, RightNode>;
|
|
10
|
+
}): INodePattern<Token, IUnaryOperatorExpressionNode<Node['nodeType'], Node['right']>>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUnaryOperatorExpressionNodePattern = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
const match_sequence_1 = require("./match-sequence");
|
|
6
|
+
function createUnaryOperatorExpressionNodePattern({ leftTokenType, nodeType, rightNodePattern }) {
|
|
7
|
+
return async (tokens) => {
|
|
8
|
+
const matches = await (0, match_sequence_1.matchSequence)([
|
|
9
|
+
leftTokenType,
|
|
10
|
+
rightNodePattern
|
|
11
|
+
], tokens);
|
|
12
|
+
if ((0, prelude_1.isntFalsy)(matches)) {
|
|
13
|
+
const [leftToken, rightMatch] = matches;
|
|
14
|
+
return {
|
|
15
|
+
consumed: 1 + rightMatch.consumed,
|
|
16
|
+
node: {
|
|
17
|
+
nodeType: nodeType,
|
|
18
|
+
right: rightMatch.node
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.createUnaryOperatorExpressionNodePattern = createUnaryOperatorExpressionNodePattern;
|
|
25
|
+
//# sourceMappingURL=create-unary-operator-expression-node-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-unary-operator-expression-node-pattern.js","sourceRoot":"","sources":["../src/create-unary-operator-expression-node-pattern.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAE/C,qDAAgD;AAUhD,SAAgB,wCAAwC,CAItD,EAAE,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAI5C;IAIC,OAAO,KAAK,EAAC,MAAM,EAAC,EAAE;QACpB,MAAM,OAAO,GAAG,MAAM,IAAA,8BAAa,EACjC;YACE,aAAa;YACb,gBAAmD;SACpD,EACD,MAAM,CACP,CAAA;QACD,IAAI,IAAA,mBAAS,EAAC,OAAO,CAAC,EAAE;YACtB,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,OAAO,CAAA;YACvC,OAAO;gBACL,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC,QAAQ;gBACjC,IAAI,EAAE;oBACJ,QAAQ,EAAE,QAAQ;oBAClB,KAAK,EAAE,UAAU,CAAC,IAAiB;iBACpC;aACF,CAAA;SACF;IACH,CAAC,CAAA;AACH,CAAC;AA/BD,4FA+BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IToken, INode, INodePattern } from './types';
|
|
2
|
+
export interface IValueExpressionNode<NodeType extends string, Value> extends INode {
|
|
3
|
+
nodeType: NodeType;
|
|
4
|
+
value: Value;
|
|
5
|
+
}
|
|
6
|
+
export declare function createValueExpressionNodePattern<Token extends IToken, Node extends IValueExpressionNode<string, Value>, Value>({ valueTokenType, nodeType, transformValue }: {
|
|
7
|
+
nodeType: Node['nodeType'];
|
|
8
|
+
valueTokenType: string;
|
|
9
|
+
transformValue: (value: string) => Value;
|
|
10
|
+
}): INodePattern<Token, IValueExpressionNode<Node['nodeType'], Node['value']>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createValueExpressionNodePattern = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
const consume_token_1 = require("./consume-token");
|
|
6
|
+
function createValueExpressionNodePattern({ valueTokenType, nodeType, transformValue }) {
|
|
7
|
+
return tokens => {
|
|
8
|
+
const mutableTokens = (0, prelude_1.toArray)(tokens);
|
|
9
|
+
const token = (0, consume_token_1.consumeToken)(valueTokenType, mutableTokens);
|
|
10
|
+
if ((0, prelude_1.isntFalsy)(token)) {
|
|
11
|
+
return {
|
|
12
|
+
consumed: 1,
|
|
13
|
+
node: {
|
|
14
|
+
nodeType,
|
|
15
|
+
value: transformValue(token.value)
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.createValueExpressionNodePattern = createValueExpressionNodePattern;
|
|
22
|
+
//# sourceMappingURL=create-value-expression-node-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-value-expression-node-pattern.js","sourceRoot":"","sources":["../src/create-value-expression-node-pattern.ts"],"names":[],"mappings":";;;AAAA,iDAAwD;AACxD,mDAA8C;AAW9C,SAAgB,gCAAgC,CAI9C,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAI3C;IACC,OAAO,MAAM,CAAC,EAAE;QACd,MAAM,aAAa,GAAG,IAAA,iBAAO,EAAC,MAAM,CAAC,CAAA;QAErC,MAAM,KAAK,GAAG,IAAA,4BAAY,EAAC,cAAc,EAAE,aAAa,CAAC,CAAA;QACzD,IAAI,IAAA,mBAAS,EAAC,KAAK,CAAC,EAAE;YACpB,OAAO;gBACL,QAAQ,EAAE,CAAC;gBACX,IAAI,EAAE;oBACJ,QAAQ;oBACR,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC;iBACnC;aACF,CAAA;SACF;IACH,CAAC,CAAA;AACH,CAAC;AAvBD,4EAuBC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export * from './tokenize';
|
|
3
3
|
export * from './parse';
|
|
4
|
+
export * from './consume-token';
|
|
5
|
+
export * from './consume-node';
|
|
6
|
+
export { matchSequence } from './match-sequence';
|
|
7
|
+
export * from './match-any-of';
|
|
4
8
|
export * from './create-token-pattern-from-regexp';
|
|
9
|
+
export * from './create-unary-operator-expression-node-pattern';
|
|
10
|
+
export * from './create-binary-operator-expression-node-pattern';
|
|
11
|
+
export * from './create-grouped-expression-node-pattern';
|
|
12
|
+
export * from './create-value-expression-node-pattern';
|
package/lib/index.js
CHANGED
|
@@ -14,8 +14,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.matchSequence = void 0;
|
|
17
18
|
__exportStar(require("./types"), exports);
|
|
18
19
|
__exportStar(require("./tokenize"), exports);
|
|
19
20
|
__exportStar(require("./parse"), exports);
|
|
21
|
+
__exportStar(require("./consume-token"), exports);
|
|
22
|
+
__exportStar(require("./consume-node"), exports);
|
|
23
|
+
var match_sequence_1 = require("./match-sequence");
|
|
24
|
+
Object.defineProperty(exports, "matchSequence", { enumerable: true, get: function () { return match_sequence_1.matchSequence; } });
|
|
25
|
+
__exportStar(require("./match-any-of"), exports);
|
|
20
26
|
__exportStar(require("./create-token-pattern-from-regexp"), exports);
|
|
27
|
+
__exportStar(require("./create-unary-operator-expression-node-pattern"), exports);
|
|
28
|
+
__exportStar(require("./create-binary-operator-expression-node-pattern"), exports);
|
|
29
|
+
__exportStar(require("./create-grouped-expression-node-pattern"), exports);
|
|
30
|
+
__exportStar(require("./create-value-expression-node-pattern"), exports);
|
|
21
31
|
//# sourceMappingURL=index.js.map
|
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":";;;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,6CAA0B;AAC1B,0CAAuB;AACvB,kDAA+B;AAC/B,iDAA8B;AAC9B,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,iDAA8B;AAC9B,qEAAkD;AAClD,kFAA+D;AAC/D,mFAAgE;AAChE,2EAAwD;AACxD,yEAAsD"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Falsy } from '@blackglory/prelude';
|
|
2
|
+
import { IToken, INode, INodePattern, INodePatternMatch } from './types';
|
|
3
|
+
export declare function matchAnyOf<Token extends IToken = IToken, Node extends INode = INode>(nodePatterns: ReadonlyArray<INodePattern<Token, Node>>, tokens: ReadonlyArray<Token>): Promise<INodePatternMatch<Node> | Falsy>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchAnyOf = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
async function matchAnyOf(nodePatterns, tokens) {
|
|
6
|
+
for (const pattern of nodePatterns) {
|
|
7
|
+
const match = await pattern(tokens);
|
|
8
|
+
if ((0, prelude_1.isntFalsy)(match)) {
|
|
9
|
+
return match;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.matchAnyOf = matchAnyOf;
|
|
14
|
+
//# sourceMappingURL=match-any-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-any-of.js","sourceRoot":"","sources":["../src/match-any-of.ts"],"names":[],"mappings":";;;AAAA,iDAAsD;AAM/C,KAAK,UAAU,UAAU,CAI9B,YAAsD,EACtD,MAA4B;IAE5B,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE;QAClC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;QACnC,IAAI,IAAA,mBAAS,EAAC,KAAK,CAAC,EAAE;YACpB,OAAO,KAAK,CAAA;SACb;KACF;AACH,CAAC;AAbD,gCAaC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NonEmptyArray, Falsy } from '@blackglory/prelude';
|
|
2
|
+
import { IToken, INode, INodePattern, INodePatternMatch } from './types';
|
|
3
|
+
declare type MapSequenceToPatterns<Sequence extends ReadonlyArray<IToken | INode>> = {
|
|
4
|
+
[Index in keyof Sequence]: [
|
|
5
|
+
Sequence[Index]
|
|
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>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitPatterns = exports.matchSequence = void 0;
|
|
4
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
+
const iterable_operator_1 = require("iterable-operator");
|
|
6
|
+
const consume_token_1 = require("./consume-token");
|
|
7
|
+
const consume_node_1 = require("./consume-node");
|
|
8
|
+
async function matchSequence(patterns, tokens) {
|
|
9
|
+
if (isTokenTypes(patterns)) {
|
|
10
|
+
const matches = [];
|
|
11
|
+
const mutableTokens = (0, prelude_1.toArray)(tokens);
|
|
12
|
+
for (const pattern of patterns) {
|
|
13
|
+
const match = (0, consume_token_1.consumeToken)(pattern, mutableTokens);
|
|
14
|
+
if ((0, prelude_1.isntFalsy)(match)) {
|
|
15
|
+
matches.push(match);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return matches;
|
|
22
|
+
}
|
|
23
|
+
else if (isNodePatterns(patterns)) {
|
|
24
|
+
const matches = [];
|
|
25
|
+
const mutableTokens = (0, prelude_1.toArray)(tokens);
|
|
26
|
+
for (const pattern of patterns) {
|
|
27
|
+
const match = await (0, consume_node_1.consumeNode)(pattern, mutableTokens);
|
|
28
|
+
if ((0, prelude_1.isntFalsy)(match)) {
|
|
29
|
+
matches.push(match);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return matches;
|
|
36
|
+
}
|
|
37
|
+
else if (isNodePatternNodeType(patterns)) {
|
|
38
|
+
const [nodePattern, tokenType] = patterns;
|
|
39
|
+
for (const indexOfToken of (0, iterable_operator_1.findAllIndexes)(tokens, x => x.tokenType === tokenType)) {
|
|
40
|
+
const leftTokens = tokens.slice(0, indexOfToken);
|
|
41
|
+
const leftMatch = await nodePattern(leftTokens);
|
|
42
|
+
if ((0, prelude_1.isntFalsy)(leftMatch) &&
|
|
43
|
+
leftMatch.consumed === indexOfToken) {
|
|
44
|
+
const matches = [
|
|
45
|
+
leftMatch,
|
|
46
|
+
tokens[indexOfToken]
|
|
47
|
+
];
|
|
48
|
+
return matches;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const matches = [];
|
|
54
|
+
const remainingTokens = (0, prelude_1.toArray)(tokens);
|
|
55
|
+
for (const subPatterns of splitPatterns(patterns)) {
|
|
56
|
+
const subMatches = await matchSequence(subPatterns, remainingTokens);
|
|
57
|
+
if ((0, prelude_1.isntFalsy)(subMatches)) {
|
|
58
|
+
const consumed = subMatches
|
|
59
|
+
.map(match => {
|
|
60
|
+
return 'consumed' in match
|
|
61
|
+
? match.consumed
|
|
62
|
+
: 1;
|
|
63
|
+
})
|
|
64
|
+
.reduce((acc, cur) => acc + cur, 0);
|
|
65
|
+
remainingTokens.splice(0, consumed);
|
|
66
|
+
matches.push(...subMatches);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return matches;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.matchSequence = matchSequence;
|
|
76
|
+
function* splitPatterns(patterns) {
|
|
77
|
+
const mutablePatterns = (0, prelude_1.toArray)(patterns);
|
|
78
|
+
while (mutablePatterns.length > 0) {
|
|
79
|
+
if (isTokenType(mutablePatterns[0])) {
|
|
80
|
+
const indexOfNodePattern = mutablePatterns.findIndex(x => isNodePattern(x));
|
|
81
|
+
if (indexOfNodePattern === -1) {
|
|
82
|
+
yield mutablePatterns.splice(0);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
yield mutablePatterns.splice(0, indexOfNodePattern);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (isNodePattern(mutablePatterns[0])) {
|
|
89
|
+
const indexOfToken = mutablePatterns.findIndex(x => isTokenType(x));
|
|
90
|
+
if (indexOfToken === -1) {
|
|
91
|
+
yield mutablePatterns.splice(0);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
yield mutablePatterns.splice(0, indexOfToken + 1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error('Unknown patterns');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.splitPatterns = splitPatterns;
|
|
103
|
+
function isTokenTypes(arr) {
|
|
104
|
+
return arr.every(isTokenType);
|
|
105
|
+
}
|
|
106
|
+
function isTokenType(val) {
|
|
107
|
+
return (0, prelude_1.isString)(val);
|
|
108
|
+
}
|
|
109
|
+
function isNodePatterns(arr) {
|
|
110
|
+
return arr.every(isNodePattern);
|
|
111
|
+
}
|
|
112
|
+
function isNodePattern(val) {
|
|
113
|
+
return (0, prelude_1.isFunction)(val);
|
|
114
|
+
}
|
|
115
|
+
function isNodePatternNodeType(arr) {
|
|
116
|
+
return arr.length === 2
|
|
117
|
+
&& isNodePattern(arr[0])
|
|
118
|
+
&& isTokenType(arr[1]);
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=match-sequence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-sequence.js","sourceRoot":"","sources":["../src/match-sequence.ts"],"names":[],"mappings":"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"}
|
package/lib/parse.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IToken, INodePattern, INode } from './types';
|
|
2
|
-
export declare function parse<Token extends IToken = IToken, Node extends INode = INode>(
|
|
2
|
+
export declare function parse<Token extends IToken = IToken, Node extends INode = INode>(patterns: Array<INodePattern<Token, Node>>, tokens: Token[]): AsyncIterableIterator<Node>;
|
package/lib/parse.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = void 0;
|
|
4
4
|
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
-
async function* parse(
|
|
5
|
+
async function* parse(patterns, tokens) {
|
|
6
6
|
let i = 0;
|
|
7
7
|
loop: while (i < tokens.length) {
|
|
8
8
|
const remainingTokens = tokens.slice(i);
|
package/lib/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAGxC,KAAK,SAAS,CAAC,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAGxC,KAAK,SAAS,CAAC,CAAC,KAAK,CAI1B,QAA0C,EAC1C,MAAe;IAEf,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,IAAI,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE;QAC9B,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAEvC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,CAAA;YAC7C,IAAI,IAAA,mBAAS,EAAC,MAAM,CAAC,EAAE;gBACrB,MAAM,MAAM,CAAC,IAAI,CAAA;gBACjB,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAA;gBACpB,SAAS,IAAI,CAAA;aACd;SACF;QAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;KAC1E;AACH,CAAC;AAtBD,sBAsBC"}
|
package/lib/tokenize.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ITokenPattern, IToken } from './types';
|
|
2
|
-
export declare function tokenize<Token extends IToken = IToken>(
|
|
2
|
+
export declare function tokenize<Token extends IToken = IToken>(patterns: Array<ITokenPattern<Token>>, text: string): AsyncIterableIterator<Token>;
|
package/lib/tokenize.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tokenize = void 0;
|
|
4
4
|
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
-
async function* tokenize(
|
|
5
|
+
async function* tokenize(patterns, text) {
|
|
6
6
|
let i = 0;
|
|
7
7
|
loop: while (i < text.length) {
|
|
8
8
|
const remainingText = text.slice(i);
|
package/lib/tokenize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenize.js","sourceRoot":"","sources":["../src/tokenize.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAGxC,KAAK,SAAS,CAAC,CAAC,QAAQ,CAC7B,
|
|
1
|
+
{"version":3,"file":"tokenize.js","sourceRoot":"","sources":["../src/tokenize.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAGxC,KAAK,SAAS,CAAC,CAAC,QAAQ,CAC7B,QAAqC,EACrC,IAAY;IAEZ,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE;QAC5B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAEnC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,CAAA;YAC3C,IAAI,IAAA,mBAAS,EAAC,MAAM,CAAC,EAAE;gBACrB,MAAM,MAAM,CAAC,KAAK,CAAA;gBAClB,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAA;gBACpB,SAAS,IAAI,CAAA;aACd;SACF;QAED,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;KAClE;AACH,CAAC;AAnBD,4BAmBC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-parser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "A functional parser toolkit",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
7
7
|
"lib"
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"@typescript-eslint/parser": "^5.42.1",
|
|
40
40
|
"eslint": "^8.27.0",
|
|
41
41
|
"husky": "^4.3.8",
|
|
42
|
-
"iterable-operator": "^2.2.0",
|
|
43
42
|
"jest": "^29.3.0",
|
|
44
43
|
"npm-run-all": "^4.1.5",
|
|
45
44
|
"return-style": "^1.0.0",
|
|
@@ -51,6 +50,7 @@
|
|
|
51
50
|
"typescript": "^4.8.4"
|
|
52
51
|
},
|
|
53
52
|
"dependencies": {
|
|
54
|
-
"@blackglory/prelude": "^0.1.8"
|
|
53
|
+
"@blackglory/prelude": "^0.1.8",
|
|
54
|
+
"iterable-operator": "^2.3.0"
|
|
55
55
|
}
|
|
56
56
|
}
|