00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_XML_REGEXP_HXX
00019 # define VCSN_XML_REGEXP_HXX
00020
00021 # include <set>
00022
00023 # include <xercesc/util/XMLString.hpp>
00024
00025 # include <vaucanson/algebra/concept/monoid_base.hh>
00026 # include <vaucanson/algebra/concept/freemonoid_base.hh>
00027
00028 # include <vaucanson/xml/tools.hh>
00029
00030 namespace vcsn
00031 {
00032 namespace xml
00033 {
00034
00035
00036
00037 template <typename T>
00038 RegexpHandler<T>::RegexpHandler (xercesc::SAX2XMLReader* parser,
00039 Handler& root,
00040 T param)
00041 : Handler(parser, root),
00042 end_(eq_.typedRegExp),
00043 param_(param),
00044 lefth_(0)
00045 {
00046 }
00047
00048 template <typename T>
00049 RegexpHandler<T>::RegexpHandler (xercesc::SAX2XMLReader* parser,
00050 Handler& root,
00051 T param,
00052 XMLCh* end)
00053 : Handler(parser, root),
00054 end_(end),
00055 param_(param),
00056 lefth_(0)
00057 {
00058 }
00059
00060 template <typename T>
00061 RegexpHandler<T>::~RegexpHandler()
00062 {
00063 delete lefth_;
00064 }
00065
00066 template <typename T>
00067 void
00068 RegexpHandler<T>::start (const XMLCh* const,
00069 const XMLCh* const localname,
00070 const XMLCh* const,
00071 const xercesc::Attributes&)
00072 {
00073 if (!(lefth_ = create(localname)))
00074 error::token(localname);
00075 else
00076 parser_->setContentHandler(lefth_);
00077 }
00078
00079 template <typename T>
00080 void
00081 RegexpHandler<T>::end (const XMLCh* const,
00082 const XMLCh* const localname,
00083 const XMLCh* const)
00084 {
00085 using namespace xercesc;
00086 if (XMLString::equals(end_, localname))
00087 {
00088 param_ = lefth_->series();
00089 parser_->setContentHandler(&root_);
00090 }
00091 else
00092 error::token(localname);
00093 }
00094
00095 template <typename T>
00096 T&
00097 RegexpHandler<T>::series()
00098 {
00099 return param_;
00100 }
00101
00102
00103
00104
00105 template <typename T>
00106 StarHandler<T>::StarHandler (xercesc::SAX2XMLReader* parser,
00107 Handler& root,
00108 T param)
00109 : RegexpHandler<T>(parser, root, param)
00110 {
00111 end_ = eq_.star;
00112 }
00113
00114 template <typename T>
00115 void
00116 StarHandler<T>::start (const XMLCh* const,
00117 const XMLCh* const localname,
00118 const XMLCh* const,
00119 const xercesc::Attributes&)
00120 {
00121 using namespace xercesc;
00122 in_++;
00123 if (in_ == 1 && (lefth_ = create(localname)))
00124 parser_->setContentHandler(lefth_);
00125 else
00126 error::token(localname);
00127 }
00128
00129 template <typename T>
00130 void
00131 StarHandler<T>::end (const XMLCh* const,
00132 const XMLCh* const localname,
00133 const XMLCh* const)
00134 {
00135 using namespace xercesc;
00136 if (XMLString::equals(end_, localname))
00137 {
00138 param_ = lefth_->series().star();
00139 parser_->setContentHandler(&root_);
00140 }
00141 else
00142 error::token(localname);
00143 }
00144
00145
00146
00147
00148 template <typename T>
00149 AtomHandler<T>::AtomHandler (xercesc::SAX2XMLReader* parser,
00150 Handler& root,
00151 T param,
00152 XMLCh* end)
00153 : RegexpHandler<T>(parser, root, param, end)
00154 {
00155 }
00156
00157 template <typename T>
00158 void
00159 AtomHandler<T>::start (const XMLCh* const,
00160 const XMLCh* const localname,
00161 const XMLCh* const,
00162 const xercesc::Attributes&)
00163 {
00164 error::token(localname);
00165 }
00166
00167 template <typename T>
00168 void
00169 AtomHandler<T>::end (const XMLCh* const,
00170 const XMLCh* const localname,
00171 const XMLCh* const)
00172 {
00173 using namespace xercesc;
00174 if (XMLString::equals(end_, localname))
00175 parser_->setContentHandler(&root_);
00176 else
00177 error::token(localname);
00178 }
00179
00180
00181
00182
00183 template <typename T>
00184 WeightHandler<T>::WeightHandler (xercesc::SAX2XMLReader* parser,
00185 Handler& root,
00186 T param)
00187 : RegexpHandler<T>(parser, root, param)
00188 {
00189 end_ = eq_.weight;
00190 }
00191
00192 template <typename T>
00193 void
00194 WeightHandler<T>::start (const XMLCh* const,
00195 const XMLCh* const localname,
00196 const XMLCh* const,
00197 const xercesc::Attributes&)
00198 {
00199 error::token(localname);
00200 }
00201
00202 template <typename T>
00203 void
00204 WeightHandler<T>::end (const XMLCh* const,
00205 const XMLCh* const localname,
00206 const XMLCh* const)
00207 {
00208 using namespace xercesc;
00209 if (XMLString::equals(end_, localname))
00210 parser_->setContentHandler(&root_);
00211 else
00212 error::token(localname);
00213 }
00214
00215
00216
00217
00218 template <typename T>
00219 ExtMulHandler<T>::ExtMulHandler (xercesc::SAX2XMLReader* parser,
00220 Handler& root,
00221 T param,
00222 bool left)
00223 : RegexpHandler<T>(parser, root, param),
00224 left_(left),
00225 righth_(0)
00226 {
00227 if (left)
00228 end_ = eq_.leftExtMul;
00229 else
00230 end_ = eq_.rightExtMul;
00231 }
00232
00233 template <typename T>
00234 ExtMulHandler<T>::~ExtMulHandler ()
00235 {
00236 delete righth_;
00237 }
00238
00239 template <typename T>
00240 void
00241 ExtMulHandler<T>::start (const XMLCh* const,
00242 const XMLCh* const localname,
00243 const XMLCh* const,
00244 const xercesc::Attributes& attrs)
00245 {
00246 using namespace xercesc;
00247 if (XMLString::equals(eq_.weight, localname) &&
00248 (lefth_ = create_weight(attrs)))
00249 parser_->setContentHandler(lefth_);
00250 else if ((righth_ = create(localname)))
00251 parser_->setContentHandler(righth_);
00252 else
00253 error::token(localname);
00254 }
00255
00256 template <typename T>
00257 void
00258 ExtMulHandler<T>::end (const XMLCh* const,
00259 const XMLCh* const localname,
00260 const XMLCh* const)
00261 {
00262 using namespace xercesc;
00263 if (XMLString::equals(end_, localname))
00264 {
00265 if (left_)
00266 param_ = lefth_->series() * righth_->series();
00267 else
00268 param_ = righth_->series() * lefth_->series();
00269 parser_->setContentHandler(&root_);
00270 }
00271 else
00272 error::token(localname);
00273 }
00274
00275
00276
00277
00278
00279 template <typename T>
00280 ProductHandler<T>::ProductHandler (xercesc::SAX2XMLReader* parser,
00281 Handler& root,
00282 T param)
00283 : RegexpHandler<T>(parser, root, param),
00284 in_(1),
00285 righth_(0)
00286 {
00287 end_ = eq_.product;
00288 }
00289
00290 template <typename T>
00291 ProductHandler<T>::~ProductHandler()
00292 {
00293 delete righth_;
00294 }
00295
00296 template <typename T>
00297 void
00298 ProductHandler<T>::start (const XMLCh* const,
00299 const XMLCh* const localname,
00300 const XMLCh* const,
00301 const xercesc::Attributes&)
00302 {
00303 using namespace xercesc;
00304 if (in_ == 1 && (lefth_ = create(localname)))
00305 parser_->setContentHandler(lefth_);
00306 else if (in_ == 2 && (righth_ = create(localname)))
00307 parser_->setContentHandler(righth_);
00308 else
00309 error::token(localname);
00310 in_++;
00311 }
00312
00313 template <typename T>
00314 void
00315 ProductHandler<T>::end (const XMLCh* const,
00316 const XMLCh* const localname,
00317 const XMLCh* const)
00318 {
00319 using namespace xercesc;
00320 if (XMLString::equals(end_, localname))
00321 {
00322 param_ = lefth_->series() * righth_->series();
00323 parser_->setContentHandler(&root_);
00324 }
00325 else if (!XMLString::equals(eq_.monGen, localname))
00326 error::token(localname);
00327 }
00328
00329
00330
00331 template <typename T>
00332 SumHandler<T>::SumHandler (xercesc::SAX2XMLReader* parser,
00333 Handler& root,
00334 T param)
00335 : RegexpHandler<T>(parser, root, param),
00336 in_(1),
00337 righth_(0)
00338 {
00339 end_ = eq_.sum;
00340 }
00341
00342 template <typename T>
00343 SumHandler<T>::~SumHandler ()
00344 {
00345 delete righth_;
00346 }
00347
00348 template <typename T>
00349 void
00350 SumHandler<T>::start (const XMLCh* const,
00351 const XMLCh* const localname,
00352 const XMLCh* const,
00353 const xercesc::Attributes&)
00354 {
00355 using namespace xercesc;
00356
00357 if (in_ == 1 && (lefth_ = create(localname)))
00358 parser_->setContentHandler(lefth_);
00359 else if (in_ == 2 && (righth_ = create(localname)))
00360 parser_->setContentHandler(righth_);
00361 else
00362 error::token(localname);
00363
00364 in_++;
00365 }
00366
00367 template <typename T>
00368 void
00369 SumHandler<T>::end (const XMLCh* const,
00370 const XMLCh* const localname,
00371 const XMLCh* const)
00372 {
00373 using namespace xercesc;
00374
00375 if (XMLString::equals(end_, localname))
00376 {
00377 param_ = lefth_->series() + righth_->series();
00378 parser_->setContentHandler(&root_);
00379 }
00380 else if (!XMLString::equals(eq_.monGen, localname))
00381 error::token(localname);
00382 }
00383
00384
00385
00386
00387 template <typename T>
00388 MonElmtHandler<T>::MonElmtHandler (xercesc::SAX2XMLReader* parser,
00389 Handler& root,
00390 T param)
00391 : RegexpHandler<T>(parser, root, param),
00392 mongenh_(0)
00393 {
00394 end_ = eq_.monElmt;
00395 }
00396
00397 template <typename T>
00398 void
00399 MonElmtHandler<T>::start (const XMLCh* const,
00400 const XMLCh* const localname,
00401 const XMLCh* const,
00402 const xercesc::Attributes& attrs)
00403 {
00404
00405
00406
00407
00408 using namespace xercesc;
00409
00410 if (XMLString::equals(eq_.monGen, localname))
00411 {
00412 typedef typename T::set_t::monoid_t monoid_t;
00413 typedef T actee_t;
00414
00415
00416 monGenAction<actee_t> action(param_);
00417
00418
00419 delete mongenh_;
00420
00421
00422 if (algebra::letter_traits<typename monoid_t::alphabet_t::letter_t>::kind() == "simple")
00423 {
00424 const XMLCh* value = tools::get_attribute(attrs, "value");
00425 mongenh_ = new monGenHandler<monoid_t, actee_t>(parser_, *this, action, value);
00426 }
00427 else
00428 mongenh_ = new monGenTupleHandler<monoid_t, actee_t>(parser_, *this, action);
00429
00430
00431 parser_->setContentHandler(mongenh_);
00432 }
00433 else
00434 error::token(localname);
00435 }
00436
00437 template <typename T>
00438 void
00439 MonElmtHandler<T>::end (const XMLCh* const,
00440 const XMLCh* const localname,
00441 const XMLCh* const)
00442 {
00443 using namespace xercesc;
00444
00445 if (XMLString::equals(end_, localname))
00446 {
00447
00448 delete mongenh_;
00449
00450
00451 parser_->setContentHandler(&root_);
00452 }
00453 else if (!XMLString::equals(eq_.monGen, localname))
00454 error::token(localname);
00455 }
00456
00457 }
00458 }
00459
00460 #endif // !VCSN_XML_REGEXP_HXX