Skip to content

Commit bf35727

Browse files
committed
feat(call): allow a multiline call to omit commas for separating args
1 parent 8fb6c07 commit bf35727

File tree

4 files changed

+82
-43
lines changed

4 files changed

+82
-43
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lang/call/call.fnk

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
{
2-
curr_loc, expression, next_is_end, advance, curr_value,
3-
next_loc, next_is
2+
curr_loc, expression, next_is_end, advance, curr_value, next_loc, next_is
43
} = import '@fink/prattler'
54

65
{symbol} = import '../symbols'
76
{seq} = import '../generic/sequence'
87
{get_block} = import '../block'
9-
{next_is_unindented} = import '../indentation'
8+
{curr_next_adjecent} = import '../indentation'
109

1110

1211
call = fn op:
13-
{
14-
...symbol(op),
12+
led = fn: fn ctx, callee:
13+
{start} = callee.loc
14+
[args, next_ctx] = seq(ctx, ')')
15+
{end} = curr_loc(next_ctx)
1516

16-
led: fn: fn ctx, callee:
17-
{start} = callee.loc
18-
[args, next_ctx] = seq(ctx, ')')
19-
{end} = curr_loc(next_ctx)
17+
[{type: 'call', callee, args, loc: {start, end}}, next_ctx]
2018

21-
[{type: 'call', callee, args, loc: {start, end}}, next_ctx]
22-
}
19+
{...symbol(op), led}
2320

2421

2522
params = fn ctx:
@@ -34,21 +31,26 @@ params = fn ctx:
3431

3532

3633
call_no_parens = fn op:
37-
{
38-
...symbol(op),
39-
40-
led: fn: fn ctx, callee:
41-
{start} = callee.loc
42-
[args, next_ctx] = params(ctx)
43-
44-
[
45-
{
46-
type: 'call',
47-
callee,
48-
args: [...args],
49-
loc: {start, end: curr_loc(next_ctx).start}
50-
},
51-
next_ctx
52-
]
53-
}
34+
led = fn: fn ctx, callee:
35+
{start} = callee.loc
36+
37+
[args, next_ctx] = match true:
38+
curr_loc(ctx).end.line == next_loc(ctx).start.line:
39+
params(ctx)
40+
else:
41+
[{exprs}, next_ctx] = get_block(ctx)
42+
# TODO: remove backward compatibility
43+
[...args] = pipe exprs:
44+
filter expr: expr.value != ','
45+
46+
[args, next_ctx]
47+
48+
{start: end} = curr_loc(next_ctx)
49+
50+
node = {type: 'call', callee, args, loc: {start, end}}
51+
52+
[node, next_ctx]
53+
54+
{...symbol(op), led}
55+
5456

src/lang/call/call.test.fnk

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ describe:: 'call() - parsing failures', fn:
2727
1| foobar(
2828
^
2929

30-
Expected ')' but found Symbol(end).
31-
`
30+
Expected ')' but found Symbol(end).`
3231

3332

3433
it:: `throws when missing ')'`, fn:
@@ -39,16 +38,33 @@ describe:: 'call() - parsing failures', fn:
3938
1| foobar(1:)
4039
^
4140

42-
Expected ')' but found ':'.
43-
`
41+
Expected ')' but found ':'.`
4442

4543

4644
describe:: 'call:: ...', fn:
4745

48-
it:: 'parses args: foobar:: spam, ni', fn:
46+
it:: 'parses single line', fn:
4947
parse_expr(`foobar:: spam, ni`) eq snapshot
5048

5149

50+
it:: 'parses multiline', fn:
51+
parse_expr(`
52+
foo::
53+
fn bar:
54+
spam
55+
ni
56+
shrub
57+
`) eq snapshot
58+
59+
it:: 'parses multiline with comma (TODO)', fn:
60+
parse_expr(`
61+
foo::
62+
bar,
63+
ni,
64+
shrub
65+
`) eq snapshot
66+
67+
5268
describe:: 'pipe foo: ...', fn:
5369

5470
it:: 'pipes', fn:

src/lang/call/call.test.fnk.snap

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,28 @@ call (1:0-1:9)
2121
2222
`;
2323

24-
exports[`call:: ... parses args: foobar:: spam, ni 1`] = `
24+
exports[`call:: ... parses multiline 1`] = `
25+
call (1:0-5:2)
26+
ident (1:0-1:3) foo
27+
block fn (2:2-3:8)
28+
ident (2:5-2:8) bar
29+
:
30+
ident (3:4-3:8) spam
31+
ident (4:2-4:4) ni
32+
ident (5:2-5:7) shrub
33+
34+
`;
35+
36+
exports[`call:: ... parses multiline with comma (TODO) 1`] = `
37+
call (1:0-4:2)
38+
ident (1:0-1:3) foo
39+
ident (2:2-2:5) bar
40+
ident (3:2-3:4) ni
41+
ident (4:2-4:7) shrub
42+
43+
`;
44+
45+
exports[`call:: ... parses single line 1`] = `
2546
call (1:0-1:15)
2647
ident (1:0-1:6) foobar
2748
ident (1:9-1:13) spam

0 commit comments

Comments
 (0)