Skip to content

Commit aebee21

Browse files
authored
Merge pull request #59 from mkantor/prepare-for-infix-notation
Prepare for infix notation
2 parents cda2dc1 + 51d52f6 commit aebee21

File tree

8 files changed

+88
-205
lines changed

8 files changed

+88
-205
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ data representation implied by the fact that a value is an atom (e.g. the atom
5151
`2` may be an integer in memory).
5252

5353
Bare words not containing any
54-
[reserved character sequences](./src/language/parsing/atom.ts#L33-L57) are
54+
[reserved character sequences](./src/language/parsing/atom.ts#L33-L55) are
5555
atoms:
5656

5757
```
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{@runtime, context =>
2-
:flow({
3-
:context.arguments.lookup
2+
:flow(
43
:match({
54
none: {}
6-
some: :flow({
7-
:context.environment.lookup
5+
some: :flow(
86
:match({
97
none: {}
108
some: :identity
119
})
12-
})
10+
)(
11+
:context.environment.lookup
12+
)
1313
})
14-
})(variable)
14+
)(
15+
:context.arguments.lookup
16+
)(variable)
1517
}

src/end-to-end.test.ts

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
133133
],
134134
[':match({ a: A })({ tag: a, value: {} })', either.makeRight('A')],
135135
[':atom.prepend(a)(b)', either.makeRight('ab')],
136-
[':flow({ :atom.append(a), :atom.append(b) })(z)', either.makeRight('zab')],
136+
[':flow(:atom.append(b))(:atom.append(a))(z)', either.makeRight('zab')],
137137
[
138138
`{
139139
// foo: bar
@@ -159,42 +159,21 @@ testCases(endToEnd, code => code)('end-to-end tests', [
159159
either.makeRight({ tag: 'none', value: {} }),
160160
],
161161
[
162-
`{@runtime, {@apply, :flow, {
163-
{@apply, :object.lookup, environment}
164-
{@apply, :match, {
165-
none: "environment does not exist"
166-
some: {@apply, :flow, {
167-
{@apply, :object.lookup, lookup}
168-
{@apply, :match, {
169-
none: "environment.lookup does not exist"
170-
some: {@apply, :apply, PATH}
171-
}}
172-
}}
173-
}}
174-
}}}`,
175-
output => {
176-
if (either.isLeft(output)) {
177-
assert.fail(output.value.message)
178-
}
179-
assert(typeof output.value === 'object')
180-
assert.deepEqual(output.value['tag'], 'some')
181-
assert.deepEqual(typeof output.value['value'], 'string')
182-
},
183-
],
184-
[
185-
`{@runtime, :flow({
186-
:object.lookup(environment)
187-
:match({
188-
none: "environment does not exist"
189-
some: :flow({
190-
:object.lookup(lookup)
191-
:match({
192-
none: "environment.lookup does not exist"
193-
some: :apply(PATH)
194-
})
162+
`{@runtime, :flow(
163+
:match({
164+
none: "environment does not exist"
165+
some: :flow(
166+
:match({
167+
none: "environment.lookup does not exist"
168+
some: :apply(PATH)
169+
})
170+
)(
171+
:object.lookup(lookup)
172+
)
195173
})
196-
})
197-
})}`,
174+
)(
175+
:object.lookup(environment)
176+
)}`,
198177
output => {
199178
if (either.isLeft(output)) {
200179
assert.fail(output.value.message)

src/language/compiling/compiler.test.ts

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,18 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
2121
{
2222
true1: ['@check', true, ['@lookup', 'identity']],
2323
true2: ['@apply', ['@index', ['@lookup', 'boolean'], ['not']], false],
24-
true3: [
25-
'@apply',
26-
[
27-
'@apply',
28-
['@lookup', 'flow'],
29-
[
30-
['@index', ['@lookup', 'boolean'], ['not']],
31-
['@index', ['@lookup', 'boolean'], ['not']],
32-
],
33-
],
34-
true,
35-
],
3624
false1: ['@check', false, ['@index', ['@lookup', 'boolean'], ['is']]],
3725
false2: [
3826
'@apply',
3927
['@index', ['@lookup', 'boolean'], ['is']],
4028
'not a boolean',
4129
],
42-
false3: [
43-
'@apply',
44-
[
45-
'@apply',
46-
['@lookup', 'flow'],
47-
[
48-
[
49-
'@apply',
50-
['@lookup', 'flow'],
51-
[
52-
['@index', ['@lookup', 'boolean'], ['not']],
53-
['@index', ['@lookup', 'boolean'], ['not']],
54-
],
55-
],
56-
['@index', ['@lookup', 'boolean'], ['not']],
57-
],
58-
],
59-
true,
60-
],
6130
},
6231
success({
6332
true1: 'true',
6433
true2: 'true',
65-
true3: 'true',
6634
false1: 'false',
6735
false2: 'false',
68-
false3: 'false',
6936
}),
7037
],
7138
[
@@ -116,37 +83,25 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
11683
'@runtime',
11784
[
11885
'@apply',
119-
['@lookup', 'flow'],
120-
[
121-
['@lookup', 'identity'],
122-
['@lookup', 'identity'],
123-
],
86+
['@apply', ['@lookup', 'flow'], ['@lookup', 'identity']],
87+
['@lookup', 'identity'],
12488
],
12589
],
12690
success({
12791
0: '@runtime',
12892
function: {
12993
0: '@apply',
130-
function: { 0: '@lookup', key: 'flow' },
131-
argument: {
132-
0: { 0: '@lookup', key: 'identity' },
133-
1: { 0: '@lookup', key: 'identity' },
94+
function: {
95+
0: '@apply',
96+
function: { 0: '@lookup', key: 'flow' },
97+
argument: { 0: '@lookup', key: 'identity' },
13498
},
99+
argument: { 0: '@lookup', key: 'identity' },
135100
},
136101
}),
137102
],
138103
[
139-
[
140-
'@runtime',
141-
[
142-
'@apply',
143-
['@lookup', 'flow'],
144-
[
145-
['@index', ['@lookup', 'boolean'], ['not']],
146-
['@index', ['@lookup', 'boolean'], ['not']],
147-
],
148-
],
149-
],
104+
['@runtime', ['@index', ['@lookup', 'boolean'], ['not']]],
150105
output => {
151106
assert(either.isLeft(output))
152107
assert(output.value.kind === 'typeMismatch')

src/language/parsing/atom.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ const atomComponentsRequiringQuotation = [
4444
singleLineCommentDelimiter,
4545
whitespace,
4646

47+
// Reserved to allow symbols like `=>` to not be conflated with atoms:
48+
literal('='),
49+
4750
// Reserved for future use:
4851
literal('['),
4952
literal(']'),
50-
literal('<'),
51-
literal('>'),
5253
literal('#'),
53-
literal('&'),
54-
literal('|'),
55-
literal('='),
5654
literal(';'),
5755
] as const
5856

src/language/runtime/evaluator.test.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,6 @@ testCases(evaluate, input => `evaluating \`${JSON.stringify(input)}\``)(
1717
[
1818
['Hello, world!', success('Hello, world!')],
1919
[['@check', true, ['@lookup', 'identity']], success('true')],
20-
[
21-
[
22-
'@runtime',
23-
[
24-
'@apply',
25-
['@lookup', 'flow'],
26-
[
27-
[
28-
'@apply',
29-
['@index', ['@lookup', 'object'], ['lookup']],
30-
'environment',
31-
],
32-
[
33-
'@apply',
34-
['@lookup', 'match'],
35-
{
36-
none: 'environment does not exist!',
37-
some: [
38-
'@apply',
39-
['@lookup', 'flow'],
40-
[
41-
[
42-
'@apply',
43-
['@index', ['@lookup', 'object'], ['lookup']],
44-
'lookup',
45-
],
46-
[
47-
'@apply',
48-
['@lookup', 'match'],
49-
{
50-
none: 'environment.lookup does not exist!',
51-
some: ['@apply', ['@lookup', 'apply'], 'PATH'],
52-
},
53-
],
54-
],
55-
],
56-
},
57-
],
58-
],
59-
],
60-
],
61-
output => {
62-
if (either.isLeft(output)) {
63-
assert.fail(output.value.message)
64-
}
65-
assert(typeof output.value === 'object')
66-
assert(output.value['tag'] === 'some')
67-
assert(typeof output.value['value'] === 'string')
68-
},
69-
],
7020
[
7121
['@check', 'not a boolean', ['@index', ['@lookup', 'boolean'], 'is']],
7222
output => assert(either.isLeft(output)),

src/language/semantics/prelude.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ export const prelude = makeObjectNode({
1313
integer: makeObjectNode(integer),
1414
atom: makeObjectNode(atom),
1515
object: makeObjectNode(object),
16+
17+
// Aliases:
18+
'>>': globalFunctions.flow,
19+
'|>': globalFunctions.identity,
20+
'+': integer.add,
21+
'-': integer.subtract,
22+
'<': integer.less_than,
23+
'>': integer.greater_than,
1624
})

0 commit comments

Comments
 (0)