]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/text/txtParser.mly
- we added a parser for lambda-delta textual syntax (file extension .hln)
[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 OPEN CLOSE GLOBAL EOF
37
38    %start entry
39    %type <Txt.entity 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
58    abst:
59       | ID CN term { $1, $3 }
60    ;
61    abbr:
62       | ID EQ term { $1, $3 }
63    ;
64    absts:
65       | abst          { [$1]     }
66       | abst CM absts { $1 :: $3 }
67    ;
68    abbrs:
69       | abbr          { [$1]     }
70       | abbr CM abbrs { $1 :: $3 }
71    ;   
72    binder: 
73       | absts { T.Abst $1 }
74       | abbrs { T.Abbr $1 }
75       | ids   { T.Void $1 }
76    ;      
77    atom:
78       | STAR IX         { T.Sort $2       }
79       | STAR ID         { T.NSrt $2       }
80       | hash IX         { T.LRef ($2, 0)  }
81       | hash IX PLUS IX { T.LRef ($2, $4) }
82       | hash ID         { T.NRef $2       }
83    ;
84    term:
85       | atom                 { $1                       }
86       | OA term CA fs term   { T.Cast ($2, $5)          }
87       | OP terms CP fs term  { T.Appl ($2, $5)          }
88       | atom OP terms CP     { T.Appl (List.rev $3, $1) }
89       | OB binder CB fs term { T.Bind ($2, $5)          }
90    ;
91    terms:
92       | term          { [$1]     }
93       | term CM terms { $1 :: $3 }
94    ;
95    
96    start: OPEN {} | CLOSE {} | GLOBAL {} | EOF {} ;
97    xentity:
98       | OPEN ID                           { Some (T.Section (Some $2))                      }
99       | CLOSE                             { Some (T.Section None)                           }
100       | GLOBAL comment ID CN term         { Some (T.Global (false, $3, $2, $5))             }
101       | GLOBAL comment ID EQ term         { Some (T.Global (true, $3, $2, $5))              }
102       | GLOBAL comment ID EQ term CN term { Some (T.Global (true, $3, $2, T.Cast ($7, $5))) }
103       | EOF                               { None                                            }
104    ;
105   entry:
106       | xentity       { $1, false }
107       | xentity start { $1, true  }
108    ;