Skip to content

Commit

Permalink
Merge pull request #32 from fink-lang/call-params-block
Browse files Browse the repository at this point in the history
call params block
  • Loading branch information
kollhof authored Apr 1, 2020
2 parents af56778 + bf35727 commit ee649e6
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 169 deletions.
256 changes: 128 additions & 128 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"@fink/prattler": "^2.0.0"
},
"devDependencies": {
"@fink/cli": "^2.2.0",
"@fink/cli": "^2.3.0",
"@fink/jest": "^1.1.0",
"@fink/larix": "^4.6.1",
"@fink/loxia": "^4.5.2",
"@fink/loxia": "^4.6.3",
"commitizen": "^4.0.3",
"cz-conventional-changelog": "^3.1.0",
"jest-cli": "^25.2.3",
"jest-cli": "^25.2.4",
"npx-run": "^2.1.2",
"semantic-release": "^17.0.4"
},
Expand Down
58 changes: 30 additions & 28 deletions src/lang/call/call.fnk
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{
curr_loc, expression, next_is_end, advance, curr_value,
next_loc, next_is
curr_loc, expression, next_is_end, advance, curr_value, next_loc, next_is
} = import '@fink/prattler'

{symbol} = import '../symbols'
{seq} = import '../generic/sequence'
{get_block} = import '../block'
{next_is_unindented} = import '../indentation'
{curr_next_adjecent} = import '../indentation'


call = fn op:
{
...symbol(op),
led = fn: fn ctx, callee:
{start} = callee.loc
[args, next_ctx] = seq(ctx, ')')
{end} = curr_loc(next_ctx)

led: fn: fn ctx, callee:
{start} = callee.loc
[args, next_ctx] = seq(ctx, ')')
{end} = curr_loc(next_ctx)
[{type: 'call', callee, args, loc: {start, end}}, next_ctx]

[{type: 'call', callee, args, loc: {start, end}}, next_ctx]
}
{...symbol(op), led}


params = fn ctx:
Expand All @@ -34,21 +31,26 @@ params = fn ctx:


call_no_parens = fn op:
{
...symbol(op),

led: fn: fn ctx, callee:
{start} = callee.loc
[args, next_ctx] = params(ctx)

[
{
type: 'call',
callee,
args: [...args],
loc: {start, end: curr_loc(next_ctx).start}
},
next_ctx
]
}
led = fn: fn ctx, callee:
{start} = callee.loc

[args, next_ctx] = match true:
curr_loc(ctx).end.line == next_loc(ctx).start.line:
params(ctx)
else:
[{exprs}, next_ctx] = get_block(ctx)
# TODO: remove backward compatibility
[...args] = pipe exprs:
filter expr: expr.value != ','

[args, next_ctx]

{start: end} = curr_loc(next_ctx)

node = {type: 'call', callee, args, loc: {start, end}}

[node, next_ctx]

{...symbol(op), led}


26 changes: 21 additions & 5 deletions src/lang/call/call.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe:: 'call() - parsing failures', fn:
1| foobar(
^

Expected ')' but found Symbol(end).
`
Expected ')' but found Symbol(end).`


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

Expected ')' but found ':'.
`
Expected ')' but found ':'.`


describe:: 'call:: ...', fn:

it:: 'parses args: foobar:: spam, ni', fn:
it:: 'parses single line', fn:
parse_expr(`foobar:: spam, ni`) eq snapshot


it:: 'parses multiline', fn:
parse_expr(`
foo::
fn bar:
spam
ni
shrub
`) eq snapshot

it:: 'parses multiline with comma (TODO)', fn:
parse_expr(`
foo::
bar,
ni,
shrub
`) eq snapshot


describe:: 'pipe foo: ...', fn:

it:: 'pipes', fn:
Expand Down
23 changes: 22 additions & 1 deletion src/lang/call/call.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,28 @@ call (1:0-1:9)
`;

exports[`call:: ... parses args: foobar:: spam, ni 1`] = `
exports[`call:: ... parses multiline 1`] = `
call (1:0-5:2)
ident (1:0-1:3) foo
block fn (2:2-3:8)
ident (2:5-2:8) bar
:
ident (3:4-3:8) spam
ident (4:2-4:4) ni
ident (5:2-5:7) shrub
`;

exports[`call:: ... parses multiline with comma (TODO) 1`] = `
call (1:0-4:2)
ident (1:0-1:3) foo
ident (2:2-2:5) bar
ident (3:2-3:4) ni
ident (4:2-4:7) shrub
`;

exports[`call:: ... parses single line 1`] = `
call (1:0-1:15)
ident (1:0-1:6) foobar
ident (1:9-1:13) spam
Expand Down
3 changes: 1 addition & 2 deletions src/lang/identifier/other.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ number = fn ctx:
float_ctx = advance(advance(ctx))
float_value = `${int_value}.${curr_value(float_ctx)}`

[foo, bar] = match true:
match true:
float_value.endsWith('e'):
e_ctx = advance(float_ctx)
e_value = `${float_value}${curr_value(e_ctx)}`
Expand All @@ -49,7 +49,6 @@ number = fn ctx:
else:
[float_value, float_ctx]

[foo, bar]
else:
[int_value, ctx]

Expand Down
4 changes: 2 additions & 2 deletions src/testing/serialize.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ str_type_op = fn {type, op, comment=null, loc: {start, end}}, indent:
prefixed = lines.map(fn line: `${indent}# ${line}`)
'${prefixed.join('\n')}\n${head}'


serialize_block = fn node, serialize, indent:
head = str_type_op(node, indent)

Expand Down Expand Up @@ -103,7 +104,7 @@ serialize_other = fn node, serialize, indent:
serialize_jsx = fn node, serialize, indent:
head = str_type_op(node, indent)

result = match true:
match true:
(node.type == 'jsx-elem'):
props = node.props.map(fn expr: serialize(expr, `${indent} `))
children = node.children.map(fn expr: serialize(expr, `${indent} `))
Expand Down Expand Up @@ -132,7 +133,6 @@ serialize_jsx = fn node, serialize, indent:
expr = serialize(node.expr, `${indent} `)
`${indent}${head}\n${expr}`

result

serialize = fn node, indent='':
match true:
Expand Down

0 comments on commit ee649e6

Please sign in to comment.