Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

defs.cc

00001 /*
00002 *  Name:      defs.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   CODEGEN definitions
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <cstring>
00027 #include <mpcl/text/codegen/defs.hh>
00028 
00029 
00031 namespace mpcl
00032 {
00033 
00035   namespace text
00036   {
00037 
00039     namespace codegen
00040     {
00041 
00042       //
00043       //  E X P O R T E D   V A R I A B L E S
00044       //
00045 
00046       //
00047       //  Tag definitions.
00048       //
00049 
00050       //
00051       //  <!-- ... -->
00052       //
00053       const char*   pkcCommentTagPattern = "[[:space:]]*<!--%t-->[[:space:]]*";
00054 
00055       //
00056       //  <!doctype dfaml [{system="value" | public="value"}]>
00057       //
00058       const char*   pkcDOCTYPE_TagPattern_1 = "[[:space:]]*<!doctype"
00059                                               "[[:space:]]+cdml[[:space:]]*>";
00060       const char*   pkcDOCTYPE_TagPattern_2 = "[[:space:]]*<!doctype"
00061                                               "[[:space:]]+cdml[[:space:]]+system[[:space:]]*>";
00062       const char*   pkcDOCTYPE_TagPattern_3 = "[[:space:]]*<!doctype"
00063                                               "[[:space:]]+cdml[[:space:]]+system"
00064                                               "[[:space:]]+%q[[:space:]]*>";
00065       const char*   pkcDOCTYPE_TagPattern_4 = "[[:space:]]*<!doctype"
00066                                               "[[:space:]]+cdml[[:space:]]+public"
00067                                               "[[:space:]]+%q[[:space:]]*>";
00068       //
00069       //  <cdml target="value" [inherit="value"]>...</dfaml>
00070       //
00071       const char*   pkcCDML_TagPattern_1  = "[[:space:]]*<cdml"
00072                                             "[[:space:]]+target[[:space:]]*="
00073                                             "[[:space:]]*%q"
00074                                             "[[:space:]]*>[[:blank:]]*\n?";
00075       const char*   pkcCDML_TagPattern_2  = "[[:space:]]*<cdml"
00076                                             "[[:space:]]+target[[:space:]]*="
00077                                             "[[:space:]]*%q"
00078                                             "[[:space:]]+inherit[[:space:]]*="
00079                                             "[[:space:]]*%q"
00080                                             "[[:space:]]*>[[:blank:]]*\n?";
00081       const char*   pkcCDML_TagPattern_3  = "[[:space:]]*<cdml"
00082                                             "[[:space:]]+inherit[[:space:]]*="
00083                                             "[[:space:]]*%q"
00084                                             "[[:space:]]+target[[:space:]]*="
00085                                             "[[:space:]]*%q"
00086                                             "[[:space:]]*>[[:blank:]]*\n?";
00087       const char*   pkcCDML_EndTagPattern = "[[:space:]]*</cdml[[:space:]]*>";
00088 
00089       //
00090       //  <desc>...</desc>
00091       //
00092       const char*   pkcDESC_ElementPattern = "[[:space:]]*<desc"
00093                                              "[[:space:]]*>[[:blank:]]*\n?"
00094                                              "%t[[:blank:]]*\n?</desc[[:space:]]*>";
00095 
00096       //
00097       //  <declare>...</declare>
00098       //
00099       const char*   pkcDECLARE_TagPattern    = "[[:space:]]*<declare[[:space:]]*>[[:blank:]]*\n?";
00100       const char*   pkcDECLARE_EndTagPattern = "[[:space:]]*</declare[[:space:]]*>";
00101 
00102       //
00103       //  <instruct name="value">...</instruct>
00104       //
00105       const char*   pkcINSTRUCT_TagPattern    = "[[:space:]]*<instruct[[:space:]]+"
00106                                                 "name[[:space:]]*=[[:space:]]*"
00107                                                 "%q[[:space:]]*>";
00108       const char*   pkcINSTRUCT_EndTagPattern = "[[:space:]]*</instruct[[:space:]]*>";
00109 
00110       //
00111       //  <variable name="value" [type={normal|file}]>
00112       //
00113       const char*   pkcVARIABLE_ElementPattern_1 = "[[:space:]]*<variable"
00114                                                    "[[:space:]]+name[[:space:]]*=[[:space:]]*%q"
00115                                                    "[[:space:]]*>%t</variable[[:space:]]*>";
00116       const char*   pkcVARIABLE_ElementPattern_2 = "[[:space:]]*<variable"
00117                                                    "[[:space:]]+name[[:space:]]*=[[:space:]]*%q"
00118                                                    "[[:space:]]+type[[:space:]]*=[[:space:]]*%q"
00119                                                    "[[:space:]]*>%t</variable[[:space:]]*>";
00120       const char*   pkcVARIABLE_ElementPattern_3 = "[[:space:]]*<variable"
00121                                                    "[[:space:]]+type[[:space:]]*=[[:space:]]*%q"
00122                                                    "[[:space:]]+name[[:space:]]*=[[:space:]]*%q"
00123                                                    "[[:space:]]*>%t</variable[[:space:]]*>";
00124 
00125       //
00126       //  <clause name="value" [target="value"] [nocheck]>...</clause>
00127       //
00128       const char*   pkcCLAUSE_TagBegin       = "[[:space:]]*<clause";
00129       const char*   pkcCLAUSE_TagNameAttr    = "[[:space:]]+name[[:space:]]*=[[:space:]]*%q";
00130       const char*   pkcCLAUSE_TagTargetAttr  = "[[:space:]]+target[[:space:]]*=[[:space:]]*%q";
00131       const char*   pkcCLAUSE_TagNoCheckAttr = "[[:space:]]+nocheck";
00132       const char*   pkcCLAUSE_TagEnd         = "[[:space:]]*>[[:blank:]]*\n?";
00133       const char*   pkcCLAUSE_BodyPattern    = "%t[[:blank:]]*</clause[[:space:]]*>";
00134 
00135       //
00136       //  Entity definitions.
00137       //
00138       const char*   pkcEntityPrefix      = "&";
00139       const char*   pkcGT_EntityPattern  = "&gt;";
00140       const char*   pkcGT_EntityValue    = ">";
00141       const char*   pkcLT_EntityPattern  = "&lt;";
00142       const char*   pkcLT_EntityValue    = "<";
00143       const char*   pkcNL_EntityPattern  = "&nl;";
00144       const char*   pkcNL_EntityValue    = "\n";
00145       const char*   pkcEOC_EntityPattern = "&eoc;";
00146       const char*   pkcAMP_EntityPattern = "&amp;";
00147       const char*   pkcAMP_EntityValue   = "&";
00148 
00149       //
00150       //  Entity lengths definitions.
00151       //
00152       size_t   zEntityPrefixLength      = std::strlen (pkcEntityPrefix);
00153       size_t   zGT_EntityPatternLength  = std::strlen (pkcGT_EntityPattern);
00154       size_t   zGT_EntityValueLength    = std::strlen (pkcGT_EntityValue);
00155       size_t   zLT_EntityPatternLength  = std::strlen (pkcLT_EntityPattern);
00156       size_t   zLT_EntityValueLength    = std::strlen (pkcLT_EntityValue);
00157       size_t   zNL_EntityPatternLength  = std::strlen (pkcNL_EntityPattern);
00158       size_t   zNL_EntityValueLength    = std::strlen (pkcNL_EntityValue);
00159       size_t   zEOC_EntityPatternLength = std::strlen (pkcEOC_EntityPattern);
00160       size_t   zAMP_EntityPatternLength = std::strlen (pkcAMP_EntityPattern);
00161       size_t   zAMP_EntityValueLength   = std::strlen (pkcAMP_EntityValue);
00162 
00163       //
00164       //  This is the separator used when encoding (name-mangling)
00165       //  clauses with an associated target.
00166       //
00167       const char*   pkcTargetSeparator = "::";
00168 
00169     }  // namespace codegen
00170 
00171   }  // namespace text
00172 
00173 }  // namespace mpcl
00174 
00175 
00176 //
00177 //  E X P O R T E D   F U N C T I O N S
00178 //
00179 
00180 void mpcl::text::codegen::
00181 InstantiateEntities (TString& ryTARGET_STRING)
00182 {
00183 
00184   using std::strncmp;
00185 
00186   const char*   pkcBase;
00187   size_t        zOffset = 0;
00188   
00189   //
00190   //  Replace all entities.
00191   //
00192   while ( TString::npos != (zOffset = ryTARGET_STRING.find (pkcEntityPrefix, zOffset)) )
00193   {
00194     pkcBase = ryTARGET_STRING.c_str() + zOffset;
00195     if ( !strncmp (pkcBase, pkcGT_EntityPattern, zGT_EntityPatternLength) )
00196     {
00197       ryTARGET_STRING.replace (zOffset, zGT_EntityPatternLength, pkcGT_EntityValue);
00198       zOffset += zGT_EntityValueLength;
00199     }
00200     else if ( !strncmp (pkcBase, pkcLT_EntityPattern, zLT_EntityPatternLength) )
00201     {
00202       ryTARGET_STRING.replace (zOffset, zLT_EntityPatternLength, pkcLT_EntityValue);
00203       zOffset += zLT_EntityValueLength;
00204     }
00205     else if ( !strncmp (pkcBase, pkcNL_EntityPattern, zNL_EntityPatternLength) )
00206     {
00207       ryTARGET_STRING.replace (zOffset, zNL_EntityPatternLength, pkcNL_EntityValue);
00208       zOffset += zNL_EntityValueLength;
00209     }
00210     else if ( !strncmp (pkcBase, pkcEOC_EntityPattern, zEOC_EntityPatternLength) )
00211     {
00212       ryTARGET_STRING.erase (zOffset);
00213       break;
00214     }
00215     else if ( !strncmp (pkcBase, pkcAMP_EntityPattern, zAMP_EntityPatternLength) )
00216     {
00217       ryTARGET_STRING.replace (zOffset, zAMP_EntityPatternLength, pkcAMP_EntityValue);
00218       zOffset += zAMP_EntityValueLength;
00219     }
00220     else
00221     {
00222       zOffset += zEntityPrefixLength;
00223     }
00224   }
00225   
00226 }  // InstantiateEntities()

Generated on Mon Oct 13 02:35:22 2003 for MPCL by doxygen1.2.18