@@ -102,6 +102,9 @@ let mkcf ~loc ?attrs ?docs d =
102102 Cf. mk ~loc: (make_loc loc) ?attrs ?docs d
103103
104104let mkrhs rhs loc = mkloc rhs (make_loc loc)
105+ (*
106+ let ghrhs rhs loc = mkloc rhs (ghost_loc loc)
107+ *)
105108
106109let mk_optional lbl loc = Optional (mkrhs lbl loc)
107110let mk_labelled lbl loc = Labelled (mkrhs lbl loc)
@@ -150,6 +153,9 @@ let mkpatvar ~loc name =
150153let ghexp ~loc d = Exp .mk ~loc: (ghost_loc loc ) d
151154let ghpat ~loc d = Pat .mk ~loc: (ghost_loc loc ) d
152155let ghtyp ~loc d = Typ .mk ~loc: (ghost_loc loc ) d
156+ (*
157+ let ghloc ~loc d = { txt = d; loc = ghost_loc loc }
158+ *)
153159let ghstr ~loc d = Str .mk ~loc: (ghost_loc loc ) d
154160let ghsig ~loc d = Sig .mk ~loc: (ghost_loc loc ) d
155161
@@ -182,6 +188,43 @@ let mkuplus ~oploc name arg =
182188 and locations-as-Location.t; it should be clear when we move from
183189 one world to the other *)
184190
191+ (*
192+ let mkexp_cons_desc consloc args =
193+ Pexp_construct(mkrhs (Lident "::") consloc, Some args)
194+ let mkexp_cons ~loc consloc args =
195+ mkexp ~loc (mkexp_cons_desc consloc args)
196+
197+ let mkpat_cons_desc consloc args =
198+ Ppat_construct(mkrhs (Lident "::") consloc, Some ([], args))
199+ let mkpat_cons ~loc consloc args =
200+ mkpat ~loc (mkpat_cons_desc consloc args)
201+
202+ let ghexp_cons_desc consloc args =
203+ Pexp_construct(ghrhs (Lident "::") consloc, Some args)
204+ let ghpat_cons_desc consloc args =
205+ Ppat_construct(ghrhs (Lident "::") consloc, Some ([], args))
206+
207+ let rec mktailexp nilloc = let open Location in function
208+ [] ->
209+ let nil = ghloc ~loc:nilloc (Lident "[]") in
210+ Pexp_construct (nil, None), nilloc
211+ | e1 :: el ->
212+ let exp_el, el_loc = mktailexp nilloc el in
213+ let loc = (e1.pexp_loc.loc_start, snd el_loc) in
214+ let arg = ghexp ~loc (Pexp_tuple [e1; ghexp ~loc:el_loc exp_el]) in
215+ ghexp_cons_desc loc arg, loc
216+
217+ let rec mktailpat nilloc = let open Location in function
218+ [] ->
219+ let nil = ghloc ~loc:nilloc (Lident "[]") in
220+ Ppat_construct (nil, None), nilloc
221+ | p1 :: pl ->
222+ let pat_pl, el_loc = mktailpat nilloc pl in
223+ let loc = (p1.ppat_loc.loc_start, snd el_loc) in
224+ let arg = ghpat ~loc (Ppat_tuple [p1; ghpat ~loc:el_loc pat_pl]) in
225+ ghpat_cons_desc loc arg, loc
226+ *)
227+
185228let mkstrexp e attrs =
186229 { pstr_desc = Pstr_eval (e, attrs); pstr_loc = e.pexp_loc }
187230
@@ -191,6 +234,16 @@ let mkexp_constraint ~loc e (t1, t2) =
191234 | _ , Some t -> mkexp ~loc (Pexp_coerce (e , t1 , t ))
192235 | None , None -> assert false
193236
237+ (*
238+ let mkexp_opt_constraint ~loc e = function
239+ | None -> e
240+ | Some constraint_ -> mkexp_constraint ~loc e constraint_
241+
242+ let mkpat_opt_constraint ~loc p = function
243+ | None -> p
244+ | Some typ -> mkpat ~loc (Ppat_constraint(p, typ))
245+ *)
246+
194247let syntax_error () =
195248 raise Syntaxerr .Escape_error
196249
@@ -201,6 +254,11 @@ let unclosed opening_name opening_loc closing_name closing_loc =
201254let expecting loc nonterm =
202255 raise Syntaxerr. (Error (Expecting (make_loc loc , nonterm )))
203256
257+ (* Continues to parse removed syntax
258+ let removed_string_set loc =
259+ raise(Syntaxerr.Error(Syntaxerr.Removed_string_set(make_loc loc)))
260+ *)
261+
204262(* Using the function [not_expecting] in a semantic action means that this
205263 syntactic form is recognized by the parser but is in fact incorrect. This
206264 idiom is used in a few places to produce ad hoc syntax error messages. *)
@@ -254,9 +312,20 @@ let loc_last (id : Longident.t Location.loc) : string Location.loc =
254312let loc_lident (id : string Location.loc ) : Longident.t Location.loc =
255313 loc_map (fun x -> Lident x ) id
256314
315+ (*
316+ let exp_of_longident lid =
317+ let lid = loc_map (fun id -> Lident (Longident.last id)) lid in
318+ Exp.mk ~loc:lid.loc (Pexp_ident lid)
319+ *)
320+
257321let exp_of_label lbl =
258322 Exp .mk ~loc: lbl.loc (Pexp_ident (loc_lident lbl ))
259323
324+ (*
325+ let pat_of_label lbl =
326+ Pat.mk ~loc:lbl.loc (Ppat_var (loc_last lbl))
327+ *)
328+
260329let mk_newtypes ~loc newtypes exp =
261330 let mkexp = mkexp ~loc in
262331 List .fold_right (fun newtype exp -> mkexp (Pexp_newtype (newtype , exp )))
@@ -299,6 +368,12 @@ let mkpat_attrs ~loc d attrs =
299368
300369let wrap_class_attrs ~loc :_ body attrs =
301370 {body with pcl_attributes = attrs @ body.pcl_attributes}
371+ (*
372+ let wrap_mod_attrs ~loc:_ attrs body =
373+ {body with pmod_attributes = attrs @ body.pmod_attributes}
374+ let wrap_mty_attrs ~loc:_ attrs body =
375+ {body with pmty_attributes = attrs @ body.pmty_attributes}
376+ *)
302377
303378let wrap_str_ext ~loc body ext =
304379 match ext with
@@ -1079,6 +1154,8 @@ parse_any_longident:
10791154
10801155(* Functor arguments appear in module expressions and module types. *)
10811156
1157+ (* Compared to upstream, [functor_args] can be empty and is not in reverse
1158+ order. *)
10821159% inline functor_args:
10831160 llist(functor_arg)
10841161 { $ 1 }
@@ -1292,6 +1369,11 @@ module_binding_body:
12921369 | mkmod(
12931370 COLON mty = module_type EQUAL me = module_expr
12941371 { Pmod_constraint (me, mty) }
1372+ (*
1373+ | arg_and_pos = functor_arg body = module_binding_body
1374+ { let (_, arg) = arg_and_pos in
1375+ Pmod_functor(arg, body) }
1376+ *)
12951377 ) { $ 1 }
12961378;
12971379
@@ -2124,7 +2206,7 @@ expr:
21242206 | expr attribute
21252207 { Exp. attr $ 1 $ 2 }
21262208/* BEGIN AVOID */
2127- (*
2209+ (* Allowed in exprs. Commented-out to reduce diffs with upstream.
21282210 | UNDERSCORE
21292211 { not_expecting $loc($1) "wildcard \"_\"" }
21302212 *)
@@ -3486,6 +3568,7 @@ label_longident:
34863568;
34873569type_longident:
34883570 mk_longident(mod_ext_longident, LIDENT) { $1 }
3571+ (* Allow identifiers like [t/42]. *)
34893572 | LIDENT SLASH TYPE_DISAMBIGUATOR { Lident ($1 ^ " / " ^ $3) }
34903573;
34913574mod_longident:
0 commit comments