Skip to content

Commit

Permalink
Fix foreach parse errors so that they report locations
Browse files Browse the repository at this point in the history
  • Loading branch information
bacam committed Jan 14, 2025
1 parent df5daa5 commit 6f3985a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/lib/parse_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ type 'a annot = l * 'a

type extern = { pure : bool; bindings : (string * string) list }

exception Parse_error_locn of l * string

type x = text (* identifier *)
type ix = text (* infix identifier *)

Expand Down
12 changes: 6 additions & 6 deletions src/lib/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,15 @@ exp:
{ mk_exp (E_try ($2, $5)) $startpos $endpos }
| Foreach Lparen id Id atomic_exp Id atomic_exp By atomic_exp In typ Rparen exp
{ if $4 <> "from" then
raise (Parse_error_locn (loc $startpos $endpos,"Missing \"from\" in foreach loop"));
raise (Reporting.err_syntax_loc (loc $startpos $endpos) ("Missing \"from\" in foreach loop"));
if $6 <> "to" then
raise (Parse_error_locn (loc $startpos $endpos,"Missing \"to\" in foreach loop"));
raise (Reporting.err_syntax_loc (loc $startpos $endpos) ("Missing \"to\" in foreach loop"));
mk_exp (E_for ($3, $5, $7, $9, $11, $13)) $startpos $endpos }
| Foreach Lparen id Id atomic_exp Id atomic_exp By atomic_exp Rparen exp
{ if $4 <> "from" then
raise (Parse_error_locn (loc $startpos $endpos,"Missing \"from\" in foreach loop"));
raise (Reporting.err_syntax_loc (loc $startpos $endpos) ("Missing \"from\" in foreach loop"));
if $6 <> "to" && $6 <> "downto" then
raise (Parse_error_locn (loc $startpos $endpos,"Missing \"to\" or \"downto\" in foreach loop"));
raise (Reporting.err_syntax_loc (loc $startpos $endpos) ("Missing \"to\" or \"downto\" in foreach loop"));
let order =
if $6 = "to"
then ATyp_aux(ATyp_inc,loc $startpos($6) $endpos($6))
Expand All @@ -677,9 +677,9 @@ exp:
mk_exp (E_for ($3, $5, $7, $9, order, $11)) $startpos $endpos }
| Foreach Lparen id Id atomic_exp Id atomic_exp Rparen exp
{ if $4 <> "from" then
raise (Parse_error_locn (loc $startpos $endpos,"Missing \"from\" in foreach loop"));
raise (Reporting.err_syntax_loc (loc $startpos $endpos) ("Missing \"from\" in foreach loop"));
if $6 <> "to" && $6 <> "downto" then
raise (Parse_error_locn (loc $startpos $endpos,"Missing \"to\" or \"downto\" in foreach loop"));
raise (Reporting.err_syntax_loc (loc $startpos $endpos) ("Missing \"to\" or \"downto\" in foreach loop"));
let step = mk_lit_exp (L_num (Big_int.of_int 1)) $startpos $endpos in
let ord =
if $6 = "to"
Expand Down

0 comments on commit 6f3985a

Please sign in to comment.