]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql_test/mQGTopParser.mly
cf2280dadd8f827ddf98a140f44f639c98d5032b
[helm.git] / helm / ocaml / mathql_test / mQGTopParser.mly
1 /* Copyright (C) 2000, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  */
25
26 /*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
27  */
28
29 %{
30    let f (x, y, z) = x
31    let s (x, y, z) = y
32    let t (x, y, z) = z
33
34    let builtin s = 
35       let ns = "http://www.cs.unibo.it/helm/schemas/schema-helm#" in
36       match s with
37          | "MH"   -> ns ^ "MainHypothesis"
38          | "IH"   -> ns ^ "InHypothesis"
39          | "MC"   -> ns ^ "MainConclusion"
40          | "IC"   -> ns ^ "InConclusion"
41          | "IB"   -> ns ^ "InBody"
42          | "SET"  ->      "Set"
43          | "PROP" ->      "Prop"
44          | "TYPE" ->      "Type"
45          | _      -> raise Parsing.Parse_error
46
47    module G = MQueryGenerator
48 %}
49    %token <string> ID
50    %token <UriManager.uri> CONURI
51    %token <UriManager.uri> VARURI
52    %token <UriManager.uri * int> INDTYURI
53    %token <UriManager.uri * int * int> INDCONURI
54    %token ALIAS EOF
55
56    %start interp
57    %type  <CicTextualParser0.interpretation_domain_item -> CicTextualParser0.interpretation_codomain_item option> interp
58    
59    %token <string> STR
60    %token DL DQ LC RC CM 
61    %token MOBJ MSORT MREL OOBJ OSORT OREL UNIV
62    
63    %start qstr specs
64    %type  <string>                    qstr
65    %type  <MQueryGenerator.spec list> specs
66 %%
67    uri:
68       | CONURI    { CicTextualParser0.ConUri $1                           }
69       | VARURI    { CicTextualParser0.VarUri $1                           }
70       | INDTYURI  { CicTextualParser0.IndTyUri ((fst $1), (snd $1))       }
71       | INDCONURI { CicTextualParser0.IndConUri ((f $1), (s $1), (t $1))  }
72    ;
73    alias:      
74       | ALIAS ID uri { ($2, CicTextualParser0.Uri $3) }
75    ;
76    aliases:
77       | alias aliases { $1 :: $2 } 
78       | EOF           { []       }
79    ;
80    interp:
81       | aliases { function CicTextualParser0.Id s -> (try Some (List.assoc s $1) 
82                                     with Not_found -> None)
83                          | _ -> None }
84    ;
85
86    qstr:
87       | DQ       { ""      }
88       | STR qstr { $1 ^ $2 }
89    ;
90    str:
91       | STR   { $1         }
92       | DL ID { builtin $2 }
93    ;
94    strs:
95       | str CM strs { $1 :: $3 }
96       | str         { [$1]     }
97       |             { []       }
98    ;
99    list:
100       | LC strs RC { $2 }
101    ;
102    spec:
103       | MOBJ  list list list { G.MustObj  ($2, $3, $4) }
104       | MSORT list list list { G.MustSort ($2, $3, $4) }
105       | MREL  list list      { G.MustRel  ($2, $3)     }
106       | OOBJ  list list list { G.OnlyObj  ($2, $3, $4) }
107       | OSORT list list list { G.OnlySort ($2, $3, $4) }
108       | OREL  list list      { G.OnlyRel  ($2, $3)     }
109       | UNIV  list           { G.Universe $2           }
110    ;   
111    specs:
112       | spec specs { $1 :: $2 }
113       | EOF        { []       }
114    ;