]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/binaries/transcript/v8Parser.mly
transcript updated
[helm.git] / helm / software / components / binaries / transcript / v8Parser.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 %{
27    module T = Types
28    
29    let out t s = () (* prerr_endline ("-- " ^ t ^ " " ^ s) *)
30
31    let trim = HExtlib.trim_blanks
32
33    let hd = List.hd
34
35    let cat x = String.concat " " x
36
37    let mk_vars idents =
38       let map ident = T.Inline (T.Var, trim ident) in
39       List.map map idents
40
41    let strip2 s =
42       String.sub s 1 (String.length s - 2)
43
44    let strip1 s = 
45       String.sub s 1 (String.length s - 1)
46 %}
47    %token <string> SPC STR IDENT INT EXTRA AC OP CP OC CC OQ CQ DEF FS COE CN SC
48    %token <string> LET IN TH PROOF QED VAR IND SEC REQ XP IP SET NOT LOAD ID COERC
49    %token EOF
50    
51    %start items
52    %type <Types.items> items
53 %%
54    comment:
55       | OQ verbatims CQ { $1 ^ $2 ^ $3 }
56    ;
57    spc:
58       | SPC     { $1 }
59       | comment { $1 }
60    ;
61    spcs:
62      |          { ""      }
63      | spc spcs { $1 ^ $2 }
64    ;
65    rspcs:
66      |           { ""      }
67      | SPC rspcs { $1 ^ $2 }
68    ;
69    fs: FS spcs { $1 ^ $2 };
70    ident: IDENT spcs { $1 ^ $2 };
71    th: TH spcs { $1 ^ $2 };
72    proof: PROOF spcs { $1 ^ $2 };
73    qed: QED spcs { $1 ^ $2 };
74    sec: SEC spcs { $1 ^ $2 };
75    def: DEF spcs { $1 ^ $2 };
76    op: OP spcs { $1 ^ $2 };
77    xlet: LET spcs { $1 ^ $2 };
78    var: VAR spcs { $1 ^ $2 };
79    req: REQ spcs { $1 ^ $2 };
80    load: LOAD spcs { $1 ^ $2 };
81    xp: XP spcs { $1 ^ $2 };
82    ip: IP spcs { $1 ^ $2 };
83    ind: IND spcs { $1 ^ $2 };
84    set: SET spcs { $1 ^ $2 };
85    notation: NOT spcs { $1 ^ $2 };
86    oc: OC spcs { $1 ^ $2 };
87    coe: COE spcs { $1 ^ $2 };
88    cn: CN spcs { $1 ^ $2 };
89    sc: SC spcs { $1 ^ $2 };
90    str: STR spcs { $1 ^ $2 };
91    id: ID spcs { $1 ^ $2 };
92    coerc: COERC spcs { $1 ^ $2 };
93
94
95    idents:
96       | ident        { [$1]     }
97       | ident idents { $1 :: $2 }
98    ;
99    
100    cnot:
101       | EXTRA { $1 }
102       | INT   { $1 }
103    ;
104    cnots:
105       | cnot spcs       { $1 ^ $2      }
106       | cnot spcs cnots { $1 ^ $2 ^ $3 }
107    ;
108    
109    xstrict:
110       | AC               { $1           }
111       | INT              { $1           }
112       | EXTRA            { $1           }
113       | CN               { $1           }
114       | SC               { $1           }
115       | OC               { $1           }
116       | CC               { $1           }
117       | COE              { $1           }
118       | STR              { $1           }   
119       | xlet extends0 IN { $1 ^ $2 ^ $3 }
120       | op extends1 CP   { $1 ^ $2 ^ $3 }
121       
122    ;
123    strict:
124       | xstrict { $1 }
125       | IDENT   { $1 } 
126       | SET     { $1 }
127       | NOT     { $1 }
128    ;
129    restrict: 
130       | strict  { $1 }
131       | IN      { $1 }
132       | CP      { $1 }
133    ;
134    xre:
135       | xstrict { $1 }
136       | IN      { $1 }
137       | CP      { $1 }   
138    ;
139    restricts:
140       | restrict spcs           { $1 ^ $2      }
141       | restrict spcs restricts { $1 ^ $2 ^ $3 }
142    ;
143    xres:
144       | xre spcs           { $1 ^ $2      }
145       | xre spcs restricts { $1 ^ $2 ^ $3 }   
146    ;
147    extend0:
148       | strict { $1 }
149       | DEF    { $1 }
150    ;
151    extends0:
152       | extend0 spcs          { $1 ^ $2      }
153       | extend0 spcs extends0 { $1 ^ $2 ^ $3 }
154    ;
155    extend1:
156       | strict { $1 }
157       | DEF    { $1 }
158       | IN     { $1 }
159    ;
160    extends1:
161       | extend1 spcs          { $1 ^ $2      }
162       | extend1 spcs extends1 { $1 ^ $2 ^ $3 }
163    ;
164    unexport_rr:
165       | AC    { $1 }
166       | INT   { $1 }
167       | IDENT { $1 }
168       | EXTRA { $1 }
169       | CN    { $1 }
170       | COE   { $1 }
171       | STR   { $1 }   
172       | OP    { $1 }
173       | LET   { $1 }
174       | IN    { $1 }
175       | CP    { $1 }
176       | DEF   { $1 }
177       | SET   { $1 }
178       | NOT   { $1 }
179       | LOAD  { $1 }
180       | ID    { $1 } 
181       | COERC { $1 } 
182    ;
183    unexport_r:
184       | unexport_rr  { $1, []                   }
185       | oc fields CC { $1 ^ fst $2 ^ $3, snd $2 }
186    ;
187    unexports_r:
188       | unexport_r spcs             { fst $1 ^ $2, snd $1                   }
189       | unexport_r spcs unexports_r { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 } 
190    ;
191    field: 
192       | ident cn unexports_r  { $1 ^ $2 ^ fst $3, snd $3                   }
193       | ident coe unexports_r { $1 ^ $2 ^ fst $3, snd $3 @ [T.Coercion $1] }
194    ;  
195    fields:
196       | field           { $1                                      }
197       | field sc fields { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3   } 
198       | cnots           { $1, []                                  }
199       | error           { out "ERROR" "fields"; failwith "fields" }
200    ;
201    unexport:
202       | unexport_r { $1     }
203       | SC         { $1, [] }
204       | CC         { $1, [] }
205    ;   
206    unexports:
207       | unexport spcs           { fst $1 ^ $2, snd $1                   }
208       | unexport spcs unexports { fst $1 ^ $2 ^ fst $3, snd $1 @ snd $3 }
209    ;
210    verbatim:
211       | unexport_rr { $1 }
212       | OC          { $1 }
213       | CC          { $1 }
214       | SC          { $1 }
215       | TH          { $1 }       
216       | VAR         { $1 }
217       | IND         { $1 }
218       | SEC         { $1 }
219       | REQ         { $1 } 
220       | XP          { $1 } 
221       | IP          { $1 } 
222       | QED         { $1 }
223       | PROOF       { $1 }
224       | FS          { $1 }
225       | SPC         { $1 } 
226    ;
227    verbatims:
228       |                    { ""      }
229       | verbatim verbatims { $1 ^ $2 }
230    ;   
231    step:
232       | macro_step   { $1 }
233       | restricts FS { [] }
234    ;
235    steps:
236       | step spcs       { []      }
237       | step spcs steps { $1 @ $3 }
238    ;
239    
240    qid:
241       | IDENT  { [$1]            }
242       | qid AC { strip1 $2 :: $1 }
243    ;
244    
245    macro_step:
246       | th ident restricts fs proof FS steps qed FS 
247          { out "TH" $2; $7 @ [T.Inline (T.Con, trim $2)]            }
248       | th ident restricts fs proof restricts FS
249          { out "TH" $2; [T.Inline (T.Con, trim $2)]                 }
250       | th ident restricts fs steps qed FS 
251          { out "TH" $2; $5 @ [T.Inline (T.Con, trim $2)]            }
252       | th ident restricts def restricts FS
253          { out "TH" $2; [T.Inline (T.Con, trim $2)]                 }
254       | th ident def restricts FS
255          { out "TH" $2; [T.Inline (T.Con, trim $2)]                 }
256       | var idents xres FS
257          { out "VAR" (cat $2); mk_vars $2                           }      
258       | ind ident unexports FS
259          { out "IND" $2; snd $3 @ [T.Inline (T.Ind, trim $2)]       }
260       | sec unexports FS 
261          { out "UNX" (fst $2); [T.Unexport ($1 ^ fst $2 ^ trim $3)] }
262       | req xp ident FS
263          { out "REQ" $3; [T.Include (trim $3)]                      }
264       | req ip ident FS
265          { out "REQ" $3; [T.Include (trim $3)]                      }
266       | req ident FS
267          { out "REQ" $2; [T.Include (trim $2)]                      } 
268       | load str FS
269          { out "REQ" $2; [T.Include (strip2 (trim $2))]             }
270       | coerc qid spcs cn unexports FS
271          { out "COERCE" (hd $2); [T.Coercion (hd $2)]               }
272       | id coerc qid spcs cn unexports FS
273          { out "COERCE" (hd $3); [T.Coercion (hd $3)]               }
274       | th ident error 
275          { out "ERROR" $2; failwith ("macro_step " ^ $2)            }
276       | ind ident error 
277          { out "ERROR" $2; failwith ("macro_step " ^ $2)            }
278       | var idents error 
279          { let vs = cat $2 in
280            out "ERROR" vs; failwith ("macro_step " ^ vs)            }
281    ;
282    item:
283       | OQ verbatims CQ       { [T.Comment $2]                       }
284       | macro_step            { $1                                   }
285       | set unexports FS      { [T.Unexport ($1 ^ fst $2 ^ trim $3)] }
286       | notation unexports FS { [T.Notation ($1 ^ fst $2 ^ trim $3)] }
287       | error                 { out "ERROR" "item"; failwith "item"  }
288     ;
289     items:
290       | rspcs EOF        { []      }
291       | rspcs item items { $2 @ $3 }
292     ;