funcity 0.2.0 → 0.3.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.cjs +416 -279
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +416 -279
- package/dist/index.mjs.map +1 -1
- package/dist/parser.d.ts +3 -266
- package/dist/parser.d.ts.map +1 -1
- package/dist/reducer.d.ts +7 -81
- package/dist/reducer.d.ts.map +1 -1
- package/dist/scripting.d.ts +10 -108
- package/dist/scripting.d.ts.map +1 -1
- package/dist/standards.d.ts +10 -5
- package/dist/standards.d.ts.map +1 -1
- package/dist/tokenizer.d.ts +3 -122
- package/dist/tokenizer.d.ts.map +1 -1
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +75 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +7 -7
package/dist/tokenizer.d.ts
CHANGED
|
@@ -1,133 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: funcity
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.3.0
|
|
4
4
|
* description: A functional language interpreter with text processing
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/funcity.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 220b26da1df7f7653a61cde67d006c26df5272da
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { FunCityErrorInfo,
|
|
12
|
-
/**
|
|
13
|
-
* The string token.
|
|
14
|
-
*/
|
|
15
|
-
export interface FunCityStringToken {
|
|
16
|
-
/**
|
|
17
|
-
* Token kind.
|
|
18
|
-
*/
|
|
19
|
-
readonly kind: 'string';
|
|
20
|
-
/**
|
|
21
|
-
* String value.
|
|
22
|
-
*/
|
|
23
|
-
readonly value: string;
|
|
24
|
-
/**
|
|
25
|
-
* Token range in source text.
|
|
26
|
-
*/
|
|
27
|
-
readonly range: FunCityRange;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* The number (numeric) token.
|
|
31
|
-
*/
|
|
32
|
-
export interface FunCityNumberToken {
|
|
33
|
-
/**
|
|
34
|
-
* Token kind.
|
|
35
|
-
*/
|
|
36
|
-
readonly kind: 'number';
|
|
37
|
-
/**
|
|
38
|
-
* Numeric value.
|
|
39
|
-
*/
|
|
40
|
-
readonly value: number;
|
|
41
|
-
/**
|
|
42
|
-
* Token range in source text.
|
|
43
|
-
*/
|
|
44
|
-
readonly range: FunCityRange;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The identity (variable name) token.
|
|
48
|
-
*/
|
|
49
|
-
export interface FunCityIdentityToken {
|
|
50
|
-
/**
|
|
51
|
-
* Token kind.
|
|
52
|
-
*/
|
|
53
|
-
readonly kind: 'identity';
|
|
54
|
-
/**
|
|
55
|
-
* Identity.
|
|
56
|
-
*/
|
|
57
|
-
readonly name: string;
|
|
58
|
-
/**
|
|
59
|
-
* Token range in source text.
|
|
60
|
-
*/
|
|
61
|
-
readonly range: FunCityRange;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Open parenthesis or bracket node.
|
|
65
|
-
*/
|
|
66
|
-
export interface FunCityOpenToken {
|
|
67
|
-
/**
|
|
68
|
-
* Token kind.
|
|
69
|
-
*/
|
|
70
|
-
readonly kind: 'open';
|
|
71
|
-
/**
|
|
72
|
-
* Open symbol.
|
|
73
|
-
*/
|
|
74
|
-
readonly symbol: string;
|
|
75
|
-
/**
|
|
76
|
-
* Token range in source text.
|
|
77
|
-
*/
|
|
78
|
-
readonly range: FunCityRange;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Close parenthesis or bracket token.
|
|
82
|
-
*/
|
|
83
|
-
export interface FunCityCloseToken {
|
|
84
|
-
/**
|
|
85
|
-
* Token kind.
|
|
86
|
-
*/
|
|
87
|
-
readonly kind: 'close';
|
|
88
|
-
/**
|
|
89
|
-
* Close symbol.
|
|
90
|
-
*/
|
|
91
|
-
readonly symbol: string;
|
|
92
|
-
/**
|
|
93
|
-
* Token range in source text.
|
|
94
|
-
*/
|
|
95
|
-
readonly range: FunCityRange;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* End of line token.
|
|
99
|
-
*/
|
|
100
|
-
export interface FunCityEndOfLineToken {
|
|
101
|
-
/**
|
|
102
|
-
* Token kind.
|
|
103
|
-
*/
|
|
104
|
-
readonly kind: 'eol';
|
|
105
|
-
/**
|
|
106
|
-
* Token range in source text.
|
|
107
|
-
*/
|
|
108
|
-
readonly range: FunCityRange;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Free form text token.
|
|
112
|
-
*/
|
|
113
|
-
export interface FunCityTextToken {
|
|
114
|
-
/**
|
|
115
|
-
* Token kind.
|
|
116
|
-
*/
|
|
117
|
-
readonly kind: 'text';
|
|
118
|
-
/**
|
|
119
|
-
* Text value.
|
|
120
|
-
*/
|
|
121
|
-
readonly text: string;
|
|
122
|
-
/**
|
|
123
|
-
* Token range in source text.
|
|
124
|
-
*/
|
|
125
|
-
readonly range: FunCityRange;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* The token.
|
|
129
|
-
*/
|
|
130
|
-
export type FunCityToken = FunCityStringToken | FunCityNumberToken | FunCityIdentityToken | FunCityOpenToken | FunCityCloseToken | FunCityEndOfLineToken | FunCityTextToken;
|
|
11
|
+
import { FunCityErrorInfo, FunCityToken } from './types';
|
|
131
12
|
/**
|
|
132
13
|
* Run the tokenizer.
|
|
133
14
|
* @param script - Input script text
|
package/dist/tokenizer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../src/tokenizer.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,KAAK,EACV,gBAAgB,
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../src/tokenizer.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,KAAK,EACV,gBAAgB,EAKhB,YAAY,EACb,MAAM,SAAS,CAAC;AA+gBjB;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,MAAM,EACd,QAAQ,gBAAgB,EAAE,KACzB,YAAY,EAiDd,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* name: funcity
|
|
3
|
+
* version: 0.3.0
|
|
4
|
+
* description: A functional language interpreter with text processing
|
|
5
|
+
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
|
+
* license: MIT
|
|
7
|
+
* repository.url: https://github.com/kekyo/funcity.git
|
|
8
|
+
* git.commit.hash: 220b26da1df7f7653a61cde67d006c26df5272da
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Location in source text.
|
|
13
|
+
*/
|
|
14
|
+
export interface FunCityLocation {
|
|
15
|
+
/**
|
|
16
|
+
* Line number (1-based).
|
|
17
|
+
*/
|
|
18
|
+
readonly line: number;
|
|
19
|
+
/**
|
|
20
|
+
* Column number (1-based).
|
|
21
|
+
*/
|
|
22
|
+
readonly column: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Range in source text.
|
|
26
|
+
*/
|
|
27
|
+
export interface FunCityRange {
|
|
28
|
+
/**
|
|
29
|
+
* Start location.
|
|
30
|
+
*/
|
|
31
|
+
readonly start: FunCityLocation;
|
|
32
|
+
/**
|
|
33
|
+
* End location.
|
|
34
|
+
*/
|
|
35
|
+
readonly end: FunCityLocation;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Error severity type.
|
|
39
|
+
*/
|
|
40
|
+
export type FunCityErrorType = 'warning' | 'error';
|
|
41
|
+
/**
|
|
42
|
+
* Error information with location.
|
|
43
|
+
*/
|
|
44
|
+
export interface FunCityErrorInfo {
|
|
45
|
+
/**
|
|
46
|
+
* Error severity.
|
|
47
|
+
*/
|
|
48
|
+
readonly type: FunCityErrorType;
|
|
49
|
+
/**
|
|
50
|
+
* Error description.
|
|
51
|
+
*/
|
|
52
|
+
readonly description: string;
|
|
53
|
+
/**
|
|
54
|
+
* Error range in source text.
|
|
55
|
+
*/
|
|
56
|
+
readonly range: FunCityRange;
|
|
57
|
+
}
|
|
58
|
+
export interface FunCityRangedObject {
|
|
59
|
+
/**
|
|
60
|
+
* This object range.
|
|
61
|
+
*/
|
|
62
|
+
readonly range: FunCityRange;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Variable map used by the reducer.
|
|
66
|
+
*/
|
|
67
|
+
export type FunCityVariables = ReadonlyMap<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* The string token.
|
|
70
|
+
*/
|
|
71
|
+
export interface FunCityStringToken extends FunCityRangedObject {
|
|
72
|
+
/**
|
|
73
|
+
* Token kind.
|
|
74
|
+
*/
|
|
75
|
+
readonly kind: 'string';
|
|
76
|
+
/**
|
|
77
|
+
* String value.
|
|
78
|
+
*/
|
|
79
|
+
readonly value: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The number (numeric) token.
|
|
83
|
+
*/
|
|
84
|
+
export interface FunCityNumberToken extends FunCityRangedObject {
|
|
85
|
+
/**
|
|
86
|
+
* Token kind.
|
|
87
|
+
*/
|
|
88
|
+
readonly kind: 'number';
|
|
89
|
+
/**
|
|
90
|
+
* Numeric value.
|
|
91
|
+
*/
|
|
92
|
+
readonly value: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The identity (variable name) token.
|
|
96
|
+
*/
|
|
97
|
+
export interface FunCityIdentityToken extends FunCityRangedObject {
|
|
98
|
+
/**
|
|
99
|
+
* Token kind.
|
|
100
|
+
*/
|
|
101
|
+
readonly kind: 'identity';
|
|
102
|
+
/**
|
|
103
|
+
* Identity.
|
|
104
|
+
*/
|
|
105
|
+
readonly name: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Open parenthesis or bracket node.
|
|
109
|
+
*/
|
|
110
|
+
export interface FunCityOpenToken extends FunCityRangedObject {
|
|
111
|
+
/**
|
|
112
|
+
* Token kind.
|
|
113
|
+
*/
|
|
114
|
+
readonly kind: 'open';
|
|
115
|
+
/**
|
|
116
|
+
* Open symbol.
|
|
117
|
+
*/
|
|
118
|
+
readonly symbol: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Close parenthesis or bracket token.
|
|
122
|
+
*/
|
|
123
|
+
export interface FunCityCloseToken extends FunCityRangedObject {
|
|
124
|
+
/**
|
|
125
|
+
* Token kind.
|
|
126
|
+
*/
|
|
127
|
+
readonly kind: 'close';
|
|
128
|
+
/**
|
|
129
|
+
* Close symbol.
|
|
130
|
+
*/
|
|
131
|
+
readonly symbol: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* End of line token.
|
|
135
|
+
*/
|
|
136
|
+
export interface FunCityEndOfLineToken extends FunCityRangedObject {
|
|
137
|
+
/**
|
|
138
|
+
* Token kind.
|
|
139
|
+
*/
|
|
140
|
+
readonly kind: 'eol';
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Free form text token.
|
|
144
|
+
*/
|
|
145
|
+
export interface FunCityTextToken extends FunCityRangedObject {
|
|
146
|
+
/**
|
|
147
|
+
* Token kind.
|
|
148
|
+
*/
|
|
149
|
+
readonly kind: 'text';
|
|
150
|
+
/**
|
|
151
|
+
* Text value.
|
|
152
|
+
*/
|
|
153
|
+
readonly text: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The token.
|
|
157
|
+
*/
|
|
158
|
+
export type FunCityToken = FunCityStringToken | FunCityNumberToken | FunCityIdentityToken | FunCityOpenToken | FunCityCloseToken | FunCityEndOfLineToken | FunCityTextToken;
|
|
159
|
+
/**
|
|
160
|
+
* String expression node.
|
|
161
|
+
*/
|
|
162
|
+
export interface FunCityStringNode extends FunCityRangedObject {
|
|
163
|
+
/**
|
|
164
|
+
* Node kind.
|
|
165
|
+
*/
|
|
166
|
+
readonly kind: 'string';
|
|
167
|
+
/**
|
|
168
|
+
* String value.
|
|
169
|
+
*/
|
|
170
|
+
readonly value: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Number (numeric) expression node.
|
|
174
|
+
*/
|
|
175
|
+
export interface FunCityNumberNode extends FunCityRangedObject {
|
|
176
|
+
/**
|
|
177
|
+
* Node kind.
|
|
178
|
+
*/
|
|
179
|
+
readonly kind: 'number';
|
|
180
|
+
/**
|
|
181
|
+
* Numeric value.
|
|
182
|
+
*/
|
|
183
|
+
readonly value: number;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Variable (identity) expression node.
|
|
187
|
+
*/
|
|
188
|
+
export interface FunCityVariableNode extends FunCityRangedObject {
|
|
189
|
+
/**
|
|
190
|
+
* Node kind.
|
|
191
|
+
*/
|
|
192
|
+
readonly kind: 'variable';
|
|
193
|
+
/**
|
|
194
|
+
* Variable name.
|
|
195
|
+
*/
|
|
196
|
+
readonly name: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Application expression node.
|
|
200
|
+
*/
|
|
201
|
+
export interface FunCityApplyNode extends FunCityRangedObject {
|
|
202
|
+
/**
|
|
203
|
+
* Node kind.
|
|
204
|
+
*/
|
|
205
|
+
readonly kind: 'apply';
|
|
206
|
+
/**
|
|
207
|
+
* Application target node.
|
|
208
|
+
*/
|
|
209
|
+
readonly func: FunCityExpressionNode;
|
|
210
|
+
/**
|
|
211
|
+
* Application arguments.
|
|
212
|
+
*/
|
|
213
|
+
readonly args: readonly FunCityExpressionNode[];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Lambda expression node.
|
|
217
|
+
*/
|
|
218
|
+
export interface FunCityLambdaNode extends FunCityRangedObject {
|
|
219
|
+
/**
|
|
220
|
+
* Node kind.
|
|
221
|
+
*/
|
|
222
|
+
readonly kind: 'lambda';
|
|
223
|
+
/**
|
|
224
|
+
* Parameter names.
|
|
225
|
+
*/
|
|
226
|
+
readonly names: readonly FunCityVariableNode[];
|
|
227
|
+
/**
|
|
228
|
+
* Lambda body expression.
|
|
229
|
+
*/
|
|
230
|
+
readonly body: FunCityExpressionNode;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Expression list (array) node.
|
|
234
|
+
*/
|
|
235
|
+
export interface FunCityListNode extends FunCityRangedObject {
|
|
236
|
+
/**
|
|
237
|
+
* Node kind.
|
|
238
|
+
*/
|
|
239
|
+
readonly kind: 'list';
|
|
240
|
+
/**
|
|
241
|
+
* List item nodes.
|
|
242
|
+
*/
|
|
243
|
+
readonly items: readonly FunCityExpressionNode[];
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Evaluate child scope node.
|
|
247
|
+
*/
|
|
248
|
+
export interface FunCityScopeNode extends FunCityRangedObject {
|
|
249
|
+
/**
|
|
250
|
+
* Node kind.
|
|
251
|
+
*/
|
|
252
|
+
readonly kind: 'scope';
|
|
253
|
+
/**
|
|
254
|
+
* Scoped node list.
|
|
255
|
+
* @remarks Reduced each nodes, but takes last one reduced value.
|
|
256
|
+
*/
|
|
257
|
+
readonly nodes: readonly FunCityExpressionNode[];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The expression node.
|
|
261
|
+
*/
|
|
262
|
+
export type FunCityExpressionNode = FunCityNumberNode | FunCityStringNode | FunCityVariableNode | FunCityApplyNode | FunCityLambdaNode | FunCityListNode | FunCityScopeNode;
|
|
263
|
+
/**
|
|
264
|
+
* Text block node.
|
|
265
|
+
*/
|
|
266
|
+
export interface FunCityTextNode extends FunCityRangedObject {
|
|
267
|
+
/**
|
|
268
|
+
* Node kind.
|
|
269
|
+
*/
|
|
270
|
+
readonly kind: 'text';
|
|
271
|
+
/**
|
|
272
|
+
* Text body.
|
|
273
|
+
*/
|
|
274
|
+
readonly text: string;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Conditional branch (`if`) block node contains else block.
|
|
278
|
+
*/
|
|
279
|
+
export interface FunCityIfNode extends FunCityRangedObject {
|
|
280
|
+
/**
|
|
281
|
+
* Node kind.
|
|
282
|
+
*/
|
|
283
|
+
readonly kind: 'if';
|
|
284
|
+
/**
|
|
285
|
+
* Condition expression node.
|
|
286
|
+
*/
|
|
287
|
+
readonly condition: FunCityExpressionNode;
|
|
288
|
+
/**
|
|
289
|
+
* Then (true) block node.
|
|
290
|
+
*/
|
|
291
|
+
readonly then: readonly FunCityBlockNode[];
|
|
292
|
+
/**
|
|
293
|
+
* Else (false) block node.
|
|
294
|
+
*/
|
|
295
|
+
readonly else: readonly FunCityBlockNode[];
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Conditional repeats (`while`) block node contains else block.
|
|
299
|
+
*/
|
|
300
|
+
export interface FunCityWhileNode extends FunCityRangedObject {
|
|
301
|
+
/**
|
|
302
|
+
* Node kind.
|
|
303
|
+
*/
|
|
304
|
+
readonly kind: 'while';
|
|
305
|
+
/**
|
|
306
|
+
* Condition expression node.
|
|
307
|
+
*/
|
|
308
|
+
readonly condition: FunCityExpressionNode;
|
|
309
|
+
/**
|
|
310
|
+
* Repeat block node.
|
|
311
|
+
*/
|
|
312
|
+
readonly repeat: readonly FunCityBlockNode[];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Item iteration (`for`) block node contains else block.
|
|
316
|
+
*/
|
|
317
|
+
export interface FunCityForNode extends FunCityRangedObject {
|
|
318
|
+
/**
|
|
319
|
+
* Node kind.
|
|
320
|
+
*/
|
|
321
|
+
readonly kind: 'for';
|
|
322
|
+
/**
|
|
323
|
+
* Bind variable node in each iteration.
|
|
324
|
+
*/
|
|
325
|
+
readonly bind: FunCityVariableNode;
|
|
326
|
+
/**
|
|
327
|
+
* Iteration target expression node.
|
|
328
|
+
*/
|
|
329
|
+
readonly iterable: FunCityExpressionNode;
|
|
330
|
+
/**
|
|
331
|
+
* Repeat block node.
|
|
332
|
+
*/
|
|
333
|
+
readonly repeat: readonly FunCityBlockNode[];
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The block node.
|
|
337
|
+
*/
|
|
338
|
+
export type FunCityBlockNode = FunCityExpressionNode | FunCityTextNode | FunCityIfNode | FunCityWhileNode | FunCityForNode;
|
|
339
|
+
export interface ParserCursor {
|
|
340
|
+
/**
|
|
341
|
+
* Peek one token.
|
|
342
|
+
* @returns A token or undefined when reached end of token.
|
|
343
|
+
*/
|
|
344
|
+
peekToken: () => FunCityToken | undefined;
|
|
345
|
+
/**
|
|
346
|
+
* Get one token and advance.
|
|
347
|
+
* @returns A token or undefined when reached end of token.
|
|
348
|
+
*/
|
|
349
|
+
takeToken: () => FunCityToken | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* Skip one token.
|
|
352
|
+
*/
|
|
353
|
+
skipToken: () => void;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Variable value result.
|
|
357
|
+
*/
|
|
358
|
+
export interface FunCityReducerContextValueResult {
|
|
359
|
+
/**
|
|
360
|
+
* Variable value.
|
|
361
|
+
*/
|
|
362
|
+
readonly value: unknown;
|
|
363
|
+
/**
|
|
364
|
+
* Is this found?
|
|
365
|
+
*/
|
|
366
|
+
readonly isFound: boolean;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Native function context.
|
|
370
|
+
*/
|
|
371
|
+
export interface FunCityFunctionContext {
|
|
372
|
+
/**
|
|
373
|
+
* Current function application node.
|
|
374
|
+
*/
|
|
375
|
+
readonly thisNode: FunCityExpressionNode;
|
|
376
|
+
/**
|
|
377
|
+
* Get current abort signal object.
|
|
378
|
+
* @returns AbortSignal when available.
|
|
379
|
+
*/
|
|
380
|
+
readonly abortSignal: AbortSignal | undefined;
|
|
381
|
+
/**
|
|
382
|
+
* Get current context (scope) variable value.
|
|
383
|
+
* @param name - Variable name
|
|
384
|
+
* @returns Variable value information
|
|
385
|
+
*/
|
|
386
|
+
readonly getValue: (name: string) => FunCityReducerContextValueResult;
|
|
387
|
+
/**
|
|
388
|
+
* Set current context (scope) variable value.
|
|
389
|
+
* @param name - Variable name
|
|
390
|
+
* @param value - New value
|
|
391
|
+
*/
|
|
392
|
+
readonly setValue: (name: string, value: unknown) => void;
|
|
393
|
+
/**
|
|
394
|
+
* Append context error.
|
|
395
|
+
* @param error - Error or warning information.
|
|
396
|
+
*/
|
|
397
|
+
readonly appendError: (error: FunCityErrorInfo) => void;
|
|
398
|
+
/**
|
|
399
|
+
* Indicate error received.
|
|
400
|
+
* @returns The context is received any errors.
|
|
401
|
+
*/
|
|
402
|
+
readonly isFailed: () => boolean;
|
|
403
|
+
/**
|
|
404
|
+
* Reduce expression node with this context.
|
|
405
|
+
* @param node - Target node
|
|
406
|
+
* @returns Reduced value.
|
|
407
|
+
*/
|
|
408
|
+
readonly reduce: (node: FunCityExpressionNode) => Promise<unknown>;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* The reducer context.
|
|
412
|
+
*/
|
|
413
|
+
export interface FunCityReducerContext {
|
|
414
|
+
/**
|
|
415
|
+
* Get current abort signal object.
|
|
416
|
+
* @returns AbortSignal when available.
|
|
417
|
+
*/
|
|
418
|
+
readonly abortSignal: AbortSignal | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Get current context (scope) variable value.
|
|
421
|
+
* @param name - Variable name
|
|
422
|
+
* @returns Variable value information
|
|
423
|
+
*/
|
|
424
|
+
readonly getValue: (name: string) => FunCityReducerContextValueResult;
|
|
425
|
+
/**
|
|
426
|
+
* Set current context (scope) variable value.
|
|
427
|
+
* @param name - Variable name
|
|
428
|
+
* @param value - New value
|
|
429
|
+
*/
|
|
430
|
+
readonly setValue: (name: string, value: unknown) => void;
|
|
431
|
+
/**
|
|
432
|
+
* Append context error.
|
|
433
|
+
* @param error - Error or warning information.
|
|
434
|
+
*/
|
|
435
|
+
readonly appendError: (error: FunCityErrorInfo) => void;
|
|
436
|
+
/**
|
|
437
|
+
* Indicate error received.
|
|
438
|
+
* @returns The context is received any errors.
|
|
439
|
+
*/
|
|
440
|
+
readonly isFailed: () => boolean;
|
|
441
|
+
/**
|
|
442
|
+
* Create new scoped context.
|
|
443
|
+
* @returns New reducer context.
|
|
444
|
+
*/
|
|
445
|
+
readonly newScope: () => FunCityReducerContext;
|
|
446
|
+
/**
|
|
447
|
+
* Create native function context proxy.
|
|
448
|
+
* @param thisNode Current node (Indicating the current application is expected)
|
|
449
|
+
* @returns Native function context proxy instance.
|
|
450
|
+
*/
|
|
451
|
+
readonly createFunctionContext: (thisNode: FunCityExpressionNode) => FunCityFunctionContext;
|
|
452
|
+
}
|
|
453
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;AAOA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,OAAO,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,YAAY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AAgB,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC;IACjC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACpE;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IAC9C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gCAAgC,CAAC;IACtE;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1D;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,qBAAqB,CAAC;IAC/C;;;;OAIG;IACH,QAAQ,CAAC,qBAAqB,EAAE,CAC9B,QAAQ,EAAE,qBAAqB,KAC5B,sBAAsB,CAAC;CAC7B"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* name: funcity
|
|
3
|
+
* version: 0.3.0
|
|
4
|
+
* description: A functional language interpreter with text processing
|
|
5
|
+
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
|
+
* license: MIT
|
|
7
|
+
* repository.url: https://github.com/kekyo/funcity.git
|
|
8
|
+
* git.commit.hash: 220b26da1df7f7653a61cde67d006c26df5272da
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { FunCityErrorInfo, FunCityLocation, FunCityRange, FunCityVariables } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Empty location with zeroed coordinates.
|
|
14
|
+
*/
|
|
15
|
+
export declare const emptyLocation: FunCityLocation;
|
|
16
|
+
/**
|
|
17
|
+
* Empty range with zeroed coordinates.
|
|
18
|
+
*/
|
|
19
|
+
export declare const emptyRange: FunCityRange;
|
|
20
|
+
/**
|
|
21
|
+
* Mark a function as a funcity special function.
|
|
22
|
+
* @param f - Target function.
|
|
23
|
+
* @returns The same function with a marker.
|
|
24
|
+
*/
|
|
25
|
+
export declare const makeFunCityFunction: (f: Function) => Function;
|
|
26
|
+
/**
|
|
27
|
+
* Check whether a function is marked as funcity special function.
|
|
28
|
+
* @param f - Target function.
|
|
29
|
+
* @returns True when marked.
|
|
30
|
+
*/
|
|
31
|
+
export declare const isFunCityFunction: (f: Function) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Evaluate value with the interpreter's conditional semantics.
|
|
34
|
+
* @param v - Target value.
|
|
35
|
+
* @returns True when the value should be treated as truthy.
|
|
36
|
+
*/
|
|
37
|
+
export declare const isConditionalTrue: (v: unknown) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Cast a value to iterable when it has a default iterator.
|
|
40
|
+
* @param v - Target value.
|
|
41
|
+
* @returns Iterable instance or undefined when not iterable.
|
|
42
|
+
*/
|
|
43
|
+
export declare const asIterable: (v: unknown) => Iterable<unknown> | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Combine variable maps or records into a single variable map.
|
|
46
|
+
* @param variablesList - Variable sources to merge.
|
|
47
|
+
* @returns Combined variable map.
|
|
48
|
+
*/
|
|
49
|
+
export declare const combineVariables: (...variablesList: readonly (FunCityVariables | Record<string, unknown>)[]) => FunCityVariables;
|
|
50
|
+
/**
|
|
51
|
+
* Convert an error object into a human-readable message.
|
|
52
|
+
* @param error - Error object.
|
|
53
|
+
* @returns Error message.
|
|
54
|
+
*/
|
|
55
|
+
export declare const fromError: (error: any) => string;
|
|
56
|
+
/**
|
|
57
|
+
* Build a range that covers all provided ranges.
|
|
58
|
+
* @param ranges - Ranges to cover.
|
|
59
|
+
* @returns The widest range.
|
|
60
|
+
*/
|
|
61
|
+
export declare const widerRange: (...ranges: FunCityRange[]) => FunCityRange;
|
|
62
|
+
/**
|
|
63
|
+
* Output error list and return whether any error-level entry exists.
|
|
64
|
+
* @param path - Source path.
|
|
65
|
+
* @param errors - Errors to output.
|
|
66
|
+
* @returns True when an error-level entry exists.
|
|
67
|
+
*/
|
|
68
|
+
export declare const outputErrors: (path: string, errors: readonly FunCityErrorInfo[]) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Convert to string.
|
|
71
|
+
* @param v Target instance
|
|
72
|
+
* @returns String
|
|
73
|
+
*/
|
|
74
|
+
export declare const convertToString: (v: unknown) => string;
|
|
75
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,eAGlB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,YAGf,CAAC;AAIX;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,GAAG,QAAQ,aAG9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,GAAG,QAAQ,KAAG,OAE/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,GAAG,OAAO,YAa3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,OAAO,KAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,SAM3D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,GAAG,eAAe,SAAS,CAAC,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,KACxE,gBAkBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,GAAG,KAAG,MAQtC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,QAAQ,YAAY,EAAE,KAAG,YA4BtD,CAAC;AA0BF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,QAAQ,SAAS,gBAAgB,EAAE,YAQpC,CAAC;AAeF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,GAAG,OAAO,KAAG,MAyC5C,CAAC"}
|