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 map ident = T.Inline (local, T.Var, trim ident, "", None) in
42 String.sub s 1 (String.length s - 2)
45 String.sub s 1 (String.length s - 1)
48 [T.Coercion (false, str); T.Coercion (true, str)]
51 [T.Notation (false, str); T.Notation (true, str)]
55 | "Remark" -> Some `Remark
56 | "Lemma" -> Some `Lemma
57 | "Theorem" -> Some `Theorem
58 | "Definition" -> Some `Definition
59 | "Fixpoint" -> Some `Definition
60 | "Let" -> Some `Definition
63 %token <string> SPC STR IDENT INT EXTRA AC OP CP OC CC OQ CQ DEF FS COE CN SC
64 %token <string> ABBR IN LET TH PROOF QED VAR AX IND SEC END UNX REQ XP IP SET NOT LOAD ID COERC
68 %type <Types.items> items
71 | OQ verbatims CQ { $1 ^ $2 ^ $3 }
79 | spc spcs { $1 ^ $2 }
83 | SPC rspcs { $1 ^ $2 }
103 fs: FS spcs { $1 ^ $2 };
104 ident: xident spcs { $1 ^ $2 };
105 th: TH spcs { $1 ^ $2 };
106 xlet: LET spcs { $1 ^ $2 };
107 proof: PROOF spcs { $1 ^ $2 };
108 qed: QED spcs { $1 ^ $2 };
109 sec: SEC spcs { $1 ^ $2 };
110 xend: END spcs { $1 ^ $2 };
111 unx: UNX spcs { $1 ^ $2 };
112 def: DEF spcs { $1 ^ $2 };
113 op: OP spcs { $1 ^ $2 };
114 abbr: ABBR spcs { $1 ^ $2 };
115 var: VAR spcs { $1 ^ $2 };
116 ax: AX spcs { $1 ^ $2 };
117 req: REQ spcs { $1 ^ $2 };
118 load: LOAD spcs { $1 ^ $2 };
119 xp: XP spcs { $1 ^ $2 };
120 ip: IP spcs { $1 ^ $2 };
121 ind: IND spcs { $1 ^ $2 };
122 set: SET spcs { $1 ^ $2 };
123 notation: NOT spcs { $1 ^ $2 };
124 oc: OC spcs { $1 ^ $2 };
125 coe: COE spcs { $1 ^ $2 };
126 cn: CN spcs { $1 ^ $2 };
127 sc: SC spcs { $1 ^ $2 };
128 str: STR spcs { $1 ^ $2 };
129 id: ID spcs { $1 ^ $2 };
130 coerc: COERC spcs { $1 ^ $2 };
134 | ident idents { $1 :: $2 }
142 | cnot spcs { $1 ^ $2 }
143 | cnot spcs cnots { $1 ^ $2 ^ $3 }
156 | abbr extends0 IN { $1 ^ $2 ^ $3 }
157 | op extends1 CP { $1 ^ $2 ^ $3 }
177 | restrict spcs { $1 ^ $2 }
178 | restrict spcs restricts { $1 ^ $2 ^ $3 }
181 | xre spcs { $1 ^ $2 }
182 | xre spcs restricts { $1 ^ $2 ^ $3 }
189 | extend0 spcs { $1 ^ $2 }
190 | extend0 spcs extends0 { $1 ^ $2 ^ $3 }
198 | extend1 spcs { $1 ^ $2 }
199 | extend1 spcs extends1 { $1 ^ $2 ^ $3 }
221 | unexport_rr { $1, [] }
222 | oc fields CC { $1 ^ fst $2 ^ $3, snd $2 }
225 | unexport_r spcs { fst $1 ^ $2, snd $1 }
226 | unexport_r spcs unexports_r { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 }
229 | ident cn unexports_r
230 { $1 ^ $2 ^ fst $3, snd $3 }
231 | ident coe unexports_r
232 { $1 ^ $2 ^ fst $3, snd $3 @ coercion (trim $1) }
236 | field sc fields { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 }
238 | error { out "ERROR" "fields"; failwith "fields" }
246 | unexport spcs { fst $1 ^ $2, snd $1 }
247 | unexport spcs unexports { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 }
272 | verbatim verbatims { $1 ^ $2 }
276 | restricts FS { [] }
280 | step spcs steps { $1 @ $3 }
285 | qid AC { strip1 $2 :: $1 }
289 | th ident restricts fs proof FS steps qed FS
291 $7 @ [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
293 | th ident restricts fs proof restricts FS
295 [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
297 | th ident restricts fs steps qed FS
299 $5 @ [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
301 | th ident restricts def restricts FS
303 [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
305 | th ident def restricts FS
307 [T.Inline (false, T.Con, trim $2, "", mk_flavour $1)]
309 | xlet ident restricts fs proof FS steps qed FS
311 $7 @ [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
313 | xlet ident restricts fs proof restricts FS
315 [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
317 | xlet ident restricts fs steps qed FS
319 $5 @ [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
321 | xlet ident restricts def restricts FS
323 [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
325 | xlet ident def restricts FS
327 [T.Inline (true, T.Con, trim $2, "", mk_flavour $1)]
330 { out "VAR" (cat $2); mk_vars true $2 }
332 { out "AX" (cat $2); mk_vars false $2 }
333 | ind ident unexports FS
335 T.Inline (false, T.Ind, trim $2, "", None) :: snd $3
338 { out "SEC" $2; [T.Section (true, trim $2, $1 ^ $2)] }
340 { out "END" $2; [T.Section (false, trim $2, $1 ^ $2)] }
342 { out "UNX" (fst $2); [T.Unexport ($1 ^ fst $2 ^ trim $3)] }
344 { out "REQ" $3; [T.Include (trim $3)] }
346 { out "REQ" $3; [T.Include (trim $3)] }
348 { out "REQ" $2; [T.Include (trim $2)] }
350 { out "REQ" $2; [T.Include (strip2 (trim $2))] }
351 | coerc qid spcs cn unexports FS
352 { out "COERCE" (hd $2); coercion (hd $2) }
353 | id coerc qid spcs cn unexports FS
354 { out "COERCE" (hd $3); coercion (hd $3) }
356 { out "ERROR" $2; failwith ("macro_step " ^ $2) }
358 { out "ERROR" $2; failwith ("macro_step " ^ $2) }
361 out "ERROR" vs; failwith ("macro_step " ^ vs) }
364 out "ERROR" vs; failwith ("macro_step " ^ vs) }
367 | OQ verbatims CQ { [T.Comment $2] }
369 | set unexports FS { [T.Unexport ($1 ^ fst $2 ^ trim $3)] }
370 | notation unexports FS { notation ($1 ^ fst $2 ^ trim $3) }
371 | error { out "ERROR" "item"; failwith "item" }
375 | rspcs item items { $2 @ $3 }