| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Util |
| 12 |
open Pp |
| 13 |
open Notationextern |
| 14 |
open Notation |
| 15 |
open Constrexpr |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
type ppbox = |
| 20 |
| PpHB |
| 21 |
| PpHOVB of int |
| 22 |
| PpHVB of int |
| 23 |
| PpVB of int |
| 24 |
|
| 25 |
type ppcut = |
| 26 |
| PpBrk of int * int |
| 27 |
| PpFnl |
| 28 |
|
| 29 |
let ppcmd_of_box = function |
| 30 |
| PpHB -> h |
| 31 |
| PpHOVB n -> hov n |
| 32 |
| PpHVB n -> hv n |
| 33 |
| PpVB n -> v n |
| 34 |
|
| 35 |
let ppcmd_of_cut = function |
| 36 |
| PpFnl -> fnl () |
| 37 |
| PpBrk(n1,n2) -> brk(n1,n2) |
| 38 |
|
| 39 |
type pattern_quote_style = QuotedPattern | NotQuotedPattern |
| 40 |
|
| 41 |
type unparsing = |
| 42 |
| UnpMetaVar of notation_entry_relative_level |
| 43 |
| UnpBinderMetaVar of notation_entry_relative_level * pattern_quote_style |
| 44 |
| UnpListMetaVar of notation_entry_relative_level * unparsing list |
| 45 |
| UnpBinderListMetaVar of |
| 46 |
bool * |
| 47 |
bool * |
| 48 |
unparsing list |
| 49 |
| UnpTerminal of string |
| 50 |
| UnpBox of ppbox * unparsing Loc.located list |
| 51 |
| UnpCut of ppcut |
| 52 |
|
| 53 |
type unparsing_rule = unparsing list |
| 54 |
|
| 55 |
let rec unparsing_eq unp1 unp2 = match (unp1,unp2) with |
| 56 |
| UnpMetaVar subentry1, UnpMetaVar subentry2 -> notation_entry_relative_level_eq subentry1 subentry2 |
| 57 |
| UnpBinderMetaVar (subentry1,s1), UnpBinderMetaVar (subentry2,s2) -> notation_entry_relative_level_eq subentry1 subentry2 && s1 = s2 |
| 58 |
| UnpListMetaVar (subentry1,l1), UnpListMetaVar (subentry2,l2) -> notation_entry_relative_level_eq subentry1 subentry2 && List.for_all2eq unparsing_eq l1 l2 |
| 59 |
| UnpBinderListMetaVar (b1,q1,l1), UnpBinderListMetaVar (b2,q2,l2) -> b1 = b2 && q1 = q2 && List.for_all2eq unparsing_eq l1 l2 |
| 60 |
| UnpTerminal s1, UnpTerminal s2 -> String.equal s1 s2 |
| 61 |
| UnpBox (b1,l1), UnpBox (b2,l2) -> b1 = b2 && List.for_all2eq unparsing_eq (List.map snd l1) (List.map snd l2) |
| 62 |
| UnpCut p1, UnpCut p2 -> p1 = p2 |
| 63 |
| (UnpMetaVar _ | UnpBinderMetaVar _ | UnpListMetaVar _ | |
| 64 |
UnpBinderListMetaVar _ | UnpTerminal _ | UnpBox _ | UnpCut _), _ -> false |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
type notation_printing_rules = { |
| 69 |
notation_printing_unparsing : unparsing_rule; |
| 70 |
notation_printing_level : entry_level; |
| 71 |
} |
| 72 |
|
| 73 |
type generic_notation_printing_rules = { |
| 74 |
notation_printing_reserved : bool; |
| 75 |
notation_printing_rules : notation_printing_rules; |
| 76 |
} |
| 77 |
|
| 78 |
let generic_notation_printing_rules = |
| 79 |
Summary.ref ~stage:Synterp ~name:"generic-notation-printing-rules" (NotationMap.empty : generic_notation_printing_rules NotationMap.t) |
| 80 |
|
| 81 |
let specific_notation_printing_rules = |
| 82 |
Summary.ref ~name:"specific-notation-printing-rules" (SpecificNotationMap.empty : notation_printing_rules SpecificNotationMap.t) |
| 83 |
|
| 84 |
let declare_generic_notation_printing_rules ntn rules = |
| 85 |
generic_notation_printing_rules := NotationMap.add ntn rules !generic_notation_printing_rules |
| 86 |
let declare_specific_notation_printing_rules specific_ntn rules = |
| 87 |
specific_notation_printing_rules := SpecificNotationMap.add specific_ntn rules !specific_notation_printing_rules |
| 88 |
|
| 89 |
let has_generic_notation_printing_rule ntn = |
| 90 |
try (NotationMap.find ntn !generic_notation_printing_rules).notation_printing_reserved |
| 91 |
with Not_found -> false |
| 92 |
|
| 93 |
let find_generic_notation_printing_rule ntn = |
| 94 |
NotationMap.find ntn !generic_notation_printing_rules |
| 95 |
|
| 96 |
let find_specific_notation_printing_rule specific_ntn = |
| 97 |
SpecificNotationMap.find specific_ntn !specific_notation_printing_rules |
| 98 |
|
| 99 |
let find_notation_printing_rule which ntn = |
| 100 |
try match which with |
| 101 |
| None -> raise Not_found |
| 102 |
| Some which -> (find_specific_notation_printing_rule (which,ntn)) |
| 103 |
with Not_found -> (find_generic_notation_printing_rule ntn).notation_printing_rules |