Skip to content

Commit ad4dc76

Browse files
committed
Simplify @lookup's encoding
Only accept a single atomic key (not a potentially-molecular query).
1 parent d3ece55 commit ad4dc76

File tree

11 files changed

+116
-184
lines changed

11 files changed

+116
-184
lines changed

src/end-to-end.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ testCases(endToEnd, code => code)('end-to-end tests', [
2727
['{a,1:overwritten,c}', either.makeRight({ 0: 'a', 1: 'c' })],
2828
['{overwritten,0:a,c}', either.makeRight({ 0: 'a', 1: 'c' })],
2929
['{@check type:true value:true}', either.makeRight('true')],
30-
['{a:A b:{@lookup {a}}}', either.makeRight({ a: 'A', b: 'A' })],
30+
['{a:A b:{@lookup a}}', either.makeRight({ a: 'A', b: 'A' })],
3131
['{a:A b: :a}', either.makeRight({ a: 'A', b: 'A' })],
32-
['{a:A {@lookup {a}}}', either.makeRight({ a: 'A', 0: 'A' })],
32+
['{a:A {@lookup a}}', either.makeRight({ a: 'A', 0: 'A' })],
3333
['{a:A :a}', either.makeRight({ a: 'A', 0: 'A' })],
3434
['{ a: (a => :a)(A) }', either.makeRight({ a: 'A' })],
3535
['{ a: ( a => :a )( A ) }', either.makeRight({ a: 'A' })],
@@ -50,7 +50,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
5050
either.makeRight({
5151
0: '@function',
5252
parameter: 'a',
53-
body: { 0: '@lookup', query: { 0: 'a' } },
53+
body: { 0: '@lookup', key: 'a' },
5454
}),
5555
],
5656
['{ success }.0', either.makeRight('success')],
@@ -126,7 +126,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
126126
0:@runtime
127127
function:{
128128
0:@apply
129-
function:{0:@index object:{0:@lookup query:{0:object}} query:{0:lookup}}
129+
function:{0:@index object:{0:@lookup key:object} query:{0:lookup}}
130130
argument:"key which does not exist in runtime context"
131131
}
132132
}

