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 if (lefth_)
00064 delete lefth_;
00065 }
00066
00067 template <typename T>
00068 void
00069 RegexpHandler<T>::start (const XMLCh* const,
00070 const XMLCh* const localname,
00071 const XMLCh* const,
00072 const xercesc::Attributes&)
00073 {
00074 if (!(lefth_ = create(localname)))
00075 error::token(localname);
00076 else
00077 parser_->setContentHandler(lefth_);
00078 }
00079
00080 template <typename T>
00081 void
00082 RegexpHandler<T>::end (const XMLCh* const,
00083 const XMLCh* const localname,
00084 const XMLCh* const)
00085 {
00086 using namespace xercesc;
00087 if (XMLString::equals(end_, localname))
00088 {
00089 param_ = lefth_->series();
00090 parser_->setContentHandler(&root_);
00091 }
00092 else
00093 error::token(localname);
00094 }
00095
00096 template <typename T>
00097 T&
00098 RegexpHandler<T>::series()
00099 {
00100 return this->param_;
00101 }
00102
00103
00104
00105
00106 template <typename T>
00107 StarHandler<T>::StarHandler (xercesc::SAX2XMLReader* parser,
00108 Handler& root,
00109 T param)
00110 : RegexpHandler<T>(parser, root, param)
00111 {
00112 this->end_ = this->eq_.star;
00113 }
00114
00115 template <typename T>
00116 void
00117 StarHandler<T>::start (const XMLCh* const,
00118 const XMLCh* const localname,
00119 const XMLCh* const,
00120 const xercesc::Attributes&)
00121 {
00122 using namespace xercesc;
00123 in_++;
00124 if (in_ == 1 && (this->lefth_ = this->create(localname)))
00125 this->parser_->setContentHandler(this->lefth_);
00126 else
00127 error::token(localname);
00128 }
00129
00130 template <typename T>
00131 void
00132 StarHandler<T>::end (const XMLCh* const,
00133 const XMLCh* const localname,
00134 const XMLCh* const)
00135 {
00136 using namespace xercesc;
00137 if (XMLString::equals(this->end_, localname))
00138 {
00139 this->param_ = this->lefth_->series().star();
00140 this->parser_->setContentHandler(&this->root_);
00141 }
00142 else
00143 error::token(localname);
00144 }
00145
00146
00147
00148
00149 template <typename T>
00150 AtomHandler<T>::AtomHandler (xercesc::SAX2XMLReader* parser,
00151 Handler& root,
00152 T param,
00153 XMLCh* end)
00154 : RegexpHandler<T>(parser, root, param, end)
00155 {
00156 }
00157
00158 template <typename T>
00159 void
00160 AtomHandler<T>::start (const XMLCh* const,
00161 const XMLCh* const localname,
00162 const XMLCh* const,
00163 const xercesc::Attributes&)
00164 {
00165 error::token(localname);
00166 }
00167
00168 template <typename T>
00169 void
00170 AtomHandler<T>::end (const XMLCh* const,
00171 const XMLCh* const localname,
00172 const XMLCh* const)
00173 {
00174 using namespace xercesc;
00175 if (XMLString::equals(this->end_, localname))
00176 this->parser_->setContentHandler(&this->root_);
00177 else
00178 error::token(localname);
00179 }
00180
00181
00182
00183
00184 template <typename T>
00185 WeightHandler<T>::WeightHandler (xercesc::SAX2XMLReader* parser,
00186 Handler& root,
00187 T param)
00188 : RegexpHandler<T>(parser, root, param)
00189 {
00190 this->end_ = this->eq_.weight;
00191 }
00192
00193 template <typename T>
00194 void
00195 WeightHandler<T>::start (const XMLCh* const,
00196 const XMLCh* const localname,
00197 const XMLCh* const,
00198 const xercesc::Attributes&)
00199 {
00200 error::token(localname);
00201 }
00202
00203 template <typename T>
00204 void
00205 WeightHandler<T>::end (const XMLCh* const,
00206 const XMLCh* const localname,
00207 const XMLCh* const)
00208 {
00209 using namespace xercesc;
00210 if (XMLString::equals(this->end_, localname))
00211 this->parser_->setContentHandler(&this->root_);
00212 else
00213 error::token(localname);
00214 }
00215
00216
00217
00218
00219 template <typename T>
00220 ExtMulHandler<T>::ExtMulHandler (xercesc::SAX2XMLReader* parser,
00221 Handler& root,
00222 T param,
00223 bool left)
00224 : RegexpHandler<T>(parser, root, param),
00225 left_(left),
00226 righth_(0)
00227 {
00228 if (left)
00229 this->end_ = this->eq_.leftExtMul;
00230 else
00231 this->end_ = this->eq_.rightExtMul;
00232 }
00233
00234 template <typename T>
00235 ExtMulHandler<T>::~ExtMulHandler ()
00236 {
00237 delete righth_;
00238 }
00239
00240 template <typename T>
00241 void
00242 ExtMulHandler<T>::start (const XMLCh* const,
00243 const XMLCh* const localname,
00244 const XMLCh* const,
00245 const xercesc::Attributes& attrs)
00246 {
00247 using namespace xercesc;
00248 if (XMLString::equals(this->eq_.weight, localname) &&
00249 (this->lefth_ = this->create_weight(attrs)))
00250 this->parser_->setContentHandler(this->lefth_);
00251 else if ((this->righth_ = this->create(localname)))
00252 this->parser_->setContentHandler(this->righth_);
00253 else
00254 error::token(localname);
00255 }
00256
00257 template <typename T>
00258 void
00259 ExtMulHandler<T>::end (const XMLCh* const,
00260 const XMLCh* const localname,
00261 const XMLCh* const)
00262 {
00263 using namespace xercesc;
00264 if (XMLString::equals(this->end_, localname))
00265 {
00266 if (left_)
00267 this->param_ = this->lefth_->series() * this->righth_->series();
00268 else
00269 this->param_ = this->righth_->series() * this->lefth_->series();
00270 this->parser_->setContentHandler(&this->root_);
00271 }
00272 else
00273 error::token(localname);
00274 }
00275
00276
00277
00278
00279
00280 template <typename T>
00281 ProductHandler<T>::ProductHandler (xercesc::SAX2XMLReader* parser,
00282 Handler& root,
00283 T param)
00284 : RegexpHandler<T>(parser, root, param),
00285 in_(1),
00286 righth_(0)
00287 {
00288 this->end_ = this->eq_.product;
00289 }
00290
00291 template <typename T>
00292 ProductHandler<T>::~ProductHandler()
00293 {
00294 delete righth_;
00295 }
00296
00297 template <typename T>
00298 void
00299 ProductHandler<T>::start (const XMLCh* const,
00300 const XMLCh* const localname,
00301 const XMLCh* const,
00302 const xercesc::Attributes&)
00303 {
00304 using namespace xercesc;
00305 if (in_ == 1 && (this->lefth_ = this->create(localname)))
00306 this->parser_->setContentHandler(this->lefth_);
00307 else if (in_ == 2 && (this->righth_ = this->create(localname)))
00308 this->parser_->setContentHandler(this->righth_);
00309 else
00310 error::token(localname);
00311 in_++;
00312 }
00313
00314 template <typename T>
00315 void
00316 ProductHandler<T>::end (const XMLCh* const,
00317 const XMLCh* const localname,
00318 const XMLCh* const)
00319 {
00320 using namespace xercesc;
00321 if (XMLString::equals(this->end_, localname))
00322 {
00323 this->param_ = this->lefth_->series() * this->righth_->series();
00324 this->parser_->setContentHandler(&this->root_);
00325 }
00326 else if (!XMLString::equals(this->eq_.monGen, localname))
00327 error::token(localname);
00328 }
00329
00330
00331
00332 template <typename T>
00333 SumHandler<T>::SumHandler (xercesc::SAX2XMLReader* parser,
00334 Handler& root,
00335 T param)
00336 : RegexpHandler<T>(parser, root, param),
00337 in_(1),
00338 righth_(0)
00339 {
00340 this->end_ = this->eq_.sum;
00341 }
00342
00343 template <typename T>
00344 SumHandler<T>::~SumHandler ()
00345 {
00346 delete righth_;
00347 }
00348
00349 template <typename T>
00350 void
00351 SumHandler<T>::start (const XMLCh* const,
00352 const XMLCh* const localname,
00353 const XMLCh* const,
00354 const xercesc::Attributes&)
00355 {
00356 using namespace xercesc;
00357 if (in_ == 1 && (this->lefth_ = this->create(localname)))
00358 this->parser_->setContentHandler(this->lefth_);
00359 else if (in_ == 2 && (this->righth_ = this->create(localname)))
00360 this->parser_->setContentHandler(this->righth_);
00361 else
00362 error::token(localname);
00363 in_++;
00364 }
00365
00366 template <typename T>
00367 void
00368 SumHandler<T>::end (const XMLCh* const,
00369 const XMLCh* const localname,
00370 const XMLCh* const)
00371 {
00372 using namespace xercesc;
00373 if (XMLString::equals(this->end_, localname))
00374 {
00375 this->param_ = this->lefth_->series() + this->righth_->series();
00376 this->parser_->setContentHandler(&this->root_);
00377 }
00378 else if (!XMLString::equals(this->eq_.monGen, localname))
00379 error::token(localname);
00380 }
00381
00382
00383
00384
00385 template <typename T>
00386 MonElmtHandler<T>::MonElmtHandler (xercesc::SAX2XMLReader* parser,
00387 Handler& root,
00388 T param)
00389 : RegexpHandler<T>(parser, root, param)
00390 {
00391 this->end_ = this->eq_.monElmt;
00392 }
00393
00394 template <typename T>
00395 void
00396 MonElmtHandler<T>::start (const XMLCh* const,
00397 const XMLCh* const localname,
00398 const XMLCh* const,
00399 const xercesc::Attributes& attrs)
00400 {
00401 using namespace xercesc;
00402 if (XMLString::equals(this->eq_.monGen, localname))
00403 {
00404 typename T::monoid_elt_t m(this->param_.structure().monoid());
00405 const std::string val(xmlstr(tools::get_attribute(attrs, "value")));
00406 std::set<char> escaped;
00407 std::string::const_iterator i = val.begin();
00408 if (!parse_word(m, val, i, escaped))
00409 error::attrs(localname, "value", val);
00410 T tmp(this->param_.structure(), m);
00411 this->param_ = this->param_ * tmp;
00412 }
00413 else
00414 error::token(localname);
00415 }
00416
00417 template <typename T>
00418 void
00419 MonElmtHandler<T>::end (const XMLCh* const,
00420 const XMLCh* const localname,
00421 const XMLCh* const)
00422 {
00423 using namespace xercesc;
00424 if (XMLString::equals(this->end_, localname))
00425 this->parser_->setContentHandler(&this->root_);
00426 else if (!XMLString::equals(this->eq_.monGen, localname))
00427 error::token(localname);
00428 }
00429
00430 }
00431 }
00432
00433 #endif // !VCSN_XML_REGEXP_HXX