Ignore:
Timestamp:
Apr 9, 2015, 5:23:06 AM (9 years ago)
Author:
djay
Message:

Major update. Creation of a basic parsing api. Call validateRequest after fork if any.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/main_conf_read.y

    r607 r621  
    1 %{
    21/*
    32 * Zoo main configuration file parser
     3 *
     4 * Author : Gérald FENOY
     5 *
     6 * Copyright (c) 209-2015 GeoLabs SARL
     7 *
     8 * Permission is hereby granted, free of charge, to any person obtaining a copy
     9 * of this software and associated documentation files (the "Software"), to deal
     10 * in the Software without restriction, including without limitation the rights
     11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     12 * copies of the Software, and to permit persons to whom the Software is
     13 * furnished to do so, subject to the following conditions:
     14 *
     15 * The above copyright notice and this permission notice shall be included in
     16 * all copies or substantial portions of the Software.
     17 *
     18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     24 * THE SOFTWARE.
    425 */
     26%{
    527#include <service.h>
    628
     
    2850%}
    2951
     52%union { char* s;char* chaine; char* key;char* val;}
    3053
    31 
    32 //======================================================
    33 /* le type des lval des jetons et des elements non terminaux bison */
    34 //======================================================
    35 %union { char* s;char* chaine; char* key;char* val;}
    36 //======================================================
    37 
    38 // jetons //
    39 //======================================================
    40 /* les jetons que l on retrouve dans FLEX */
    41 //======================================================
    42 /* texte on a besoin de récupérer une valeur char* pour la comparer */
    4354%token <s> ID
    4455%token <s> CHAINE
    45 /* STARTXMLDECL et ENDXMLDECL qui sont <?xml et ?>*/
    46 %token STARTXMLDECL ENDXMLDECL
    47 //======================================================
    48 /* version="xxx" et encoding="xxx" */
    49 %token VERSIONDECL ENCODINGDECL SDDECL
    50 //======================================================
    51 /* < et > */
    52 %token INFCAR SUPCAR
    53 //======================================================
    54 /* / = a1  texte "texte" */
    55 %token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR EPAIRS ANID
     56
     57%token PAIR SPAIR EPAIR EPAIRS ANID
    5658%type <chaine> PAIR
    5759%type <chaine> EPAIRS
     
    5961%type <chaine> SPAIR
    6062
    61 //======================================================
    62 /* <!-- xxx -> <? xxx yyy ?> */
    63 %token PI PIERROR /** COMMENT **/
    64 //======================================================
    65 /* <!-- xxx -> <? xxx yyy ?> */
    66 %token ERREURGENERALE CDATA WHITESPACE NEWLINE
    67 //======================================================
    68 // non terminaux typés
    69 //======================================================
    70 /* elements non terminaux de type char *     */
    71 /* uniquement ceux qui devrons etre comparés */
    72 //======================================================
    73 %type <s> STag
    74 %type <s> ETag
     63%token WHITESPACE NEWLINE
     64
    7565%type <s> ANID
    76 //======================================================
    77 // %start
    78 //======================================================
    7966
    8067%%
    81 // document <//===
    82 //======================================================
    83 // regle 1
    84 // on est a la racine du fichier xml
    85 //======================================================
     68
    8669document
    87  : miscetoile element miscetoile {}
     70 : miscetoile miscetoile {}
    8871 | contentetoile processid contentetoile document {}
    8972 ;
    9073
    9174miscetoile
    92  : miscetoile PIERROR {crerror("processing instruction begining with <?xml ?> impossible\n");}
    93  | miscetoile PI {}
    94  | {}
     75 : {}
    9576 ;
    96 // element
    97 //======================================================
    98 // regle 39
    99 // OUVRANTE CONTENU FERMANTE obligatoirement
    100 // ou neutre
    101 // on ne peut pas avoir Epsilon
    102 // un fichier xml ne peut pas etre vide ou seulement avec un prolog
    103 //======================================================
    104 element
    105  : STag contentetoile ETag     
    106 {
    107   /* les non terminaux rendent les valeurs de leur identifiants de balise */
    108   /* en char*, donc on peut comparer ces valeurs avec la fonction C++ strcmp(const char*;const char*) */
    109   /* de string */
    110   if (strcmp($1,$3) != 0)
    111     {
    112       crerror("Opening and ending tag mismatch");
    113       printf("\n  ::details : tag '%s' et '%s' \n",$1,$3);
    114       return 1;
    115       // on retourne different de 0
    116       // sinon yyparse rendra 0
    117       // et dans le main on croira a le fichier xml est valide !
    118     }
    119 }
    120 // pour neutre
    121 // on a rien a faire, meme pas renvoyer l identificateur de balise
    122 // vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle .
    123  | EmptyElemTag          {}
    124  ;
    125 //======================================================
    126 // STag
    127 //======================================================
    128 // regle 40
    129 // BALISE OUVRANTE
    130 // on est obligé de faire appel a infcar et supcar
    131 // pour acceder aux start conditions DANSBALISE et INITIAL
    132 //======================================================
    133 STag
    134  : INFCAR ID Attributeetoile SUPCAR
    135 {       
    13677
    137 #ifdef DEBUG
    138         printf("* Identifiant : %s\n",$2);
    139 #endif
    140        
    141         $$ = $2 ;
    142 }
    143  ;
    144 //======================================================
    145 // Attributeetoile
    146 //======================================================
    147 // regle 41
    148 // une liste qui peut etre vide d'attributs
    149 // utiliser la récursivité a gauche
    150 //======================================================
    15178Attributeetoile
    152  : Attributeetoile attribute {}
     79 : Attributeetoile {}
    15380 |                                {/* Epsilon */}
    15481 ;
    155 //======================================================
    156 // attribute
    157 //======================================================
    158 // regle 41
    159 // un attribut est compose d'un identifiant
    160 // d'un "="
    161 // et d'une définition de chaine de caractere
    162 // ( "xxx" ou 'xxx' )
    163 //======================================================
    164 attribute
    165  : ID Eq ATTVALUE               
    166 {
    167         // on verifie que les attributst ne sont pas en double
    168         // sinon on ajoute au vector
    169 }
    170  ;
    171 //======================================================
    172 // EmptyElemTag
    173 //======================================================
    174 // regle 44
    175 // ICI ON DEFINIT NEUTRE
    176 // on ne renvoie pas de char*
    177 // parce qu'il n'y a pas de comparaisons a faire
    178 // avec un identifiant d'une balise jumelle
    179 //======================================================
    180 EmptyElemTag
    181  : INFCAR ID Attributeetoile SLASH SUPCAR       {}
    182  ;
    183 //======================================================
    184 // ETag
    185 //======================================================
    186 // regle 42
    187 // BALISE FERMANTE
    188 // les separateurs après ID sont filtrés
    189 //======================================================
    190 ETag
    191  : INFCAR SLASH ID SUPCAR
    192 {
    193   /* on renvoie l'identifiant de la balise pour pouvoir comparer les 2 */
    194   /* /!\ une balise fermante n'a pas d'attributs (c.f. : W3C) */
    195   $$ = $3;
    196 }
    197  ;
    198 //======================================================
    199 // contentetoile
    200 //======================================================
    201 // regle 43
    202 // ENTRE 2 BALISES
    203 // entre 2 balises, on peut avoir :
    204 // --- OUVRANTE CONTENU FERMANTE (recursivement !)
    205 // --- DU TEXTE quelconque
    206 // --- COMMENTS
    207 // --- DES PROCESSES INSTRUCTIONS
    208 // --- /!\ il peut y avoir une processing instruction invalide ! <?xml
    209 // --- EPSILON
    210 // ### et/ou tout ca a la suite en nombre indeterminé
    211 // ### donc c'est un operateur etoile (*)
    212 //======================================================
     82
    21383contentetoile
    214 : contentetoile element           {}
    215  | contentetoile PIERROR                  {crerror("processing instruction <?xml ?> impossible\n");}
    216  | contentetoile PI                       {}
    217 ///// on filtre les commentaires | contentetoile comment              {}
    218  | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/}
     84: contentetoile NEWLINE {}
    21985 | contentetoile pair {}
    220  | contentetoile processid {}
    221  | contentetoile texteinterbalise         {}
    222  | contentetoile CDATA {} 
    22386 | {/* Epsilon */}
    22487 ;
    225 //======================================================
    226 // texteinterbalise
    227 //======================================================
    228 // regle 14
    229 // DU TEXTE quelconque
    230 // c'est du CHARDATA
    231 // il y a eut un probleme avec ID,
    232 // on a mis des starts conditions,
    233 // maintenant on croise les ID dans les dbalises
    234 // et des CHARDATA hors des balises
    235 //======================================================
    236 texteinterbalise
    237  : CHARDATA             {}
    238  ;
    239 //======================================================
    24088
    241 pair: PAIR {curr_key=zStrdup($1);/*printf("START 0 PAIR FOUND !! \n [%s]\n",$1);*/}
     89pair: PAIR {curr_key=zStrdup($1);}
    24290| EPAIR {
    24391  if(current_content==NULL)
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

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