----------------------- Spirit \ Mexico pression2.h ------------------------------
# Pragma once
# Include <string>
# Include <iostream>
# Include <cassert>
# Include <boost/spirit/include/classic_core.hpp>
# Include <boost/spirit/include/classic_confix.hpp>
# Include <boost/spirit/include/classic_chset.hpp>
Using namespace STD;
Using namespace boost_spirit_classic_ns;
Namespace mexpr {
//////////////////////////////////////// ///////////////////////////////////////
// Actor called after successfully matching a single character
Class actor_string
{
Public:
Actor_string (STD: string & rstr ):
Matched (rstr)
{
}
Void operator () (const char * pbegin, const char * pend) const
{
Matched + = STD: string (pbegin, pend-pbegin );
}
PRIVATE:
STD: string & matched;
};
Void ev_3 (const char * expr );
}
Bytes -------------------------------------------------------------------------------------------
------------------------ Spirit \ mexpression2.cpp ----------------------------------
# Include "mexpression2.h"
Void mexpr: ev_3 (const char * expr ){
String body;
Rule <> open_tag, html_tag, close_tag, body_text;
Open_tag = str_p ("<B> ");
Body_text = anychar_p;
Close_tag = str_p ("</B> ");
Html_tag = confix_p (open_tag, (* body_text) [actor_string (body)], close_tag );
Char const * ptag = "<B> body text </B> ";
parse_info <> result = parse (ptag, html_tag );
If (result. hit)
{< br> cout <"parsed HTML snippet \" body text \ "successfully"
"(with re-attached actor)! " cout <" found body ("<(INT) body. size () <"characters):";
cout <"\" "}< br> else
{< br> cout <"failed to parse HTML snippet (with re-attached actor )! "
}
String STR;
Rule <> strrule;
Strrule = confix_p (str_p ("\" "), (* anychar_p) [actor_string (STR)], str_p ("\""));
String S = "\" abcdefg \"";
Cout <S <Endl;
If (PARSE (S. c_str (), strrule). Hit)
{
Cout <STR <Endl;
}
Else
{
Cout <"not a string" <Endl;
}
}
Bytes -------------------------------------------------------------------------------------------