Skip to content

Commit 3fcb35a

Browse files
authored
Merge pull request #204 from aspeddro/fix-try-expression
try_expression: allow `expression`
2 parents 14e7605 + 68300b6 commit 3fcb35a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

grammar.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,7 @@ module.exports = grammar({
718718

719719
try_expression: $ => seq(
720720
'try',
721-
choice(
722-
$.block,
723-
$.primary_expression,
724-
),
721+
$.expression,
725722
'catch',
726723
'{',
727724
repeat($.switch_match),

test/corpus/expressions.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,12 @@ try switch foo() {
12731273
| Js.Exn.Error(obj) => "error"
12741274
}
12751275

1276+
try for i in 0 to 10 {
1277+
call()
1278+
} catch {
1279+
| Not_found => false
1280+
}
1281+
12761282
---
12771283

12781284
(source_file
@@ -1320,7 +1326,17 @@ try switch foo() {
13201326
(module_identifier))
13211327
(variant_identifier))
13221328
(formal_parameters (value_identifier)))
1323-
(sequence_expression (expression_statement (string (string_fragment))))))))
1329+
(sequence_expression (expression_statement (string (string_fragment)))))))
1330+
1331+
(expression_statement
1332+
(try_expression
1333+
(for_expression (value_identifier) (number) (number)
1334+
(block
1335+
(expression_statement
1336+
(call_expression (value_identifier) (arguments)))))
1337+
(switch_match
1338+
(variant_pattern (variant_identifier))
1339+
(sequence_expression (expression_statement (false)))))))
13241340

13251341
===========================================
13261342
Mutation expressions

0 commit comments

Comments
 (0)