1 /* Copyright (C) 2000, 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://cs.unibo.it/helm/.
29 let out t s = () (* prerr_endline ("-- " ^ t ^ " " ^ s) *)
31 let trim = HExtlib.trim_blanks
35 let cat x = String.concat " " x
37 let mk_vars local idents =
38 let kind = if local then T.Var else T.Con in
39 let map ident = T.Inline (local, kind, trim ident, "", None) in
43 String.sub s 1 (String.length s - 2)
46 String.sub s 1 (String.length s - 1)
49 [T.Coercion (false, str); T.Coercion (true, str)]
52 [T.Notation (false, str); T.Notation (true, str)]
56 | "Remark" -> Some `Remark
57 | "Lemma" -> Some `Lemma
58 | "Theorem" -> Some `Theorem
59 | "Definition" -> Some `Definition
60 | "Fixpoint" -> Some `Definition
61 | "Let" -> Some `Definition
64 %token <string> SPC STR IDENT INT EXTRA AC OP CP OC CC OQ CQ DEF FS COE CN SC
65 %token <string> ABBR IN LET TH PROOF QED VAR AX IND SEC END UNX REQ XP IP SET NOT LOAD ID COERC
69 %type <Types.items> items
72 | OQ verbatims CQ { $1 ^ $2 ^ $3 }
80 | spc spcs { $1 ^ $2 }
84 | SPC rspcs { $1 ^ $2 }
104 fs: FS spcs { $1 ^ $2 };
105 ident: xident spcs { $1 ^ $2 };
106 th: TH spcs { $1 ^ $2 };
107 xlet: LET spcs { $1 ^ $2 };
108 proof: PROOF spcs { $1 ^ $2 };
109 qed: QED spcs { $1 ^ $2 };
110 sec: SEC spcs { $1 ^ $2 };
111 xend: END spcs { $1 ^ $2 };
112 unx: UNX spcs { $1 ^ $2 };
113 def: DEF spcs { $1 ^ $2 };
114 op: OP spcs { $1 ^ $2 };
115 abbr: ABBR spcs { $1 ^ $2 };
116 var: VAR spcs { $1 ^ $2 };
117 ax: AX spcs { $1 ^ $2 };
118 req: REQ spcs { $1 ^ $2 };
119 load: LOAD spcs { $1 ^ $2 };
120 xp: XP spcs { $1 ^ $2 };
121 ip: IP spcs { $1 ^ $2 };
122 ind: IND spcs { $1 ^ $2 };
123 set: SET spcs { $1 ^ $2 };
124 notation: NOT spcs { $1 ^ $2 };
125 oc: OC spcs { $1 ^ $2 };
126 coe: COE spcs { $1 ^ $2 };
127 cn: CN spcs { $1 ^ $2 };
128 sc: SC spcs { $1 ^ $2 };
129 str: STR spcs { $1 ^ $2 };
130 id: ID spcs { $1 ^ $2 };
131 coerc: COERC spcs { $1 ^ $2 };
135 | ident idents { $1 :: $2 }
143 | cnot spcs { $1 ^ $2 }
144 | cnot spcs cnots { $1 ^ $2 ^ $3 }
157 | abbr extends0 IN { $1 ^ $2 ^ $3 }
158 | op extends1 CP { $1 ^ $2 ^ $3 }
178 | restrict spcs { $1 ^ $2 }
179 | restrict spcs restricts { $1 ^ $2 ^ $3 }
182 | xre spcs { $1 ^ $2 }
183 | xre spcs restricts { $1 ^ $2 ^ $3 }
190 | extend0 spcs { $1 ^ $2 }
191 | extend0 spcs extends0 { $1 ^ $2 ^ $3 }
199 | extend1 spcs { $1 ^ $2 }
200 | extend1 spcs extends1 { $1 ^ $2 ^ $3 }
222 | unexport_rr { $1, [] }
223 | oc fields CC { $1 ^ fst $2 ^ $3, snd $2 }
226 | unexport_r spcs { fst $1 ^ $2, snd $1 }
227 | unexport_r spcs unexports_r { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 }
230 | ident cn unexports_r
231 { $1 ^ $2 ^ fst $3, snd $3 }
232 | ident coe unexports_r
233 { $1 ^ $2 ^ fst $3, snd $3 @ coercion (trim $1) }
237 | field sc fields { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 }
239 | error { out "ERROR" "fields"; failwith "fields" }
247 | unexport spcs { fst $1 ^ $2, snd $1 }
248 | unexport spcs unexports { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 }
273 | verbatim verbatims { $1 ^ $2 }
277 | restricts FS { [] }
281 | step spcs steps { $1 @ $3 }
286 | qid AC { strip1 $2 :: $1 }
290 | th ident restricts fs proof FS steps qed FS
292 $7 @ [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
294 | th ident restricts fs proof restricts FS
296 [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
298 | th ident restricts fs steps qed FS
300 $5 @ [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
302 | th ident restricts def restricts FS
304 [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
306 | th ident def restricts FS
308 [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
310 | xlet ident restricts fs proof FS steps qed FS
312 $7 @ [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
314 | xlet ident restricts fs proof restricts FS
316 [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
318 | xlet ident restricts fs steps qed FS
320 $5 @ [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
322 | xlet ident restricts def restricts FS
324 [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
326 | xlet ident def restricts FS
328 [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
331 { out "VAR" (cat $2); mk_vars true $2 }
333 { out "AX" (cat $2); mk_vars false $2 }
334 | ind ident unexports FS
336 T.Inline (false, T.Ind, trim $2, "", None) :: snd $3
339 { out "SEC" $2; [T.Section (true, trim $2, $1 ^ $2)] }
341 { out "END" $2; [T.Section (false, trim $2, $1 ^ $2)] }
343 { out "UNX" (fst $2); [T.Unexport ($1 ^ fst $2 ^ trim $3)] }
345 { out "REQ" $3; [T.Include (trim $3)] }
347 { out "REQ" $3; [T.Include (trim $3)] }
349 { out "REQ" $2; [T.Include (trim $2)] }
351 { out "REQ" $2; [T.Include (strip2 (trim $2))] }
352 | coerc qid spcs cn unexports FS
353 { out "COERCE" (hd $2); coercion (hd $2) }
354 | id coerc qid spcs cn unexports FS
355 { out "COERCE" (hd $3); coercion (hd $3) }
357 { out "ERROR" $2; failwith ("macro_step " ^ $2) }
359 { out "ERROR" $2; failwith ("macro_step " ^ $2) }
362 out "ERROR" vs; failwith ("macro_step " ^ vs) }
365 out "ERROR" vs; failwith ("macro_step " ^ vs) }
368 | OQ verbatims CQ { [T.Comment $2] }
370 | set unexports FS { [T.Unexport ($1 ^ fst $2 ^ trim $3)] }
371 | notation unexports FS { notation ($1 ^ fst $2 ^ trim $3) }
372 | error { out "ERROR" "item"; failwith "item" }
376 | rspcs item items { $2 @ $3 }