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