Skip to content

Commit f90cd7e

Browse files
authored
Merge pull request #879 from SkySkimmer/stream-comlex-fail
Adapt to rocq-prover/rocq#20964 (less exn driven parser)
2 parents 68fe617 + 8172ab6 commit f90cd7e

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

src/rocq_elpi_arg_syntax.mlg

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ let rec strip_square loc s =
3535
else Rocq_elpi_utils.of_coq_loc loc, s
3636

3737
[%%if coq = "8.20" || coq = "9.0" || coq = "9.1"]
38-
let streamFail = Gramlib.Stream.Failure
38+
let streamOk x = x
39+
let streamFail () = raise Gramlib.Stream.Failure
3940
[%%else]
40-
let streamFail = Procq.StreamFail
41+
let streamOk x = Ok x
42+
let streamFail () = Error ()
4143
[%%endif]
4244
}
4345

@@ -78,8 +80,9 @@ let any_qname kwstate strm =
7880
else
7981
the_qname := sym
8082
| _ -> the_qname := sym
81-
end
82-
| _ -> raise streamFail
83+
end;
84+
streamOk ()
85+
| _ -> streamFail ()
8386
let any_qname = Pcoq.Entry.(of_parser "any_qname" { parser_fun = any_qname })
8487

8588
}
@@ -205,8 +208,8 @@ let opt2list = function None -> [] | Some l -> l
205208

206209
let any_kwd kwstate strm =
207210
match LStream.peek kwstate strm with
208-
| Some (Tok.KEYWORD sym) when sym <> "." -> LStream.junk kwstate strm; sym
209-
| _ -> raise streamFail
211+
| Some (Tok.KEYWORD sym) when sym <> "." -> LStream.junk kwstate strm; streamOk sym
212+
| _ -> streamFail ()
210213
let any_kwd = Pcoq.Entry.(of_parser "any_symbols_or_kwd" { parser_fun = any_kwd })
211214

212215
let pr_attributes _ _ _ atts =

src/rocq_elpi_utils.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ let patch_loc_source execution_loc error_loc msg =
7878
(* external file *)
7979
Pp.(hv 0 (Loc.pr elpiloc ++ spc () ++ msg)), execution_loc
8080

81+
[%%if coq = "8.20" || coq = "9.0" || coq = "9.1"]
82+
exception ParseError = Gramlib.Grammar.Error
83+
[%%else]
84+
exception ParseError = Gramlib.Grammar.ParseError
85+
[%%endif]
86+
8187
let handle_elpi_compiler_errors ~loc ?error_header f =
8288
let w_header m =
8389
match error_header with
@@ -95,7 +101,7 @@ let handle_elpi_compiler_errors ~loc ?error_header f =
95101
let _,info = Exninfo.capture e in
96102
let msg, loc = patch_loc_source loc (Some (to_coq_loc oloc)) (Pp.str msg) in
97103
CErrors.user_err ~info ~loc (w_header msg)
98-
| Gramlib.Grammar.Error _ as e ->
104+
| ParseError _ as e ->
99105
let _,info = Exninfo.capture e in
100106
let cloc = Loc.get_loc info in
101107
let msg = CErrors.print_no_report e in

src/rocq_elpi_vernacular.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ let main_interp_qedc = ET.Constants.declare_global_symbol "main-interp-qed"
2626
let main_synterpc = ET.Constants.declare_global_symbol "main-synterp"
2727
let attributesc = ET.Constants.declare_global_symbol "attributes"
2828

29+
[%%if coq = "8.20" || coq = "9.0" || coq = "9.1"]
30+
exception ParseError = Gramlib.Grammar.Error
31+
[%%else]
32+
exception ParseError = Gramlib.Grammar.ParseError
33+
[%%endif]
34+
2935
let atts2impl ~depth loc phase
3036
state atts q =
3137
let open Rocq_elpi_builtins_synterp in
@@ -52,7 +58,7 @@ let atts2impl ~depth loc phase
5258
match Pcoq.parse_string (Pvernac.main_entry None) (Printf.sprintf "#[%s] Qed." txt) |> Option.map (fun x -> x.CAst.v) with
5359
| None -> atts
5460
| Some { Vernacexpr.attrs ; _ } -> List.map (fun {CAst.v=(name,v)} -> convert_att_r ("elpi."^name,v)) attrs @ atts
55-
| exception Gramlib.Grammar.Error msg ->
61+
| exception ParseError msg ->
5662
CErrors.user_err Pp.(str"Environment variable COQ_ELPI_ATTRIBUTES contains ill formed value:" ++ spc () ++ str txt ++ cut () ++ str msg) in
5763
let state, atts, _ = EU.map_acc (Rocq_elpi_builtins_synterp.attribute.API.Conversion.embed ~depth) state atts in
5864
let atts = ET.mkApp attributesc (EU.list_to_lp_list atts) [] in

src/rocq_elpi_vernacular_syntax.mlg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ let lookahead_lib_colon kwstate strm =
9191
match Gramlib.LStream.peek_nth kwstate 0 strm with
9292
| Some (Tok.IDENT "lib") ->
9393
(match Gramlib.LStream.peek_nth kwstate 1 strm with
94-
| Some (Tok.KEYWORD ":") -> ()
95-
| _ -> raise streamFail)
96-
| _ -> raise streamFail
94+
| Some (Tok.KEYWORD ":") -> streamOk ()
95+
| _ -> streamFail ())
96+
| _ -> streamFail ()
9797
[%%endif]
9898

9999
[%%if coq = "8.20"]

0 commit comments

Comments
 (0)