From 6f3985a9031eaf4334a18df40debca28f5a2141e Mon Sep 17 00:00:00 2001 From: Brian Campbell Date: Tue, 14 Jan 2025 14:39:43 +0000 Subject: [PATCH] Fix foreach parse errors so that they report locations --- src/lib/parse_ast.ml | 2 -- src/lib/parser.mly | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib/parse_ast.ml b/src/lib/parse_ast.ml index 4765437fb..a6047fe0f 100644 --- a/src/lib/parse_ast.ml +++ b/src/lib/parse_ast.ml @@ -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 *) diff --git a/src/lib/parser.mly b/src/lib/parser.mly index cac4c5b3d..efd27738e 100644 --- a/src/lib/parser.mly +++ b/src/lib/parser.mly @@ -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)) @@ -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"