agency-lang 0.0.15 → 0.0.17
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/lib/backends/agencyGenerator.js +24 -6
- package/dist/lib/backends/agencyGenerator.test.d.ts +1 -0
- package/dist/lib/backends/agencyGenerator.test.js +205 -0
- package/dist/lib/backends/baseGenerator.d.ts +1 -0
- package/dist/lib/backends/baseGenerator.js +12 -2
- package/dist/lib/backends/graphGenerator.js +7 -5
- package/dist/lib/backends/typescriptGenerator.d.ts +3 -3
- package/dist/lib/backends/typescriptGenerator.js +17 -11
- package/dist/lib/parsers/access.d.ts +3 -5
- package/dist/lib/parsers/access.js +54 -13
- package/dist/lib/parsers/access.test.js +40 -500
- package/dist/lib/parsers/assignment.js +2 -2
- package/dist/lib/parsers/assignment.test.d.ts +1 -0
- package/dist/lib/parsers/assignment.test.js +279 -0
- package/dist/lib/parsers/dataStructures.js +3 -3
- package/dist/lib/parsers/function.d.ts +3 -1
- package/dist/lib/parsers/function.js +6 -4
- package/dist/lib/parsers/function.test.js +653 -8
- package/dist/lib/parsers/functionCall.js +3 -2
- package/dist/lib/parsers/functionCall.test.js +310 -0
- package/dist/lib/parsers/literals.d.ts +2 -1
- package/dist/lib/parsers/literals.js +15 -5
- package/dist/lib/parsers/literals.test.js +189 -16
- package/dist/lib/parsers/matchBlock.js +2 -2
- package/dist/lib/parsers/parserUtils.test.d.ts +1 -0
- package/dist/lib/parsers/parserUtils.test.js +46 -0
- package/dist/lib/parsers/returnStatement.js +2 -2
- package/dist/lib/parsers/returnStatement.test.d.ts +1 -0
- package/dist/lib/parsers/returnStatement.test.js +268 -0
- package/dist/lib/parsers/specialVar.test.d.ts +1 -0
- package/dist/lib/parsers/specialVar.test.js +219 -0
- package/dist/lib/types/access.d.ts +5 -5
- package/dist/lib/types/access.js +6 -1
- package/dist/lib/types/dataStructures.d.ts +3 -3
- package/dist/lib/types/function.d.ts +10 -4
- package/dist/lib/types/literals.d.ts +5 -1
- package/dist/lib/types/matchBlock.d.ts +2 -2
- package/dist/lib/types/returnStatement.d.ts +2 -2
- package/dist/lib/types/whileLoop.d.ts +2 -2
- package/dist/lib/types.d.ts +3 -3
- package/package.json +2 -2
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { capture, char, many1WithJoin, or, sepBy, seqC, seqR, set, } from "tarsec";
|
|
2
|
-
import { accessExpressionParser } from "./access.js";
|
|
2
|
+
import { accessExpressionParser, indexAccessParser } from "./access.js";
|
|
3
3
|
import { literalParser } from "./literals.js";
|
|
4
4
|
import { optionalSemicolon } from "./parserUtils.js";
|
|
5
5
|
import { optionalSpaces, varNameChar } from "./utils.js";
|
|
6
|
+
import { agencyArrayParser, agencyObjectParser } from "./dataStructures.js";
|
|
6
7
|
const comma = seqR(optionalSpaces, char(","), optionalSpaces);
|
|
7
8
|
export const functionCallParser = (input) => {
|
|
8
|
-
const parser = seqC(set("type", "functionCall"), capture(many1WithJoin(varNameChar), "functionName"), char("("), optionalSpaces, capture(sepBy(comma, or(functionCallParser, accessExpressionParser, literalParser)), "arguments"), optionalSpaces, char(")"), optionalSemicolon);
|
|
9
|
+
const parser = seqC(set("type", "functionCall"), capture(many1WithJoin(varNameChar), "functionName"), char("("), optionalSpaces, capture(sepBy(comma, or(agencyArrayParser, agencyObjectParser, indexAccessParser, functionCallParser, accessExpressionParser, literalParser)), "arguments"), optionalSpaces, char(")"), optionalSemicolon);
|
|
9
10
|
return parser(input);
|
|
10
11
|
};
|
|
@@ -98,6 +98,316 @@ describe("functionCallParser", () => {
|
|
|
98
98
|
input: "",
|
|
99
99
|
expected: { success: false },
|
|
100
100
|
},
|
|
101
|
+
// Function calls with array arguments
|
|
102
|
+
{
|
|
103
|
+
input: "processArray([1, 2, 3])",
|
|
104
|
+
expected: {
|
|
105
|
+
success: true,
|
|
106
|
+
result: {
|
|
107
|
+
type: "functionCall",
|
|
108
|
+
functionName: "processArray",
|
|
109
|
+
arguments: [
|
|
110
|
+
{
|
|
111
|
+
type: "agencyArray",
|
|
112
|
+
items: [
|
|
113
|
+
{ type: "number", value: "1" },
|
|
114
|
+
{ type: "number", value: "2" },
|
|
115
|
+
{ type: "number", value: "3" },
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
input: "processArray([1, 2, 3, 4, 5])",
|
|
124
|
+
expected: {
|
|
125
|
+
success: true,
|
|
126
|
+
result: {
|
|
127
|
+
type: "functionCall",
|
|
128
|
+
functionName: "processArray",
|
|
129
|
+
arguments: [
|
|
130
|
+
{
|
|
131
|
+
type: "agencyArray",
|
|
132
|
+
items: [
|
|
133
|
+
{ type: "number", value: "1" },
|
|
134
|
+
{ type: "number", value: "2" },
|
|
135
|
+
{ type: "number", value: "3" },
|
|
136
|
+
{ type: "number", value: "4" },
|
|
137
|
+
{ type: "number", value: "5" },
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
input: "handleStrings([\"hello\", \"world\"])",
|
|
146
|
+
expected: {
|
|
147
|
+
success: true,
|
|
148
|
+
result: {
|
|
149
|
+
type: "functionCall",
|
|
150
|
+
functionName: "handleStrings",
|
|
151
|
+
arguments: [
|
|
152
|
+
{
|
|
153
|
+
type: "agencyArray",
|
|
154
|
+
items: [
|
|
155
|
+
{ type: "string", value: "hello" },
|
|
156
|
+
{ type: "string", value: "world" },
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
input: "processEmpty([])",
|
|
165
|
+
expected: {
|
|
166
|
+
success: true,
|
|
167
|
+
result: {
|
|
168
|
+
type: "functionCall",
|
|
169
|
+
functionName: "processEmpty",
|
|
170
|
+
arguments: [
|
|
171
|
+
{
|
|
172
|
+
type: "agencyArray",
|
|
173
|
+
items: [],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
input: "processNested([[1, 2], [3, 4]])",
|
|
181
|
+
expected: {
|
|
182
|
+
success: true,
|
|
183
|
+
result: {
|
|
184
|
+
type: "functionCall",
|
|
185
|
+
functionName: "processNested",
|
|
186
|
+
arguments: [
|
|
187
|
+
{
|
|
188
|
+
type: "agencyArray",
|
|
189
|
+
items: [
|
|
190
|
+
{
|
|
191
|
+
type: "agencyArray",
|
|
192
|
+
items: [
|
|
193
|
+
{ type: "number", value: "1" },
|
|
194
|
+
{ type: "number", value: "2" },
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: "agencyArray",
|
|
199
|
+
items: [
|
|
200
|
+
{ type: "number", value: "3" },
|
|
201
|
+
{ type: "number", value: "4" },
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
// Function calls with object arguments
|
|
211
|
+
{
|
|
212
|
+
input: "configure({key: \"value\"})",
|
|
213
|
+
expected: {
|
|
214
|
+
success: true,
|
|
215
|
+
result: {
|
|
216
|
+
type: "functionCall",
|
|
217
|
+
functionName: "configure",
|
|
218
|
+
arguments: [
|
|
219
|
+
{
|
|
220
|
+
type: "agencyObject",
|
|
221
|
+
entries: [
|
|
222
|
+
{
|
|
223
|
+
key: "key",
|
|
224
|
+
value: { type: "string", value: "value" },
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
input: "createUser({name: \"Alice\", age: 30})",
|
|
234
|
+
expected: {
|
|
235
|
+
success: true,
|
|
236
|
+
result: {
|
|
237
|
+
type: "functionCall",
|
|
238
|
+
functionName: "createUser",
|
|
239
|
+
arguments: [
|
|
240
|
+
{
|
|
241
|
+
type: "agencyObject",
|
|
242
|
+
entries: [
|
|
243
|
+
{
|
|
244
|
+
key: "name",
|
|
245
|
+
value: { type: "string", value: "Alice" },
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
key: "age",
|
|
249
|
+
value: { type: "number", value: "30" },
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
input: "initialize({})",
|
|
259
|
+
expected: {
|
|
260
|
+
success: true,
|
|
261
|
+
result: {
|
|
262
|
+
type: "functionCall",
|
|
263
|
+
functionName: "initialize",
|
|
264
|
+
arguments: [
|
|
265
|
+
{
|
|
266
|
+
type: "agencyObject",
|
|
267
|
+
entries: [],
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
input: "processData({items: [1, 2, 3]})",
|
|
275
|
+
expected: {
|
|
276
|
+
success: true,
|
|
277
|
+
result: {
|
|
278
|
+
type: "functionCall",
|
|
279
|
+
functionName: "processData",
|
|
280
|
+
arguments: [
|
|
281
|
+
{
|
|
282
|
+
type: "agencyObject",
|
|
283
|
+
entries: [
|
|
284
|
+
{
|
|
285
|
+
key: "items",
|
|
286
|
+
value: {
|
|
287
|
+
type: "agencyArray",
|
|
288
|
+
items: [
|
|
289
|
+
{ type: "number", value: "1" },
|
|
290
|
+
{ type: "number", value: "2" },
|
|
291
|
+
{ type: "number", value: "3" },
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
input: "nestedConfig({outer: {inner: 42}})",
|
|
303
|
+
expected: {
|
|
304
|
+
success: true,
|
|
305
|
+
result: {
|
|
306
|
+
type: "functionCall",
|
|
307
|
+
functionName: "nestedConfig",
|
|
308
|
+
arguments: [
|
|
309
|
+
{
|
|
310
|
+
type: "agencyObject",
|
|
311
|
+
entries: [
|
|
312
|
+
{
|
|
313
|
+
key: "outer",
|
|
314
|
+
value: {
|
|
315
|
+
type: "agencyObject",
|
|
316
|
+
entries: [
|
|
317
|
+
{
|
|
318
|
+
key: "inner",
|
|
319
|
+
value: { type: "number", value: "42" },
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
// Function calls with mixed arguments
|
|
331
|
+
{
|
|
332
|
+
input: "mixed(42, [1, 2], {key: \"value\"})",
|
|
333
|
+
expected: {
|
|
334
|
+
success: true,
|
|
335
|
+
result: {
|
|
336
|
+
type: "functionCall",
|
|
337
|
+
functionName: "mixed",
|
|
338
|
+
arguments: [
|
|
339
|
+
{ type: "number", value: "42" },
|
|
340
|
+
{
|
|
341
|
+
type: "agencyArray",
|
|
342
|
+
items: [
|
|
343
|
+
{ type: "number", value: "1" },
|
|
344
|
+
{ type: "number", value: "2" },
|
|
345
|
+
],
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
type: "agencyObject",
|
|
349
|
+
entries: [
|
|
350
|
+
{
|
|
351
|
+
key: "key",
|
|
352
|
+
value: { type: "string", value: "value" },
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
input: "complexCall(\"test\", [], {}, 100)",
|
|
362
|
+
expected: {
|
|
363
|
+
success: true,
|
|
364
|
+
result: {
|
|
365
|
+
type: "functionCall",
|
|
366
|
+
functionName: "complexCall",
|
|
367
|
+
arguments: [
|
|
368
|
+
{ type: "string", value: "test" },
|
|
369
|
+
{
|
|
370
|
+
type: "agencyArray",
|
|
371
|
+
items: [],
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
type: "agencyObject",
|
|
375
|
+
entries: [],
|
|
376
|
+
},
|
|
377
|
+
{ type: "number", value: "100" },
|
|
378
|
+
],
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
input: "withVariables(x, [y, z], {key: value})",
|
|
384
|
+
expected: {
|
|
385
|
+
success: true,
|
|
386
|
+
result: {
|
|
387
|
+
type: "functionCall",
|
|
388
|
+
functionName: "withVariables",
|
|
389
|
+
arguments: [
|
|
390
|
+
{ type: "variableName", value: "x" },
|
|
391
|
+
{
|
|
392
|
+
type: "agencyArray",
|
|
393
|
+
items: [
|
|
394
|
+
{ type: "variableName", value: "y" },
|
|
395
|
+
{ type: "variableName", value: "z" },
|
|
396
|
+
],
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
type: "agencyObject",
|
|
400
|
+
entries: [
|
|
401
|
+
{
|
|
402
|
+
key: "key",
|
|
403
|
+
value: { type: "variableName", value: "value" },
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
},
|
|
101
411
|
];
|
|
102
412
|
testCases.forEach(({ input, expected }) => {
|
|
103
413
|
if (expected.success) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { InterpolationSegment, Literal, NumberLiteral, PromptLiteral, StringLiteral, TextSegment, VariableNameLiteral } from "../types.js";
|
|
1
|
+
import { InterpolationSegment, Literal, MultiLineStringLiteral, NumberLiteral, PromptLiteral, StringLiteral, TextSegment, VariableNameLiteral } from "../types.js";
|
|
2
2
|
import { Parser } from "tarsec";
|
|
3
3
|
export declare const textSegmentParser: Parser<TextSegment>;
|
|
4
4
|
export declare const interpolationSegmentParser: Parser<InterpolationSegment>;
|
|
5
5
|
export declare const promptParser: Parser<PromptLiteral>;
|
|
6
6
|
export declare const numberParser: Parser<NumberLiteral>;
|
|
7
7
|
export declare const stringParser: Parser<StringLiteral>;
|
|
8
|
+
export declare const multiLineStringParser: Parser<MultiLineStringLiteral>;
|
|
8
9
|
export declare const variableNameParser: Parser<VariableNameLiteral>;
|
|
9
10
|
export declare const literalParser: Parser<Literal>;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { backtick, varNameChar } from "./utils.js";
|
|
2
|
-
import { capture, char, digit, many, many1Till, many1WithJoin,
|
|
2
|
+
import { capture, char, digit, letter, many, many1Till, many1WithJoin, manyTillOneOf, manyTillStr, manyWithJoin, map, or, seq, seqC, set, str, } from "tarsec";
|
|
3
3
|
export const textSegmentParser = map(many1Till(or(backtick, char("$"))), (text) => ({
|
|
4
4
|
type: "text",
|
|
5
5
|
value: text,
|
|
6
6
|
}));
|
|
7
|
-
export const interpolationSegmentParser = seqC(set("type", "interpolation"), char("$"), char("{"), capture(
|
|
7
|
+
export const interpolationSegmentParser = seqC(set("type", "interpolation"), char("$"), char("{"), capture(manyTillStr("}"), "variableName"), char("}"));
|
|
8
8
|
export const promptParser = seqC(set("type", "prompt"), backtick, capture(many(or(textSegmentParser, interpolationSegmentParser)), "segments"), backtick);
|
|
9
9
|
export const numberParser = seqC(set("type", "number"), capture(many1WithJoin(or(char("-"), char("."), digit)), "value"));
|
|
10
|
-
export const stringParser = seqC(set("type", "string"), char('"'), capture(
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
10
|
+
export const stringParser = seqC(set("type", "string"), char('"'), capture(manyTillOneOf(['"', "\n"]), "value"), char('"'));
|
|
11
|
+
export const multiLineStringParser = seqC(set("type", "multiLineString"), str('"""'), capture(manyTillStr('"""'), "value"), str('"""'));
|
|
12
|
+
export const variableNameParser = seq([
|
|
13
|
+
set("type", "variableName"),
|
|
14
|
+
capture(letter, "init"),
|
|
15
|
+
capture(manyWithJoin(varNameChar), "value"),
|
|
16
|
+
], (_, captures) => {
|
|
17
|
+
return {
|
|
18
|
+
type: "variableName",
|
|
19
|
+
value: `${captures.init}${captures.value}`,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
export const literalParser = or(promptParser, numberParser, multiLineStringParser, stringParser, variableNameParser);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { textSegmentParser, interpolationSegmentParser, promptParser, numberParser, stringParser, variableNameParser, literalParser, } from "./literals.js";
|
|
2
|
+
import { textSegmentParser, interpolationSegmentParser, promptParser, numberParser, stringParser, multiLineStringParser, variableNameParser, literalParser, } from "./literals.js";
|
|
3
3
|
describe("literals parsers", () => {
|
|
4
4
|
describe("textSegmentParser", () => {
|
|
5
5
|
const testCases = [
|
|
@@ -112,7 +112,16 @@ describe("literals parsers", () => {
|
|
|
112
112
|
{ input: "${foo", expected: { success: false } },
|
|
113
113
|
{ input: "$foo}", expected: { success: false } },
|
|
114
114
|
{ input: "{foo}", expected: { success: false } },
|
|
115
|
-
{
|
|
115
|
+
{
|
|
116
|
+
input: "${}",
|
|
117
|
+
expected: {
|
|
118
|
+
success: true,
|
|
119
|
+
result: {
|
|
120
|
+
type: "interpolation",
|
|
121
|
+
variableName: "",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
116
125
|
{ input: "", expected: { success: false } },
|
|
117
126
|
{ input: "foo", expected: { success: false } },
|
|
118
127
|
];
|
|
@@ -391,13 +400,6 @@ describe("literals parsers", () => {
|
|
|
391
400
|
result: { type: "string", value: "tab\there" },
|
|
392
401
|
},
|
|
393
402
|
},
|
|
394
|
-
{
|
|
395
|
-
input: '"newline\nhere"',
|
|
396
|
-
expected: {
|
|
397
|
-
success: true,
|
|
398
|
-
result: { type: "string", value: "newline\nhere" },
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
403
|
{
|
|
402
404
|
input: '"special!@#$%^&*()"',
|
|
403
405
|
expected: {
|
|
@@ -425,6 +427,13 @@ describe("literals parsers", () => {
|
|
|
425
427
|
{ input: "'hello'", expected: { success: false } },
|
|
426
428
|
{ input: "", expected: { success: false } },
|
|
427
429
|
{ input: "hello", expected: { success: false } },
|
|
430
|
+
/// use """ for multi-line strings
|
|
431
|
+
{
|
|
432
|
+
input: '"newline\nhere"',
|
|
433
|
+
expected: {
|
|
434
|
+
success: false,
|
|
435
|
+
},
|
|
436
|
+
},
|
|
428
437
|
];
|
|
429
438
|
testCases.forEach(({ input, expected }) => {
|
|
430
439
|
if (expected.success) {
|
|
@@ -444,6 +453,170 @@ describe("literals parsers", () => {
|
|
|
444
453
|
}
|
|
445
454
|
});
|
|
446
455
|
});
|
|
456
|
+
describe("multiLineStringParser", () => {
|
|
457
|
+
const testCases = [
|
|
458
|
+
// Happy path - simple strings
|
|
459
|
+
{
|
|
460
|
+
input: '"""hello"""',
|
|
461
|
+
expected: {
|
|
462
|
+
success: true,
|
|
463
|
+
result: { type: "multiLineString", value: "hello" },
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
input: '"""world"""',
|
|
468
|
+
expected: {
|
|
469
|
+
success: true,
|
|
470
|
+
result: { type: "multiLineString", value: "world" },
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
// Empty multi-line string
|
|
474
|
+
{
|
|
475
|
+
input: '""""""',
|
|
476
|
+
expected: {
|
|
477
|
+
success: true,
|
|
478
|
+
result: { type: "multiLineString", value: "" },
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
// Multi-line strings with actual newlines
|
|
482
|
+
{
|
|
483
|
+
input: '"""line1\nline2"""',
|
|
484
|
+
expected: {
|
|
485
|
+
success: true,
|
|
486
|
+
result: { type: "multiLineString", value: "line1\nline2" },
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
input: '"""line1\nline2\nline3"""',
|
|
491
|
+
expected: {
|
|
492
|
+
success: true,
|
|
493
|
+
result: { type: "multiLineString", value: "line1\nline2\nline3" },
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
input: '"""\nstarts with newline"""',
|
|
498
|
+
expected: {
|
|
499
|
+
success: true,
|
|
500
|
+
result: { type: "multiLineString", value: "\nstarts with newline" },
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
input: '"""ends with newline\n"""',
|
|
505
|
+
expected: {
|
|
506
|
+
success: true,
|
|
507
|
+
result: { type: "multiLineString", value: "ends with newline\n" },
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
// Strings with special characters
|
|
511
|
+
{
|
|
512
|
+
input: '"""Hello, World!"""',
|
|
513
|
+
expected: {
|
|
514
|
+
success: true,
|
|
515
|
+
result: { type: "multiLineString", value: "Hello, World!" },
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
input: '"""123"""',
|
|
520
|
+
expected: {
|
|
521
|
+
success: true,
|
|
522
|
+
result: { type: "multiLineString", value: "123" },
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
input: '""" spaces and tabs\t\t"""',
|
|
527
|
+
expected: {
|
|
528
|
+
success: true,
|
|
529
|
+
result: { type: "multiLineString", value: " spaces and tabs\t\t" },
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
input: '"""special!@#$%^&*()"""',
|
|
534
|
+
expected: {
|
|
535
|
+
success: true,
|
|
536
|
+
result: { type: "multiLineString", value: "special!@#$%^&*()" },
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
// Strings containing single and double quotes
|
|
540
|
+
{
|
|
541
|
+
input: '"""single\'quotes\'here"""',
|
|
542
|
+
expected: {
|
|
543
|
+
success: true,
|
|
544
|
+
result: { type: "multiLineString", value: "single'quotes'here" },
|
|
545
|
+
},
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
input: '"""double"quotes"here"""',
|
|
549
|
+
expected: {
|
|
550
|
+
success: true,
|
|
551
|
+
result: { type: "multiLineString", value: 'double"quotes"here' },
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
input: '"""mixed"and\'quotes"""',
|
|
556
|
+
expected: {
|
|
557
|
+
success: true,
|
|
558
|
+
result: { type: "multiLineString", value: `mixed"and'quotes` },
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
// Strings containing backticks and interpolation-like syntax
|
|
562
|
+
{
|
|
563
|
+
input: '"""`backtick`"""',
|
|
564
|
+
expected: {
|
|
565
|
+
success: true,
|
|
566
|
+
result: { type: "multiLineString", value: "`backtick`" },
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
input: '"""${notInterpolation}"""',
|
|
571
|
+
expected: {
|
|
572
|
+
success: true,
|
|
573
|
+
result: { type: "multiLineString", value: "${notInterpolation}" },
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
// Multiple consecutive newlines
|
|
577
|
+
{
|
|
578
|
+
input: '"""line1\n\n\nline2"""',
|
|
579
|
+
expected: {
|
|
580
|
+
success: true,
|
|
581
|
+
result: { type: "multiLineString", value: "line1\n\n\nline2" },
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
// Mixed whitespace
|
|
585
|
+
{
|
|
586
|
+
input: '""" \n\t\n """',
|
|
587
|
+
expected: {
|
|
588
|
+
success: true,
|
|
589
|
+
result: { type: "multiLineString", value: " \n\t\n " },
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
// Failure cases
|
|
593
|
+
{ input: '"""hello', expected: { success: false } },
|
|
594
|
+
{ input: 'hello"""', expected: { success: false } },
|
|
595
|
+
{ input: '""hello"""', expected: { success: false } },
|
|
596
|
+
{ input: '"""hello""', expected: { success: false } },
|
|
597
|
+
{ input: '"hello"', expected: { success: false } },
|
|
598
|
+
{ input: "'hello'", expected: { success: false } },
|
|
599
|
+
{ input: "", expected: { success: false } },
|
|
600
|
+
{ input: "hello", expected: { success: false } },
|
|
601
|
+
];
|
|
602
|
+
testCases.forEach(({ input, expected }) => {
|
|
603
|
+
if (expected.success) {
|
|
604
|
+
it(`should parse ${JSON.stringify(input)} successfully`, () => {
|
|
605
|
+
const result = multiLineStringParser(input);
|
|
606
|
+
expect(result.success).toBe(true);
|
|
607
|
+
if (result.success) {
|
|
608
|
+
expect(result.result).toEqual(expected.result);
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
it(`should fail to parse ${JSON.stringify(input)}`, () => {
|
|
614
|
+
const result = multiLineStringParser(input);
|
|
615
|
+
expect(result.success).toBe(false);
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
});
|
|
447
620
|
describe("variableNameParser", () => {
|
|
448
621
|
const testCases = [
|
|
449
622
|
// Happy path
|
|
@@ -497,13 +670,6 @@ describe("literals parsers", () => {
|
|
|
497
670
|
result: { type: "variableName", value: "var2test" },
|
|
498
671
|
},
|
|
499
672
|
},
|
|
500
|
-
{
|
|
501
|
-
input: "123",
|
|
502
|
-
expected: {
|
|
503
|
-
success: true,
|
|
504
|
-
result: { type: "variableName", value: "123" },
|
|
505
|
-
},
|
|
506
|
-
},
|
|
507
673
|
// Mixed case
|
|
508
674
|
{
|
|
509
675
|
input: "camelCase",
|
|
@@ -528,6 +694,13 @@ describe("literals parsers", () => {
|
|
|
528
694
|
},
|
|
529
695
|
// Failure cases
|
|
530
696
|
{ input: "", expected: { success: false } },
|
|
697
|
+
// cannot start with number
|
|
698
|
+
{
|
|
699
|
+
input: "1a",
|
|
700
|
+
expected: {
|
|
701
|
+
success: false,
|
|
702
|
+
},
|
|
703
|
+
},
|
|
531
704
|
];
|
|
532
705
|
testCases.forEach(({ input, expected }) => {
|
|
533
706
|
if (expected.success) {
|
|
@@ -13,12 +13,12 @@ import { optionalSpaces } from "./utils.js";
|
|
|
13
13
|
import { literalParser } from "./literals.js";
|
|
14
14
|
import { assignmentParser } from "./assignment.js";
|
|
15
15
|
import { functionCallParser } from "./functionCall.js";
|
|
16
|
-
import { accessExpressionParser } from "./access.js";
|
|
16
|
+
import { accessExpressionParser, indexAccessParser } from "./access.js";
|
|
17
17
|
import { optionalSemicolon } from "./parserUtils.js";
|
|
18
18
|
import { agencyArrayParser, agencyObjectParser } from "./dataStructures.js";
|
|
19
19
|
import { commentParser } from "./comment.js";
|
|
20
20
|
import { returnStatementParser } from "./returnStatement.js";
|
|
21
21
|
export const defaultCaseParser = char("_");
|
|
22
|
-
export const matchBlockParserCase = seqC(set("type", "matchBlockCase"), optionalSpaces, capture(or(defaultCaseParser, accessExpressionParser, literalParser), "caseValue"), optionalSpaces, str("=>"), optionalSpaces, capture(or(returnStatementParser, agencyArrayParser, agencyObjectParser, accessExpressionParser, assignmentParser, functionCallParser, literalParser), "body"));
|
|
22
|
+
export const matchBlockParserCase = seqC(set("type", "matchBlockCase"), optionalSpaces, capture(or(defaultCaseParser, indexAccessParser, accessExpressionParser, literalParser), "caseValue"), optionalSpaces, str("=>"), optionalSpaces, capture(or(returnStatementParser, agencyArrayParser, agencyObjectParser, accessExpressionParser, assignmentParser, functionCallParser, literalParser), "body"));
|
|
23
23
|
const semicolon = seqC(optionalSpaces, char(";"), optionalSpaces);
|
|
24
24
|
export const matchBlockParser = seqC(set("type", "matchBlock"), str("match"), optionalSpaces, char("("), capture(literalParser, "expression"), char(")"), optionalSpaces, char("{"), optionalSpaces, capture(sepBy(or(semicolon, newline), or(commentParser, matchBlockParserCase)), "cases"), optionalSpaces, char("}"), optionalSemicolon);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|