1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 (* $Id: acic2astMatcher.ml 9271 2008-11-28 18:28:58Z fguidi $ *)
28 module Ast = CicNotationPt
29 module Util = CicNotationUtil
31 let reference_of_oxuri = ref (fun _ -> assert false);;
32 let set_reference_of_oxuri f = reference_of_oxuri := f;;
40 | NRef of NReference.reference
41 | Appl of cic_mask_t list
43 let uri_of_term t = CicUtil.uri_of_term (Deannotate.deannotate_term t)
45 let mask_of_cic = function
46 | NCic.Appl tl -> Appl (List.map (fun _ -> Blob) tl), tl
47 | NCic.Const nref -> NRef nref, []
51 let mask, tl = mask_of_cic t in
54 let mask_of_appl_pattern = function
55 | Ast.UriPattern uri -> NRef (!reference_of_oxuri uri), []
56 | Ast.NRefPattern nref -> NRef nref, []
58 | Ast.VarPattern _ -> Blob, []
59 | Ast.ApplPattern pl -> Appl (List.map (fun _ -> Blob) pl), pl
61 let tag_of_pattern p =
62 let mask, pl = mask_of_appl_pattern p in
65 type pattern_t = Ast.cic_appl_pattern
66 type term_t = NCic.term
68 let string_of_pattern = CicNotationPp.pp_cic_appl_pattern
69 let string_of_term t =
71 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t
73 let classify = function
75 | Ast.VarPattern _ -> PatternMatcher.Variable
78 | Ast.ApplPattern _ -> PatternMatcher.Constructor
81 module M = PatternMatcher.Matcher (Pattern32)
84 let match_cb rows matched_terms constructors =
92 | Ast.ImplicitPattern -> Util.fresh_name (), t
93 | Ast.VarPattern name -> name, t
96 with Invalid_argument _ -> assert false in
97 let rec check_non_linear_patterns =
103 name <> name' || NCicReduction.alpha_eq [] [] [] t t'
104 ) tl && check_non_linear_patterns tl
106 if check_non_linear_patterns env then
107 Some (env, constructors, pid)
112 M.compiler rows match_cb (fun () -> None)