source: trunk/zoo-project/zoo-kernel/main_conf_read.y @ 453

Last change on this file since 453 was 453, checked in by djay, 10 years ago

Add the optional Ruby Language Support to the ZOO-Kernel with an API similar to the Python ZOO-API. Small rewrite of Python support. Fix issue #86 and #87. Add usid in [lenv] section, this value is used to generate an unique identifier based on time and the process identifier. This usid is now used to name the stored result or the mapfile generated. Remove *some* warning messages displayed at compilation time.

File size: 9.6 KB
Line 
1%{
2//======================================================
3/**
4   Zoo main configuration file parser
5**/
6//======================================================
7
8#include <service.h>
9
10static int defaultsc=0;
11static maps* my_maps=NULL;
12static maps* current_maps=NULL;
13static map* previous_content=NULL;
14static map* current_content=NULL;
15static elements* current_element=NULL;
16static map* scontent=NULL;
17static char* curr_key;
18static int debug=0;
19static int previous_data=0;
20static int current_data=0;
21using namespace std;
22
23extern void crerror(const char *s);
24
25void usage(void) ;
26
27extern int crdebug;
28
29extern char crtext[];
30
31extern int crlineno;
32
33extern FILE* crin;
34
35extern int crlex(void);
36extern int crlex_destroy(void);
37
38%}
39
40
41
42//======================================================
43/* le type des lval des jetons et des elements non terminaux bison */
44//======================================================
45%union { char* s;char* chaine; char* key;char* val;}
46//======================================================
47
48// jetons //
49//======================================================
50/* les jetons que l on retrouve dans FLEX */
51//======================================================
52/* texte on a besoin de récupérer une valeur char* pour la comparer */
53%token <s> ID
54%token <s> CHAINE
55/* STARTXMLDECL et ENDXMLDECL qui sont <?xml et ?>*/
56%token STARTXMLDECL ENDXMLDECL
57//======================================================
58/* version="xxx" et encoding="xxx" */
59%token VERSIONDECL ENCODINGDECL SDDECL
60//======================================================
61/* < et > */
62%token INFCAR SUPCAR
63//======================================================
64/* / = a1  texte "texte" */
65%token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR EPAIRS ANID
66%type <chaine> PAIR
67%type <chaine> EPAIRS
68%type <chaine> EPAIR
69%type <chaine> SPAIR
70
71//======================================================
72/* <!-- xxx -> <? xxx yyy ?> */
73%token PI PIERROR /** COMMENT **/
74//======================================================
75/* <!-- xxx -> <? xxx yyy ?> */
76%token ERREURGENERALE CDATA WHITESPACE NEWLINE
77//======================================================
78// non terminaux typés
79//======================================================
80/* elements non terminaux de type char *     */
81/* uniquement ceux qui devrons etre comparés */
82//======================================================
83%type <s> STag
84%type <s> ETag
85%type <s> ANID
86//======================================================
87// %start
88//======================================================
89
90%%
91// document <//===
92//======================================================
93// regle 1
94// on est a la racine du fichier xml
95//======================================================
96document
97 : miscetoile element miscetoile {}
98 | contentetoile processid contentetoile document {}
99 ;
100
101miscetoile
102 : miscetoile PIERROR {crerror("processing instruction begining with <?xml ?> impossible\n");}
103 | miscetoile PI {}
104 | {}
105 ;
106// element
107//======================================================
108// regle 39
109// OUVRANTE CONTENU FERMANTE obligatoirement
110// ou neutre
111// on ne peut pas avoir Epsilon
112// un fichier xml ne peut pas etre vide ou seulement avec un prolog
113//======================================================
114element
115 : STag contentetoile ETag     
116{
117  /* les non terminaux rendent les valeurs de leur identifiants de balise */
118  /* en char*, donc on peut comparer ces valeurs avec la fonction C++ strcmp(const char*;const char*) */
119  /* de string */
120  if (strcmp($1,$3) != 0)
121    {
122      crerror("Opening and ending tag mismatch");
123      printf("\n  ::details : tag '%s' et '%s' \n",$1,$3);
124      return 1;
125      // on retourne different de 0
126      // sinon yyparse rendra 0
127      // et dans le main on croira a le fichier xml est valide !
128    }
129}
130// pour neutre
131// on a rien a faire, meme pas renvoyer l identificateur de balise
132// vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle .
133 | EmptyElemTag          {}
134 ;
135//======================================================
136// STag
137//======================================================
138// regle 40
139// BALISE OUVRANTE
140// on est obligé de faire appel a infcar et supcar
141// pour acceder aux start conditions DANSBALISE et INITIAL
142//======================================================
143STag
144 : INFCAR ID Attributeetoile SUPCAR
145{       
146
147#ifdef DEBUG
148        printf("* Identifiant : %s\n",$2);
149#endif
150       
151        $$ = $2 ;
152}
153 ;
154//======================================================
155// Attributeetoile
156//======================================================
157// regle 41
158// une liste qui peut etre vide d'attributs
159// utiliser la récursivité a gauche
160//======================================================
161Attributeetoile
162 : Attributeetoile attribute  {}
163 |                                {/* Epsilon */}
164 ;
165//======================================================
166// attribute
167//======================================================
168// regle 41
169// un attribut est compose d'un identifiant
170// d'un "="
171// et d'une définition de chaine de caractere
172// ( "xxx" ou 'xxx' )
173//======================================================
174attribute
175 : ID Eq ATTVALUE               
176{
177        // on verifie que les attributst ne sont pas en double
178        // sinon on ajoute au vector
179}
180 ;
181//======================================================
182// EmptyElemTag
183//======================================================
184// regle 44
185// ICI ON DEFINIT NEUTRE
186// on ne renvoie pas de char*
187// parce qu'il n'y a pas de comparaisons a faire
188// avec un identifiant d'une balise jumelle
189//======================================================
190EmptyElemTag
191 : INFCAR ID Attributeetoile SLASH SUPCAR       {}
192 ;
193//======================================================
194// ETag
195//======================================================
196// regle 42
197// BALISE FERMANTE
198// les separateurs après ID sont filtrés
199//======================================================
200ETag
201 : INFCAR SLASH ID SUPCAR
202{
203  /* on renvoie l'identifiant de la balise pour pouvoir comparer les 2 */
204  /* /!\ une balise fermante n'a pas d'attributs (c.f. : W3C) */
205  $$ = $3;
206}
207 ;
208//======================================================
209// contentetoile
210//======================================================
211// regle 43
212// ENTRE 2 BALISES
213// entre 2 balises, on peut avoir :
214// --- OUVRANTE CONTENU FERMANTE (recursivement !)
215// --- DU TEXTE quelconque
216// --- COMMENTS
217// --- DES PROCESSES INSTRUCTIONS
218// --- /!\ il peut y avoir une processing instruction invalide ! <?xml
219// --- EPSILON
220// ### et/ou tout ca a la suite en nombre indeterminé
221// ### donc c'est un operateur etoile (*)
222//======================================================
223contentetoile
224: contentetoile element           {}
225 | contentetoile PIERROR                  {crerror("processing instruction <?xml ?> impossible\n");}
226 | contentetoile PI                       {}
227///// on filtre les commentaires | contentetoile comment              {}
228 | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/}
229 | contentetoile pair {}
230 | contentetoile processid {}
231 | contentetoile texteinterbalise         {}
232 | contentetoile CDATA {} 
233 | {/* Epsilon */}
234 ;
235//======================================================
236// texteinterbalise
237//======================================================
238// regle 14
239// DU TEXTE quelconque
240// c'est du CHARDATA
241// il y a eut un probleme avec ID,
242// on a mis des starts conditions,
243// maintenant on croise les ID dans les dbalises
244// et des CHARDATA hors des balises
245//======================================================
246texteinterbalise
247 : CHARDATA             {}
248 ;
249//======================================================
250
251pair: PAIR {curr_key=zStrdup($1);/*printf("START 0 PAIR FOUND !! \n [%s]\n",$1);*/}
252| EPAIR {
253  if(current_content==NULL)
254    current_content=createMap(curr_key,$1);
255  else{
256    addToMap(current_content,curr_key,$1);
257  }
258  if(debug){
259    printf("EPAIR FOUND !! \n");
260    printf("[%s=>%s]\n",curr_key,$1);
261  }
262  free(curr_key);
263  }
264| SPAIR  {curr_key=zStrdup($1);if(debug) printf("SPAIR FOUND !!\n"); }
265 ;
266
267
268processid
269: ANID  {
270   if(current_maps->name!=NULL){
271     addMapToMap(&current_maps->content,current_content);
272     freeMap(&current_content);
273     free(current_content);
274     current_maps->next=NULL;
275     current_maps->next=(maps*)malloc(MAPS_SIZE);
276     current_maps->next->name=zStrdup($1);
277     current_maps->next->content=NULL;
278     current_maps->next->next=NULL;
279     current_maps=current_maps->next;
280     current_content=current_maps->content;
281   }
282   else{
283     current_maps->name=(char*)malloc((strlen($1)+1)*sizeof(char));
284     snprintf(current_maps->name,(strlen($1)+1),"%s",$1);
285     current_maps->content=NULL;
286     current_maps->next=NULL;
287     current_content=NULL;
288   }
289 }
290 ;
291
292%%
293
294// crerror
295//======================================================
296/* fonction qui affiche l erreur si il y en a une */
297//======================================================
298void crerror(const char *s)
299{
300  if(debug)
301    printf("\nligne %d : %s\n",crlineno,s);
302}
303
304// main
305//======================================================
306/* fonction principale : entrée dans le programme */
307//======================================================
308int conf_read(const char* file,maps* my_map){
309 
310  crin = fopen(file,"r");
311  if (crin==NULL){
312    return 2 ;
313  }
314
315  my_maps=my_map;
316  my_maps->name=NULL;
317  current_maps=my_maps;
318 
319  int resultatYYParse = crparse() ;
320  if(current_content!=NULL){
321    addMapToMap(&current_maps->content,current_content);
322    current_maps->next=NULL;
323    freeMap(&current_content);
324    free(current_content);
325  }
326
327  fclose(crin);
328#ifndef WIN32
329  crlex_destroy();
330#endif
331
332  return resultatYYParse;
333}
334
335
336//======================================================
337// FIN //
338//======================================================
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png