src/language/compiling/compiler.test.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,44 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
1616
'compiler',
1717
[
1818
['Hello, world!', success('Hello, world!')],
19-
[['@check', true, ['@lookup', ['identity']]], success('true')],
19+
[['@check', true, ['@lookup', 'identity']], success('true')],
2020
[
2121
{
22-
true1: ['@check', true, ['@lookup', ['identity']]],
23-
true2: ['@apply', ['@index', ['@lookup', ['boolean']], ['not']], false],
22+
true1: ['@check', true, ['@lookup', 'identity']],
23+
true2: ['@apply', ['@index', ['@lookup', 'boolean'], ['not']], false],
2424
true3: [
2525
'@apply',
2626
[
2727
'@apply',
28-
['@lookup', ['flow']],
28+
['@lookup', 'flow'],
2929
[
30-
['@index', ['@lookup', ['boolean']], ['not']],
31-
['@index', ['@lookup', ['boolean']], ['not']],
30+
['@index', ['@lookup', 'boolean'], ['not']],
31+
['@index', ['@lookup', 'boolean'], ['not']],
3232
],
3333
],
3434
true,
3535
],
36-
false1: ['@check', false, ['@index', ['@lookup', ['boolean']], ['is']]],
36+
false1: ['@check', false, ['@index', ['@lookup', 'boolean'], ['is']]],
3737
false2: [
3838
'@apply',
39-
['@index', ['@lookup', ['boolean']], ['is']],
39+
['@index', ['@lookup', 'boolean'], ['is']],
4040
'not a boolean',
4141
],
4242
false3: [
4343
'@apply',
4444
[
4545
'@apply',
46-
['@lookup', ['flow']],
46+
['@lookup', 'flow'],
4747
[
4848
[
4949
'@apply',
50-
['@lookup', ['flow']],
50+
['@lookup', 'flow'],
5151
[
52-
['@index', ['@lookup', ['boolean']], ['not']],
53-
['@index', ['@lookup', ['boolean']], ['not']],
52+
['@index', ['@lookup', 'boolean'], ['not']],
53+
['@index', ['@lookup', 'boolean'], ['not']],
5454
],
5555
],
56-
['@index', ['@lookup', ['boolean']], ['not']],
56+
['@index', ['@lookup', 'boolean'], ['not']],
5757
],
5858
],
5959
true,
@@ -69,29 +69,29 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
6969
}),
7070
],
7171
[
72-
['@runtime', ['@lookup', ['identity']]],
72+
['@runtime', ['@lookup', 'identity']],
7373
success({
7474
0: '@runtime',
75-
function: { 0: '@lookup', query: { 0: 'identity' } },
75+
function: { 0: '@lookup', key: 'identity' },
7676
}),
7777
],
7878
[
7979
[
8080
'@runtime',
81-
['@apply', ['@lookup', ['identity']], ['@lookup', ['identity']]],
81+
['@apply', ['@lookup', 'identity'], ['@lookup', 'identity']],
8282
],
8383
success({
8484
0: '@runtime',
85-
function: { 0: '@lookup', query: { 0: 'identity' } },
85+
function: { 0: '@lookup', key: 'identity' },
8686
}),
8787
],
8888
[
89-
['@check', 'not a boolean', ['@index', ['@lookup', ['boolean']], ['is']]],
89+
['@check', 'not a boolean', ['@index', ['@lookup', 'boolean'], ['is']]],
9090
output => assert(either.isLeft(output)),
9191
],
92-
[['@lookup', ['compose']], output => assert(either.isLeft(output))],
92+
[['@lookup', 'compose'], output => assert(either.isLeft(output))],
9393
[
94-
['@runtime', ['@index', ['@lookup', ['boolean']], ['not']]],
94+
['@runtime', ['@index', ['@lookup', 'boolean'], ['not']]],
9595
output => {
9696
assert(either.isLeft(output))
9797
assert(output.value.kind === 'typeMismatch')
@@ -102,8 +102,8 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
102102
'@runtime',
103103
[
104104
'@apply',
105-
['@lookup', ['identity']],
106-
['@index', ['@lookup', ['boolean']], ['not']],
105+
['@lookup', 'identity'],
106+
['@index', ['@lookup', 'boolean'], ['not']],
107107
],
108108
],
109109
output => {
@@ -116,21 +116,21 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
116116
'@runtime',
117117
[
118118
'@apply',
119-
['@lookup', ['flow']],
119+
['@lookup', 'flow'],
120120
[
121-
['@lookup', ['identity']],
122-
['@lookup', ['identity']],
121+
['@lookup', 'identity'],
122+
['@lookup', 'identity'],
123123
],
124124
],
125125
],
126126
success({
127127
0: '@runtime',
128128
function: {
129129
0: '@apply',
130-
function: { 0: '@lookup', query: { 0: 'flow' } },
130+
function: { 0: '@lookup', key: 'flow' },
131131
argument: {
132-
0: { 0: '@lookup', query: { 0: 'identity' } },
133-
1: { 0: '@lookup', query: { 0: 'identity' } },
132+
0: { 0: '@lookup', key: 'identity' },
133+
1: { 0: '@lookup', key: 'identity' },
134134
},
135135
},
136136
}),
@@ -140,10 +140,10 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
140140
'@runtime',
141141
[
142142
'@apply',
143-
['@lookup', ['flow']],
143+
['@lookup', 'flow'],
144144
[
145-
['@index', ['@lookup', ['boolean']], ['not']],
146-
['@index', ['@lookup', ['boolean']], ['not']],
145+
['@index', ['@lookup', 'boolean'], ['not']],
146+
['@index', ['@lookup', 'boolean'], ['not']],
147147
],
148148
],
149149
],
@@ -159,7 +159,7 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
159159
0: '@apply',
160160
function: {
161161
0: '@index',
162-
object: { 0: '@lookup', query: { 0: 'object' } },
162+
object: { 0: '@lookup', key: 'object' },
163163
query: { 0: 'lookup' },
164164
},
165165
argument: 'key which does not exist in runtime context',
@@ -171,7 +171,7 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
171171
0: '@apply',
172172
function: {
173173
0: '@index',
174-
object: { 0: '@lookup', query: { 0: 'object' } },
174+
object: { 0: '@lookup', key: 'object' },
175175
query: { 0: 'lookup' },
176176
},
177177
argument: 'key which does not exist in runtime context',

src/language/compiling/semantics.test.ts

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@ elaborationSuite('@lookup', [
205205
[
206206
{
207207
foo: 'bar',
208-
bar: { 0: '@lookup', 1: { 0: 'foo' } },
208+
bar: { 0: '@lookup', 1: 'foo' },
209209
},
210210
success({ foo: 'bar', bar: 'bar' }),
211211
],
212212
[
213213
{
214214
foo: 'bar',
215-
bar: { 0: '@lookup', query: { 0: 'foo' } },
215+
bar: { 0: '@lookup', key: 'foo' },
216216
},
217217
success({ foo: 'bar', bar: 'bar' }),
218218
],
@@ -228,7 +228,7 @@ elaborationSuite('@lookup', [
228228
a: 'A',
229229
b: {
230230
a: 'different A',
231-
b: { 0: '@lookup', query: { 0: 'a' } },
231+
b: { 0: '@lookup', key: 'a' },
232232
},
233233
},
234234
success({
@@ -242,21 +242,17 @@ elaborationSuite('@lookup', [
242242
[
243243
{
244244
foo: 'bar',
245-
bar: { 0: '@lookup', 1: { 0: 'foo' } },
246-
baz: { 0: '@lookup', 1: { 0: 'bar' } },
245+
bar: { 0: '@lookup', 1: 'foo' },
246+
baz: { 0: '@lookup', 1: 'bar' },
247247
},
248248
success({ foo: 'bar', bar: 'bar', baz: 'bar' }),
249249
],
250250
[
251-
{ a: { 0: '@lookup', _: 'missing query' } },
252-
output => assert(either.isLeft(output)),
253-
],
254-
[
255-
{ a: { 0: '@lookup', query: 'not a valid selector' } },
251+
{ a: { 0: '@lookup', _: 'missing key' } },
256252
output => assert(either.isLeft(output)),
257253
],
258254
[
259-
{ a: { 0: '@lookup', query: { 0: 'thisPropertyDoesNotExist' } } },
255+
{ a: { 0: '@lookup', key: 'thisPropertyDoesNotExist' } },
260256
output => assert(either.isLeft(output)),
261257
],
262258

@@ -265,7 +261,7 @@ elaborationSuite('@lookup', [
265261
{
266262
a: 'C',
267263
b: {
268-
c: { 0: '@lookup', query: { 0: 'a' } },
264+
c: { 0: '@lookup', key: 'a' },
269265
},
270266
},
271267
success({
@@ -280,7 +276,7 @@ elaborationSuite('@lookup', [
280276
a: 'C',
281277
b: {
282278
a: 'other C', // this `a` should be referenced
283-
c: { 0: '@lookup', query: { 0: 'a' } },
279+
c: { 0: '@lookup', key: 'a' },
284280
},
285281
},
286282
success({
@@ -294,22 +290,19 @@ elaborationSuite('@lookup', [
294290
])
295291

296292
elaborationSuite('@apply', [
297-
[
298-
{ 0: '@apply', 1: { 0: '@lookup', query: { 0: 'identity' } }, 2: 'a' },
299-
success('a'),
300-
],
293+
[{ 0: '@apply', 1: { 0: '@lookup', key: 'identity' }, 2: 'a' }, success('a')],
301294
[
302295
{
303296
0: '@apply',
304-
function: { 0: '@lookup', query: { 0: 'identity' } },
297+
function: { 0: '@lookup', key: 'identity' },
305298
argument: 'a',
306299
},
307300
success('a'),
308301
],
309302
[
310303
{
311304
0: '@apply',
312-
function: { 0: '@lookup', query: { 0: 'identity' } },
305+
function: { 0: '@lookup', key: 'identity' },
313306
argument: { foo: 'bar' },
314307
},
315308
success({ foo: 'bar' }),
@@ -338,8 +331,8 @@ elaborationSuite('@apply', [
338331
0: '@function',
339332
parameter: 'b',
340333
body: {
341-
A: { 0: '@lookup', query: 'a' },
342-
B: { 0: '@lookup', query: 'b' },
334+
A: { 0: '@lookup', key: 'a' },
335+
B: { 0: '@lookup', key: 'b' },
343336
},
344337
},
345338
argument: 'b',
@@ -359,7 +352,7 @@ elaborationSuite('@apply', [
359352
0: '@apply',
360353
function: {
361354
0: '@index',
362-
1: { 0: '@lookup', 1: { 0: 'boolean' } },
355+
1: { 0: '@lookup', 1: 'boolean' },
363356
2: { 0: 'not' },
364357
},
365358
argument: { 0: '@lookup', 1: 'x' },
@@ -377,7 +370,7 @@ elaborationSuite('@apply', [
377370
1: 'x',
378371
2: {
379372
0: '@index',
380-
1: { 0: '@lookup', 1: { 0: 'x' } },
373+
1: { 0: '@lookup', 1: 'x' },
381374
2: { 0: 'a' },
382375
},
383376
},
@@ -409,7 +402,7 @@ elaborationSuite('@apply', [
409402
parameter: 'a',
410403
body: {
411404
0: '@lookup',
412-
query: 'a',
405+
key: 'a',
413406
},
414407
},
415408
argument: 'it works',
@@ -449,9 +442,9 @@ elaborationSuite('@apply', [
449442
function: {
450443
0: '@function',
451444
parameter: 'a',
452-
body: { 0: '@lookup', query: 'a' },
445+
body: { 0: '@lookup', key: 'a' },
453446
},
454-
argument: { 0: '@lookup', query: 'a' },
447+
argument: { 0: '@lookup', key: 'a' },
455448
},
456449
},
457450
},
@@ -486,13 +479,13 @@ elaborationSuite('@apply', [
486479
function: {
487480
0: '@function',
488481
parameter: 'a',
489-
body: { 0: '@lookup', query: 'a' },
482+
body: { 0: '@lookup', key: 'a' },
490483
},
491-
argument: { 0: '@lookup', query: 'a' },
484+
argument: { 0: '@lookup', key: 'a' },
492485
},
493486
},
494487
},
495-
argument: { 0: '@lookup', query: 'a' },
488+
argument: { 0: '@lookup', key: 'a' },
496489
},
497490
},
498491
success({
@@ -524,7 +517,7 @@ elaborationSuite('@apply', [
524517
function: {
525518
0: '@function',
526519
parameter: 'b',
527-
body: { 0: '@lookup', query: 'a' },
520+
body: { 0: '@lookup', key: 'a' },
528521
},
529522
argument: 'unused',
530523
},
@@ -563,7 +556,7 @@ elaborationSuite('@apply', [
563556
function: {
564557
0: '@function',
565558
parameter: 'b',
566-
body: { 0: '@lookup', query: 'a' },
559+
body: { 0: '@lookup', key: 'a' },
567560
},
568561
argument: 'unused',
569562
},
@@ -601,7 +594,7 @@ elaborationSuite('@function', [
601594
either.makeRight({
602595
0: '@function',
603596
parameter: 'x',
604-
body: { 0: '@lookup', query: { 0: 'x' } },
597+
body: { 0: '@lookup', key: 'x' },
605598
}),
606599
)
607600
},
@@ -610,7 +603,7 @@ elaborationSuite('@function', [
610603

611604
elaborationSuite('@runtime', [
612605
[
613-
{ 0: '@runtime', 1: { 0: '@lookup', query: { 0: 'identity' } } },
606+
{ 0: '@runtime', 1: { 0: '@lookup', key: 'identity' } },
614607
either.makeRight(
615608
withPhantomData<never>()(
616609
makeObjectNode({ 0: '@runtime', function: prelude['identity']! }),

0 commit comments

Comments
 (0)