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