Skip to content

Commit

Permalink
Merge pull request #34 from fink-lang/fix-throw-new-precendence
Browse files Browse the repository at this point in the history
fix(throw,new): fix precedence
  • Loading branch information
kollhof authored Apr 7, 2020
2 parents bc38d47 + 0a1353b commit f7a0124
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/lang/js-compat/index.fnk
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
{add_non_separating} = import '@fink/prattler/symbols'
{expression, curr_loc} = import '@fink/prattler'

{prefix} = import '../generic/prefix'
{symbol} = import '../symbols'


js_op = fn op, type:
{
...symbol(op),

nud: fn lbp: fn ctx:
{start} = curr_loc:: ctx
[right, next_ctx] = expression:: ctx, 0
{end} = right.loc

[{type, op, right, loc: {start, end}}, next_ctx]
}


add_js_ops = fn ctx:
pipe ctx:
add_non_separating(prefix('new', 'new'))
add_non_separating(prefix('throw', 'throw'))
add_non_separating:: js_op:: 'new', 'new'
add_non_separating:: js_op:: 'throw', 'throw'
2 changes: 2 additions & 0 deletions src/lang/js-compat/index.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ describe:: 'js-compat operators', fn:

it:: 'parses new', fn:
parse_expr('new_foo = new Foobar(spam, ni)') eq snapshot
parse_expr('new_foo = new Foobar:: spam, ni') eq snapshot


it:: 'parses throw', fn:
parse_expr(`throw_foo = foo || throw err('foobar')`) eq snapshot
parse_expr(`throw_foo = foo || throw err:: 'foobar'`) eq snapshot

24 changes: 24 additions & 0 deletions src/lang/js-compat/index.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ assign = (1:0-1:30)
`;

exports[`js-compat operators parses new 2`] = `
assign = (1:0-1:29)
ident (1:0-1:7) new_foo
new (1:10-1:29)
call (1:14-1:29)
ident (1:14-1:20) Foobar
ident (1:23-1:27) spam
ident (1:29-1:31) ni
`;

exports[`js-compat operators parses throw 1`] = `
assign = (1:0-1:38)
ident (1:0-1:9) throw_foo
Expand All @@ -23,3 +34,16 @@ assign = (1:0-1:38)
\`foobar\`
`;

exports[`js-compat operators parses throw 2`] = `
assign = (1:0-1:38)
ident (1:0-1:9) throw_foo
logical || (1:12-1:38)
ident (1:12-1:15) foo
throw (1:19-1:38)
call (1:25-1:38)
ident (1:25-1:28) err
string ' (1:31-1:39)
\`foobar\`
`;

0 comments on commit f7a0124

Please sign in to comment.