Skip to content

Commit 60e8800

Browse files
committed
Add {string concatenate} to prelude
1 parent 4d57790 commit 60e8800

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/end-to-end.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
6262
['({ ((a): :(b)) ((b): B) })', either.makeRight({ a: 'B', b: 'B' })],
6363
['{ (a: :(")")), (")": (B)) }', either.makeRight({ a: 'B', ')': 'B' })],
6464
[':match({ a: A })({ tag: a, value: {} })', either.makeRight('A')],
65+
[':{string concatenate}(a)(b)', either.makeRight('ab')],
6566
[
6667
`{
6768
"static data":"blah blah blah"

src/language/compiling/semantics/prelude.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,50 @@ export const prelude: ObjectNode = makeObjectNode({
344344
},
345345
),
346346
}),
347+
348+
string: makeObjectNode({
349+
concatenate: preludeFunction(
350+
['string', 'concatenate'],
351+
{
352+
parameter: types.string,
353+
return: makeFunctionType('', {
354+
parameter: types.string,
355+
return: types.string,
356+
}),
357+
},
358+
string1 =>
359+
either.makeRight(
360+
makeFunctionNode(
361+
{
362+
parameter: types.string,
363+
return: types.string,
364+
},
365+
() =>
366+
either.makeRight(
367+
makeUnelaboratedObjectNode({
368+
0: '@apply',
369+
function: {
370+
0: '@lookup',
371+
query: { 0: 'string', 1: 'concatenate' },
372+
},
373+
argument: string1,
374+
}),
375+
),
376+
option.none,
377+
string2 => {
378+
if (typeof string1 !== 'string' || typeof string2 !== 'string') {
379+
return either.makeLeft({
380+
kind: 'panic',
381+
message: 'concatenate received a non-string argument',
382+
})
383+
} else {
384+
return either.makeRight(string1 + string2)
385+
}
386+
},
387+
),
388+
),
389+
),
390+
}),
347391
})
348392

349393
type BooleanNode = 'true' | 'false'

0 commit comments

Comments
 (0)