]> matita.cs.unibo.it Git - helm.git/blob - helm/metadata/create4/METADATA/meta_lex.l
MathQL homepage added
[helm.git] / helm / metadata / create4 / METADATA / meta_lex.l
1  /******************************************************************/
2  /*  Copyright (C) 2000, HELM Team                                 */ 
3  /*                                                                */
4  /* This file is part of HELM, an Hypertextual, Electronic         */
5  /* Library of Mathematics, developed at the Computer Science      */
6  /* Department, University of Bologna, Italy.                      */
7  /*                                                                */
8  /* HELM is free software; you can redistribute it and/or          */
9  /* modify it under the terms of the GNU General Public License    */
10  /* as published by the Free Software Foundation; either version   */
11  /* 2 of the License, or (at your option) any later version.       */
12  /*                                                                */
13  /* HELM is distributed in the hope that it will be useful,        */
14  /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15  /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the   */
16  /* GNU General Public License for more details.                   */
17  /*                                                                */
18  /* You should have received a copy of the GNU General Public      */
19  /* License along with HELM; if not, write to the Free Software    */
20  /* Foundation, Inc., 59 Temple Place - Suite 330, Boston,         */
21  /* MA  02111-1307, USA.                                           */
22  /*                                                                */
23  /* For details, see the HELM World-Wide-Web page,                 */
24  /* http://cs.unibo.it/helm/.                                      */
25  /******************************************************************/
26
27  /***************************************************************/
28  /*                        META_LEXAN                           */
29  /*                 Automatic Metadata Extractor                */
30  /*           First draft 11/12/2001, by Andrea Asperti         */
31  /***************************************************************/
32
33  /***************************************************************/
34  /* 1. Inclusion of header files.                               */
35  /***************************************************************/
36
37 %{
38 #include                <string.h>
39 #include                <stdlib.h>
40 #include                "sthandler.h"
41 %}
42
43  /***************************************************************/
44  /* 2. Constants and Variables Definitions                      */
45  /***************************************************************/
46
47 %{
48 #define                 NOWHERE   0
49 #define                 CONST     1
50 #define                 MUTIND    2
51 #define                 MUTCONSTRUCT  3
52
53 #define                 INBODY    0
54 #define                 MAINHYP   1
55 #define                 INHYP     2
56 #define                 INCONCL   3
57 #define                 MAINCONCL 4
58 #define                 INTYPE    5
59 #define                 NOTFOUND  6
60
61 #define                 BEFORE    0
62 #define                 HERE      1     
63 #define                 AFTER     2
64
65
66 int                     where = NOWHERE;
67 int                     found = NOTFOUND;
68 int                     position = INBODY;
69 int                     first_child = BEFORE;
70 int                     no_open_source =0;
71 int                     tmp_n;
72 char                    sep = '"';
73 char                    *xpointer = "#xpointer(1/";
74 char                    *uri;
75 char                    *tmp;
76 %}
77
78  /***************************************************************/
79  /* 3. Regular definitions.                                     */
80  /***************************************************************/
81
82 uri                     [^"]+
83 digits                  [0-9]+                   
84
85  /***************************************************************/
86  /* 4. Rules.                                                   */
87  /***************************************************************/
88
89
90
91 %%
92
93 "<type>"           { 
94                      position = INTYPE;
95                      first_child = BEFORE;
96                    }
97
98 "<source"          {
99                     if ((position == INTYPE) ||
100                         (position == INHYP))
101                         { position = INHYP;
102                           no_open_source++;};
103                     /* printf("source %d\n", no_open_source); */
104                    }
105
106 "</source>"        {
107                     if (position == INHYP)
108                      {
109                       no_open_source--;
110                       /* printf("source %d\n", no_open_source); */
111                       if (no_open_source == 0) 
112                        { position = INTYPE;
113                          first_child = BEFORE; };
114                      };
115                    }
116
117
118 "<body>"           { 
119                      position = INBODY;
120                    }
121
122 .|\n               {
123                    }
124
125 "<APPLY"           {
126                     if (first_child == BEFORE)
127                           first_child = HERE;
128                     else if (first_child == HERE)
129                           first_child = AFTER; 
130                    } 
131
132 "<LAMBDA"          |
133 "<REL"             |
134 "<MUTCASE"         |
135 "<FIX"             |
136 "<COFIX"           { 
137                     if ((first_child == BEFORE) || (first_child == HERE))
138                           first_child = AFTER;
139                    }
140
141 "<CONST"           { 
142                      if (position == INTYPE) /* CONST on the spine */
143                         position = INCONCL;
144                      if (first_child == BEFORE)
145                           first_child = HERE;
146                      where = CONST;
147                    }
148
149 "<MUTIND"          { 
150                      if (position == INTYPE) /* MUTIND on the spine */
151                         position = INCONCL;
152                      if (first_child == BEFORE)
153                           first_child = HERE;
154                      where = MUTIND;
155                    }
156
157 "<MUTCONSTRUCT"    { 
158                      if (position == INTYPE) /* MUTCONSTRUCT on the spine */
159                         position = INCONCL;
160                      if (first_child == BEFORE)
161                           first_child = HERE;     
162                      where = MUTCONSTRUCT;
163                    }
164
165 "uri=\""{uri}      {     
166                          uri=(char *)malloc((sizeof('a')*200)); 
167                          strcpy(uri,yytext);
168                          strsep(&uri,&sep);
169                          if (where == CONST)
170                              {
171                                 search(uri,first_child,position); 
172                                 where = NOWHERE;
173                                 first_child = AFTER;
174                                 free(uri); 
175                               };
176                    } 
177
178 "noType=\""{digits} {
179                          if ((where == MUTIND) || (where == MUTCONSTRUCT))
180                           { strsep(&yytext,&sep);
181                             tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
182                             strcpy(tmp,yytext);
183                             tmp_n = atoi(tmp)+1;
184                             sprintf(tmp,"%d",tmp_n);
185                             strcat(uri,"#xpointer(1/"); 
186                             strcat(uri,tmp); 
187                           };
188                          if (where == MUTIND) 
189                              { 
190                                strcat(uri,")");
191                                search(uri,first_child,position); 
192                                free(uri);
193                                free(tmp);
194                                where = NOWHERE; 
195                                first_child = AFTER;};
196                    } 
197
198 "noConstr=\""{digits} {
199                          if (where == MUTCONSTRUCT)
200                           { strsep(&yytext,&sep);
201                             tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
202                             strcpy(tmp,yytext);
203                             strcat(uri,"/");
204                             strcat(uri,tmp);
205                             strcat(uri,")");
206                             search(uri,first_child,position);
207                             free(uri);
208                             free(tmp);
209                             where = NOWHERE; 
210                             first_child = AFTER;};
211                    } 
212
213
214
215 %%
216
217  /***************************************************************/
218  /* 6. Auxiliary functions.                                     */
219  /***************************************************************/
220
221 main(int argc, char *argv[])
222 {                  
223                    init_symbol_table();
224                    yylex();
225                    printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n");
226                    printf("<rdf:RDF xml:lang=\"en\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:h=\"http:/www.cs.unibo.it/helm/schemas/schema-h.rdf#\">\n");
227                    printf("<h:Object rdf:about=\"");
228                    printf("%s",argv[1]);
229                    printf("\">\n");
230                    print_all();
231                    printf("</h:Object>\n");
232                    printf("</rdf:RDF>\n");
233                    } 
234
235 search(uri,first_child,position)
236 char               *uri;
237 int                first_child;
238 int                position; 
239 {                  
240                    if (first_child == HERE)
241                       {
242                        if (position == INHYP)
243                           found = search_bucket(uri,MAINHYP);
244                        else if (position == INCONCL)
245                           found = search_bucket(uri,MAINCONCL);
246                        /* if (found == NOTFOUND)
247                           printf( "pos = %d, uri = %s\n", MAINCONCL, uri); */
248                        }
249                     else found = search_bucket(uri,position);
250                     /* if (found == NOTFOUND)
251                           printf( "pos = %d, uri = %s\n", position, uri); */
252                     }
253
254 int yywrap() {
255                return 1;
256              }
257
258
259
260
261
262
263