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