aboutsummaryrefslogtreecommitdiff
path: root/parsing/notgram_ops.ml
diff options
context:
space:
mode:
authorHugo Herbelin2020-02-15 18:42:55 +0100
committerHugo Herbelin2020-02-16 21:44:43 +0100
commit6a630e92a2c0972d78e724482c71b1f7f7232369 (patch)
tree61694625fbeb3491bef8cb1f09f2a07548318acf /parsing/notgram_ops.ml
parent96e78e7e25d666f30a7c00e0288762e127690c67 (diff)
Revert "Suite picking numeral notation"
This reverts commit 03c48bb6943312e606b80b7af65b1ccb7122a386.
Diffstat (limited to 'parsing/notgram_ops.ml')
-rw-r--r--parsing/notgram_ops.ml92
1 files changed, 40 insertions, 52 deletions
diff --git a/parsing/notgram_ops.ml b/parsing/notgram_ops.ml
index 5c79ec2eba..5c220abeda 100644
--- a/parsing/notgram_ops.ml
+++ b/parsing/notgram_ops.ml
@@ -13,7 +13,22 @@ open CErrors
open Util
open Notation
open Notation_gram
-open Constrexpr
+
+(* Uninterpreted notation levels *)
+
+let notation_level_map = Summary.ref ~name:"notation_level_map" NotationMap.empty
+
+let declare_notation_level ?(onlyprint=false) ntn level =
+ try
+ let (level,onlyprint) = NotationMap.find ntn !notation_level_map in
+ if not onlyprint then anomaly (str "Notation " ++ pr_notation ntn ++ str " is already assigned a level.")
+ with Not_found ->
+ notation_level_map := NotationMap.add ntn (level,onlyprint) !notation_level_map
+
+let level_of_notation ?(onlyprint=false) ntn =
+ let (level,onlyprint') = NotationMap.find ntn !notation_level_map in
+ if onlyprint' && not onlyprint then raise Not_found;
+ level
(**********************************************************************)
(* Equality *)
@@ -25,61 +40,34 @@ let parenRelation_eq t1 t2 = match t1, t2 with
| Prec l1, Prec l2 -> Int.equal l1 l2
| _ -> false
-let constr_entry_key_compatible v1 v2 = match v1, v2 with
-| (ETGlobal | ETBigint | ETString), (ETGlobal | ETBigint | ETString) -> true
-| (ETIdent | ETBigint | ETString), ETIdent -> true
-| ETIdent, (ETBigint | ETString) -> true
+let production_position_eq pp1 pp2 = match (pp1,pp2) with
+| BorderProd (side1,assoc1), BorderProd (side2,assoc2) -> side1 = side2 && assoc1 = assoc2
+| InternalProd, InternalProd -> true
+| (BorderProd _ | InternalProd), _ -> false
+
+let production_level_eq l1 l2 = match (l1,l2) with
+| NextLevel, NextLevel -> true
+| NumLevel n1, NumLevel n2 -> Int.equal n1 n2
+| DefaultLevel, DefaultLevel -> true
+| (NextLevel | NumLevel _ | DefaultLevel), _ -> false
+
+let constr_entry_key_eq eq v1 v2 = match v1, v2 with
+| ETIdent, ETIdent -> true
+| ETGlobal, ETGlobal -> true
+| ETBigint, ETBigint -> true
+| ETString, ETString -> true
| ETBinder b1, ETBinder b2 -> b1 == b2
-| ETConstr (s1,bko1,_lev1), ETConstr (s2,bko2,_lev2) ->
- notation_entry_eq s1 s2 && Option.equal (=) bko1 bko2
+| ETConstr (s1,bko1,lev1), ETConstr (s2,bko2,lev2) ->
+ notation_entry_eq s1 s2 && eq lev1 lev2 && Option.equal (=) bko1 bko2
| ETPattern (b1,n1), ETPattern (b2,n2) -> b1 = b2 && Option.equal Int.equal n1 n2
| (ETIdent | ETGlobal | ETBigint | ETString | ETBinder _ | ETConstr _ | ETPattern _), _ -> false
-let level_compatible (s1, l1, t1, u1) (s2, l2, t2, u2) =
+let level_eq_gen strict (s1, l1, t1, u1) (s2, l2, t2, u2) =
let tolerability_eq (i1, r1) (i2, r2) = Int.equal i1 i2 && parenRelation_eq r1 r2 in
+ let prod_eq (l1,pp1) (l2,pp2) =
+ not strict ||
+ (production_level_eq l1 l2 && production_position_eq pp1 pp2) in
notation_entry_eq s1 s2 && Int.equal l1 l2 && List.equal tolerability_eq t1 t2
- && List.equal constr_entry_key_compatible u1 u2
+ && List.equal (constr_entry_key_eq prod_eq) u1 u2
-(* Uninterpreted notation levels *)
-
-let pr_arg_level from (lev,typ) =
- let pplev = function
- | (n,L) when Int.equal n from -> str "at next level"
- | (n,E) -> str "at level " ++ int n
- | (n,L) -> str "at level below " ++ int n
- | (n,Prec m) when Int.equal m n -> str "at level " ++ int n
- | (n,_) -> str "Unknown level" in
- Ppvernac.pr_set_entry_type (fun _ -> (*TO CHECK*) mt()) typ ++
- (match typ with
- | ETConstr _ | ETPattern _ -> spc () ++ pplev lev
- | _ -> mt ())
-
-let pr_level ntn (from,fromlevel,args,typs) =
- (match from with InConstrEntry -> mt () | InCustomEntry s -> str "in " ++ str s ++ spc()) ++
- str "at level " ++ int fromlevel ++ spc () ++ str "with arguments" ++ spc() ++
- prlist_with_sep pr_comma (pr_arg_level fromlevel) (List.combine args typs)
-
-let error_incompatible_level ntn oldprec prec =
- user_err
- (str "Notation " ++ pr_notation ntn ++ str " is already defined" ++ spc() ++
- pr_level ntn oldprec ++
- spc() ++ str "while it is now required to be" ++ spc() ++
- pr_level ntn prec ++ str ".")
-
-let notation_level_map = Summary.ref ~name:"notation_level_map" NotationMap.empty
-
-let declare_notation_level ?(onlyprint=false) ntn prec =
- let oldprecs =
- try
- let oldprecs = NotationMap.find ntn !notation_level_map in
- let f (old,onlyprint) = not onlyprint && not (level_compatible prec old) in
- match List.filter f oldprecs with
- | (oldprec,_)::_ -> error_incompatible_level ntn oldprec prec
- | [] -> oldprecs
- with Not_found -> [] in
- notation_level_map := NotationMap.add ntn ((prec,onlyprint)::oldprecs) !notation_level_map
-
-let level_of_notation ?(onlyprint=false) ntn =
- let (level,onlyprint') = NotationMap.find ntn !notation_level_map in
- if onlyprint' && not onlyprint then raise Not_found;
- level
+let level_eq = level_eq_gen false