| 1 | #ifndef BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP |
|---|
| 2 | #define BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP |
|---|
| 3 | |
|---|
| 4 | // MS compatible compilers support #pragma once |
|---|
| 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
|---|
| 6 | # pragma once |
|---|
| 7 | #endif |
|---|
| 8 | |
|---|
| 9 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|---|
| 10 | // basic_xml_grammar.hpp |
|---|
| 11 | |
|---|
| 12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
|---|
| 13 | // Use, modification and distribution is subject to the Boost Software |
|---|
| 14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 15 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 16 | |
|---|
| 17 | // See http://www.boost.org for updates, documentation, and revision history. |
|---|
| 18 | |
|---|
| 19 | // this module is derived from simplexml.cpp - an example shipped as part of |
|---|
| 20 | // the spirit parser. This example contains the following notice: |
|---|
| 21 | /*============================================================================= |
|---|
| 22 | simplexml.cpp |
|---|
| 23 | |
|---|
| 24 | Spirit V1.3 |
|---|
| 25 | URL: http://spirit.sourceforge.net/ |
|---|
| 26 | |
|---|
| 27 | Copyright (c) 2001, Daniel C. Nuffer |
|---|
| 28 | |
|---|
| 29 | This software is provided 'as-is', without any express or implied |
|---|
| 30 | warranty. In no event will the copyright holder be held liable for |
|---|
| 31 | any damages arising from the use of this software. |
|---|
| 32 | |
|---|
| 33 | Permission is granted to anyone to use this software for any purpose, |
|---|
| 34 | including commercial applications, and to alter it and redistribute |
|---|
| 35 | it freely, subject to the following restrictions: |
|---|
| 36 | |
|---|
| 37 | 1. The origin of this software must not be misrepresented; you must |
|---|
| 38 | not claim that you wrote the original software. If you use this |
|---|
| 39 | software in a product, an acknowledgment in the product documentation |
|---|
| 40 | would be appreciated but is not required. |
|---|
| 41 | |
|---|
| 42 | 2. Altered source versions must be plainly marked as such, and must |
|---|
| 43 | not be misrepresented as being the original software. |
|---|
| 44 | |
|---|
| 45 | 3. This notice may not be removed or altered from any source |
|---|
| 46 | distribution. |
|---|
| 47 | =============================================================================*/ |
|---|
| 48 | #include <string> |
|---|
| 49 | |
|---|
| 50 | #include <boost/config.hpp> |
|---|
| 51 | #include <boost/detail/workaround.hpp> |
|---|
| 52 | |
|---|
| 53 | // supress noise |
|---|
| 54 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) |
|---|
| 55 | # pragma warning (disable : 4786) // too long name, harmless warning |
|---|
| 56 | #endif |
|---|
| 57 | |
|---|
| 58 | //#define BOOST_SPIRIT_DEBUG |
|---|
| 59 | //#include <boost/spirit/core.hpp> |
|---|
| 60 | #include <boost/spirit/core/non_terminal/rule.hpp> |
|---|
| 61 | #include <boost/spirit/core/non_terminal/grammar.hpp> |
|---|
| 62 | |
|---|
| 63 | // the following hack is to evade a bogus error generated by using the |
|---|
| 64 | // word "arg" when bind.hpp has been included |
|---|
| 65 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) |
|---|
| 66 | #define arg xarg |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | #include <boost/spirit/utility/chset.hpp> |
|---|
| 70 | |
|---|
| 71 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) |
|---|
| 72 | #undef arg |
|---|
| 73 | #endif |
|---|
| 74 | |
|---|
| 75 | #include <boost/archive/basic_archive.hpp> |
|---|
| 76 | #include <boost/serialization/tracking.hpp> |
|---|
| 77 | #include <boost/serialization/version.hpp> |
|---|
| 78 | |
|---|
| 79 | namespace boost { |
|---|
| 80 | namespace archive { |
|---|
| 81 | |
|---|
| 82 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|---|
| 83 | // XML grammar parsing |
|---|
| 84 | |
|---|
| 85 | template<class CharType> |
|---|
| 86 | class basic_xml_grammar : public boost::spirit::grammar<basic_xml_grammar<CharType> > |
|---|
| 87 | { |
|---|
| 88 | public: |
|---|
| 89 | // The following is not necessary according to DR45, but at least |
|---|
| 90 | // one compiler (Compaq C++ 6.5 in strict_ansi mode) chokes otherwise. |
|---|
| 91 | struct return_values; |
|---|
| 92 | friend struct return_values; |
|---|
| 93 | |
|---|
| 94 | private: |
|---|
| 95 | typedef BOOST_DEDUCED_TYPENAME std::basic_istream<CharType> IStream; |
|---|
| 96 | typedef BOOST_DEDUCED_TYPENAME std::basic_string<CharType> StringType; |
|---|
| 97 | typedef BOOST_DEDUCED_TYPENAME boost::spirit::chset<CharType> chset_t; |
|---|
| 98 | typedef BOOST_DEDUCED_TYPENAME boost::spirit::chlit<CharType> chlit_t; |
|---|
| 99 | typedef BOOST_DEDUCED_TYPENAME boost::spirit::scanner< |
|---|
| 100 | BOOST_DEDUCED_TYPENAME std::basic_string<CharType>::iterator |
|---|
| 101 | > scanner_t; |
|---|
| 102 | typedef BOOST_DEDUCED_TYPENAME boost::spirit::rule<scanner_t> rule_t; |
|---|
| 103 | // Start grammar definition |
|---|
| 104 | rule_t |
|---|
| 105 | Reference, |
|---|
| 106 | Eq, |
|---|
| 107 | STag, |
|---|
| 108 | ETag, |
|---|
| 109 | LetterOrUnderscoreOrColon, |
|---|
| 110 | AttValue, |
|---|
| 111 | CharRef1, |
|---|
| 112 | CharRef2, |
|---|
| 113 | CharRef, |
|---|
| 114 | AmpRef, |
|---|
| 115 | LTRef, |
|---|
| 116 | GTRef, |
|---|
| 117 | AposRef, |
|---|
| 118 | QuoteRef, |
|---|
| 119 | CharData, |
|---|
| 120 | CharDataChars, |
|---|
| 121 | content, |
|---|
| 122 | AmpName, |
|---|
| 123 | LTName, |
|---|
| 124 | GTName, |
|---|
| 125 | ClassNameChar, |
|---|
| 126 | ClassName, |
|---|
| 127 | Name, |
|---|
| 128 | XMLDecl, |
|---|
| 129 | XMLDeclChars, |
|---|
| 130 | DocTypeDecl, |
|---|
| 131 | DocTypeDeclChars, |
|---|
| 132 | ClassIDAttribute, |
|---|
| 133 | ObjectIDAttribute, |
|---|
| 134 | ClassNameAttribute, |
|---|
| 135 | TrackingAttribute, |
|---|
| 136 | VersionAttribute, |
|---|
| 137 | UnusedAttribute, |
|---|
| 138 | Attribute, |
|---|
| 139 | SignatureAttribute, |
|---|
| 140 | SerializationWrapper, |
|---|
| 141 | NameHead, |
|---|
| 142 | NameTail, |
|---|
| 143 | AttributeList, |
|---|
| 144 | S; |
|---|
| 145 | |
|---|
| 146 | // XML Character classes |
|---|
| 147 | chset_t |
|---|
| 148 | BaseChar, |
|---|
| 149 | Ideographic, |
|---|
| 150 | Char, |
|---|
| 151 | Letter, |
|---|
| 152 | Digit, |
|---|
| 153 | CombiningChar, |
|---|
| 154 | Extender, |
|---|
| 155 | Sch, |
|---|
| 156 | NameChar; |
|---|
| 157 | |
|---|
| 158 | void init_chset(); |
|---|
| 159 | |
|---|
| 160 | bool my_parse( |
|---|
| 161 | IStream & is, |
|---|
| 162 | const rule_t &rule_, |
|---|
| 163 | const CharType delimiter = L'>' |
|---|
| 164 | ); |
|---|
| 165 | public: |
|---|
| 166 | struct return_values { |
|---|
| 167 | StringType object_name; |
|---|
| 168 | StringType contents; |
|---|
| 169 | class_id_type class_id; |
|---|
| 170 | object_id_type object_id; |
|---|
| 171 | version_type version; |
|---|
| 172 | tracking_type tracking_level; |
|---|
| 173 | StringType class_name; |
|---|
| 174 | return_values() : |
|---|
| 175 | version(0), |
|---|
| 176 | tracking_level(false) |
|---|
| 177 | {} |
|---|
| 178 | } rv; |
|---|
| 179 | bool parse_start_tag(IStream & is) ; |
|---|
| 180 | bool parse_end_tag(IStream & is); |
|---|
| 181 | bool parse_string(IStream & is, StringType & s); |
|---|
| 182 | void init(IStream & is); |
|---|
| 183 | void windup(IStream & is); |
|---|
| 184 | basic_xml_grammar(); |
|---|
| 185 | }; |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | } // namespace archive |
|---|
| 189 | } // namespace boost |
|---|
| 190 | |
|---|
| 191 | #endif // BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP |
|---|