diff --git a/lib/syntax/parser.mly b/lib/syntax/parser.mly index 5f85338..af7e08f 100644 --- a/lib/syntax/parser.mly +++ b/lib/syntax/parser.mly @@ -235,7 +235,7 @@ expr: { make_node (ELet (x, e1, e2)) $startpos $endpos } | LET REC binds=separated_nonempty_list(AND, function_bind) IN body=expr %prec over_TOP { make_node (ELetrec (binds, body)) $startpos $endpos } - | IF e0=expr THEN e1=expr ELSE e2=expr + | IF e0=expr THEN e1=expr ELSE e2=expr %prec over_TOP { make_node (EIf (e0, e1, e2)) $startpos $endpos } | tu=tuple_expr { tu } diff --git a/tests/regular/parse_test.ml b/tests/regular/parse_test.ml index eb7677c..fbe5d32 100644 --- a/tests/regular/parse_test.ml +++ b/tests/regular/parse_test.ml @@ -1319,6 +1319,38 @@ let result = print_int (sum 4) (start_loc ((pos_fname "") (pos_lnum 3) (pos_bol 46) (pos_cnum 78))) (end_loc ((pos_fname "") (pos_lnum 3) (pos_bol 46) (pos_cnum 79))) (attrs ())))) + |}]; + + print_parsed_program {| +let x = if true then 2 else 1 + +let x = 1 + |}; + [%expect + {| + ((TopLet x + ((desc + (EIf + ((desc (EConst (CBool true))) + (start_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 12))) + (end_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 16))) + (attrs ())) + ((desc (EConst (CInt 2))) + (start_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 22))) + (end_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 23))) + (attrs ())) + ((desc (EConst (CInt 1))) + (start_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 29))) + (end_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 30))) + (attrs ())))) + (start_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 9))) + (end_loc ((pos_fname "") (pos_lnum 2) (pos_bol 1) (pos_cnum 30))) + (attrs ()))) + (TopLet x + ((desc (EConst (CInt 1))) + (start_loc ((pos_fname "") (pos_lnum 4) (pos_bol 33) (pos_cnum 41))) + (end_loc ((pos_fname "") (pos_lnum 4) (pos_bol 33) (pos_cnum 42))) + (attrs ())))) |}] let%expect_test "Test: path parsing" =