]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/text/txtParser.mly
d9336b189f142a8d4e6a58546fb076941b0f2dbe
[helm.git] / helm / software / helena / src / text / txtParser.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 G = Options
28    module N = Layer
29    module T = Txt
30    
31    let _ = Parsing.set_trace !G.debug_parser
32 %}
33    %token <int> IX
34    %token <string> ID STR
35    %token OP CP OB CB OA CA FS CN CM EQ STAR HASH PLUS TE WTO STO CT
36    %token GRAPH MAIN DECL AX CONG DEF TH GEN REQ OPEN CLOSE SORTS EOF
37
38    %start entry
39    %type <Txt.command option> entry
40
41    %nonassoc CP CB CA
42    %right WTO STO
43 %%
44    hash:
45       |      {}
46       | HASH {}
47    ;
48    fs:
49       |    {}
50       | FS {}
51    ;
52    main:
53       |      { false }
54       | MAIN { true  }
55    ;
56    comment:
57       |         { "", "" }
58       | STR     { "", $1 }
59       | STR STR { $1, $2 }
60    ;
61    ids:
62       | ID        { [$1]     }
63       | ID CM ids { $1 :: $3 }
64    ;
65    sort:
66       | ID    { None, $1    }
67       | IX ID { Some $1, $2 }
68    ;
69    sorts:
70       | sort          { [$1]     }
71       | sort CM sorts { $1 :: $3 }
72    ;
73    level:
74       |       { N.infinite }
75       | CT IX { N.finite $2}
76    ;
77
78    abst:
79       | ID CN term { $1, true, $3  }
80       | TE term    { "", false, $2 }
81       | ID TE term { $1, false, $3 }
82    ;
83    abbr:
84       | ID EQ term { $1, $3 }
85    ;
86    absts:
87       | abst          { [$1]     }
88       | abst CM absts { $1 :: $3 }
89    ;
90    abbrs:
91       | abbr          { [$1]     }
92       | abbr CM abbrs { $1 :: $3 }
93    ;   
94    binder: 
95       | absts { T.Abst $1 }
96       | abbrs { T.Abbr $1 }
97       | ids   { T.Void $1 }
98    ;      
99    atom:
100       | STAR IX          { T.Sort $2         }
101       | STAR ID          { T.NSrt $2         }
102       | hash IX          { T.LRef ($2, 0)    }
103       | hash IX PLUS IX  { T.LRef ($2, $4)   }
104       | ID               { T.NRef $1         }
105       | HASH ID          { T.NRef $2         }
106       | atom OP term CP  { T.Inst ($1, [$3]) }
107       | atom OP terms CP { T.Inst ($1, $3)   }
108    ;
109    term:
110       | atom                       { $1                             }
111       | OA term CA fs term         { T.Cast ($2, $5)                }
112       | OP term CP fs term         { T.Appl ([$2], $5)              }
113       | OP terms CP fs term        { T.Appl ($2, $5)                }
114       | OB binder CB level fs term { T.Bind ($4, $2, $6)            }
115       | term WTO level term        { T.Impl ($3, false, "", $1, $4) }
116       | ID TE term WTO level term  { T.Impl ($5, false, $1, $3, $6) }
117       | term STO level term        { T.Impl ($3, true, "", $1, $4)  }
118       | ID TE term STO level term  { T.Impl ($5, true, $1, $3, $6)  }
119       | OP term CP                 { $2                             }
120    ;
121    terms:
122       | term CM term  { [$1; $3] }
123       | term CM terms { $1 :: $3 }
124    ;
125    
126    decl:
127       | DECL { T.Decl }
128       | AX   { T.Ax   }
129       | CONG { T.Cong }
130    ;
131    def:   
132       | DEF  { T.Def } 
133       | TH   { T.Th  }
134    ;
135    xentity:
136       | GRAPH ID
137          { T.Graph $2                                     }
138       | main decl level comment ID CN term
139          { T.Entity ($1, $2, $3, $5, $4, $7)              }
140       | main def level comment ID EQ term
141          { T.Entity ($1, $2, $3, $5, $4, $7)              }
142       | main def level comment ID EQ term CN term
143          { T.Entity ($1, $2, $3, $5, $4, T.Cast ($9, $7)) }
144       | GEN term
145          { T.Generate [$2]                                }
146       | GEN terms
147          { T.Generate $2                                  }      
148       | REQ ids
149          { T.Require $2                                   }
150       | OPEN ID                           
151          { T.Section (Some $2)                            }
152       | CLOSE                             
153          { T.Section None                                 }
154       | SORTS sorts
155          { T.Sorts $2                                     }
156    ;
157    start: 
158       | GRAPH {} | decl {} | def {} | GEN {} |
159       | REQ {} | OPEN {} | CLOSE {} | SORTS {} | EOF {}
160    ;
161    entry:
162       | xentity start { Some $1 }
163       | EOF           { None    }
164    ;