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

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

Add the optional YAML ZCFG support #4 and the zcfg2yaml converter. Return error messages that enable the service provider to quickly identify the root cause of errors due to configuration file syntax #90. Fix logic in addMapToMap #91. Enable multiple range definition using default and supported blocks. Add the lastest revision number in version.h (available from Python ZOO-API as zoo.VERSION).

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