From e094a4a8b4f04dcb572e38050cd538b2c65381c7 Mon Sep 17 00:00:00 2001 From: jez_higgins <> Date: Fri, 4 Apr 2003 19:30:29 +0000 Subject: [PATCH] Use boost::bind instead of our own binder class. --- SAX/parsers/saxgarden.h | 74 +++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/SAX/parsers/saxgarden.h b/SAX/parsers/saxgarden.h index 6d234e14..18086546 100644 --- a/SAX/parsers/saxgarden.h +++ b/SAX/parsers/saxgarden.h @@ -2,6 +2,7 @@ #define saxgarden_h #include +#include #include #include #include @@ -72,23 +73,6 @@ private: void hexCharacterRef(iterator_t s, iterator_t e); void characterRef(iterator_t s, iterator_t e, int base); - - typedef void(Garden::* xmlp_fn)(iterator_t s, iterator_t e); - class binder - { - public: - binder(Garden* p, xmlp_fn f) : p_(p), fn_(f) { } - - void operator()(iterator_t str, iterator_t end) const - { - (p_->*fn_)(str, end); - } // operator() - - private: - Garden* p_; - xmlp_fn fn_; - }; // class binder - // Start grammar definition rule_t prolog, element, Misc, Reference, CDSect, CDStart, CData, CDEnd, @@ -97,7 +81,7 @@ private: VersionNum, Eq, EmptyElemTag, STag, content, ETag, Attribute, AttValue, CharData, Comment, CharRef, EntityRef, EncName, document_, - Name, Comment1, S; + Name, Comment1, Spaces; stringT str(iterator_t s, iterator_t e, int trim = 0); @@ -131,8 +115,8 @@ Garden::Garden() : // characters chset_t Char("\x9\xA\xD\x20-\xFF"); - chset_t Sch("\x20\x9\xD\xA"); - S = +(Sch); + chset_t SpaceChar("\x20\x9\xD\xA"); + Spaces = +(SpaceChar); chset_t Letter("\x41-\x5A\x61-\x7A\xC0-\xD6\xD8-\xF6\xF8-\xFF"); chset_t Digit("0-9"); chlit_t Extender('\xB7'); @@ -142,55 +126,57 @@ Garden::Garden() : document_ = prolog >> element >> *Misc; chset_t CharDataChar (boost::spirit::anychar_p - (chset_t('<') | chset_t('&'))); - CharData = (*(CharDataChar - boost::spirit::str_p("]]>")))[binder(this, &Garden::elementContent)]; + CharData = (*(CharDataChar - boost::spirit::str_p("]]>")))[boost::bind(&Garden::elementContent, this, _1, _2)]; // Section 2.5 - Comments Comment = boost::spirit::str_p(""); Comment1 = *((Char - boost::spirit::ch_p('-')) | (boost::spirit::ch_p('-') >> (Char - boost::spirit::ch_p('-')))); // Section 2.6 - Processing Instructions - PI = boost::spirit::str_p("> (PITarget)[binder(this, &Garden::piTarget)] >> !S >> (PIData)[binder(this, &Garden::piData)] >> (boost::spirit::str_p("?>"))[binder(this, &Garden::piEnd)]; - PITarget = Name - boost::spirit::as_lower_d[(boost::spirit::str_p("xml"))]; - PIData = !(!S >> (*(Char - boost::spirit::str_p("?>")))); + PI = boost::spirit::str_p("> (PITarget)[boost::bind(&Garden::piTarget, this, _1, _2)] >> !Spaces >> (PIData)[boost::bind(&Garden::piData, this, _1, _2)] >> (boost::spirit::str_p("?>"))[boost::bind(&Garden::piEnd, this, _1, _2)]; + PITarget = Name - boost::spirit::as_lower_d[boost::spirit::str_p("xml")]; + PIData = !(!Spaces >> (*(Char - boost::spirit::str_p("?>")))); // Section 2.7 - CDATA - CDSect = CDStart >> (CData)[binder(this, &Garden::elementContent)] >> CDEnd; + CDSect = CDStart >> (CData)[boost::bind(&Garden::elementContent, this, _1, _2)] >> CDEnd; CDStart = boost::spirit::str_p("")); CDEnd = boost::spirit::str_p("]]>"); - prolog = !XMLDecl >> *Misc >> !(doctypedecl >> *Misc); - XMLDecl = boost::spirit::str_p("> VersionInfo >> !EncodingDecl >> !SDDecl >> !S >> boost::spirit::str_p("?>"); - VersionInfo = S >> boost::spirit::str_p("version") >> Eq >> (boost::spirit::ch_p('\'') >> VersionNum >>'\'' + // bits before the root elemenet + prolog = !XMLDecl >> *Misc >> !(doctypedecl >> *Misc); + XMLDecl = boost::spirit::str_p("> VersionInfo >> !EncodingDecl >> !SDDecl >> !Spaces >> boost::spirit::str_p("?>"); + VersionInfo = Spaces >> boost::spirit::str_p("version") >> Eq >> (boost::spirit::ch_p('\'') >> VersionNum >>'\'' | boost::spirit::ch_p('"') >> VersionNum >> '"'); - Eq = !S >> '=' >> !S; chset_t VersionNumCh("A-Za-z0-9_.:-"); VersionNum = +(VersionNumCh); - Misc = Comment | S | PI; - doctypedecl = boost::spirit::str_p("> *(Char - (chset_t('[') | '>')) >> !('[' >> *(Char - ']') >> ']') >> '>'; - - SDDecl = S >> boost::spirit::str_p("standalone") >> Eq >> ((boost::spirit::ch_p('\'') >> (boost::spirit::str_p("yes") | boost::spirit::str_p("no")) >> '\'') + SDDecl = Spaces >> boost::spirit::str_p("standalone") >> Eq >> ((boost::spirit::ch_p('\'') >> (boost::spirit::str_p("yes") | boost::spirit::str_p("no")) >> '\'') | (boost::spirit::ch_p('"') >> (boost::spirit::str_p("yes") | boost::spirit::str_p("no")) >> '"')); - element = STag >> (EmptyElemTag | (boost::spirit::str_p(">"))[binder(this, &Garden::closeElement)] >> content >> ETag); - STag = '<' >> (Name)[binder(this, &Garden::openElement)] >> *(S >> Attribute) >> !S; - Attribute = (Name)[binder(this, &Garden::attributeName)] >> Eq >> AttValue; - EmptyElemTag = (boost::spirit::str_p("/>"))[binder(this, &Garden::closeEmptyElement)]; - ETag = (boost::spirit::str_p("> (Name)[binder(this, &Garden::endElementName)] >> !S >> '>')[binder(this, &Garden::endElement)]; + // odd bits + Eq = !Spaces >> '=' >> !Spaces; + Misc = Comment | Spaces | PI; + + // Elements + element = STag >> (EmptyElemTag | (boost::spirit::str_p(">"))[boost::bind(&Garden::closeElement, this, _1, _2)] >> content >> ETag); + STag = '<' >> (Name)[boost::bind(&Garden::openElement, this, _1, _2)] >> *(Spaces >> Attribute) >> !Spaces; + Attribute = (Name)[boost::bind(&Garden::attributeName, this, _1, _2)] >> Eq >> AttValue; + EmptyElemTag = (boost::spirit::str_p("/>"))[boost::bind(&Garden::closeEmptyElement, this, _1, _2)]; + ETag = (boost::spirit::str_p("> (Name)[boost::bind(&Garden::endElementName, this, _1, _2)] >> !Spaces >> '>')[boost::bind(&Garden::endElement, this, _1, _2)]; - AttValue = '"' >> (*((boost::spirit::anychar_p - (chset_t('<') | '&' | '"')) | Reference))[binder(this, &Garden::attributeValue)] >> '"' - | '\'' >> (*((boost::spirit::anychar_p - (chset_t('<') | '&' | '\'')) | Reference))[binder(this, &Garden::attributeValue)] >> '\''; + AttValue = '"' >> (*((boost::spirit::anychar_p - (chset_t('<') | '&' | '"')) | Reference))[boost::bind(&Garden::attributeValue, this, _1, _2)] >> '"' + | '\'' >> (*((boost::spirit::anychar_p - (chset_t('<') | '&' | '\'')) | Reference))[boost::bind(&Garden::attributeValue, this, _1, _2)] >> '\''; content = !CharData >> *((element | Reference | CDSect | Comment | PI) >> !CharData); // Section 4.1 - Character and entity references - CharRef = boost::spirit::str_p("&#") >> (+boost::spirit::digit_p >> ';')[binder(this, &Garden::decimalCharacterRef)] | - boost::spirit::str_p("&#x") >> (+boost::spirit::xdigit_p >> ';')[binder(this, &Garden::hexCharacterRef)]; + CharRef = boost::spirit::str_p("&#") >> (+boost::spirit::digit_p >> ';')[boost::bind(&Garden::decimalCharacterRef, this, _1, _2)] | + boost::spirit::str_p("&#x") >> (+boost::spirit::xdigit_p >> ';')[boost::bind(&Garden::hexCharacterRef, this, _1, _2)]; Reference = EntityRef | CharRef; - EntityRef = '&' >> (Name >> boost::spirit::ch_p(';'))[binder(this, &Garden::entityRef)]; + EntityRef = '&' >> (Name >> boost::spirit::ch_p(';'))[boost::bind(&Garden::entityRef, this, _1, _2)]; - EncodingDecl = S >> boost::spirit::str_p("encoding") >> Eq >> (boost::spirit::ch_p('"') >> EncName >> '"' | + EncodingDecl = Spaces >> boost::spirit::str_p("encoding") >> Eq >> (boost::spirit::ch_p('"') >> EncName >> '"' | boost::spirit::ch_p('\'') >> EncName >> '\''); chset_t EncNameCh = VersionNumCh - chset_t(':'); EncName = boost::spirit::alpha_p >> *(EncNameCh);