| 1 | /*============================================================================= |
|---|
| 2 | Copyright (c) 2002 2004 Joel de Guzman |
|---|
| 3 | Copyright (c) 2004 Eric Niebler |
|---|
| 4 | http://spirit.sourceforge.net/ |
|---|
| 5 | |
|---|
| 6 | Use, modification and distribution is subject to the Boost Software |
|---|
| 7 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 8 | http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 9 | =============================================================================*/ |
|---|
| 10 | #if !defined(BOOST_SPIRIT_QUICKBOOK_DOC_INFO_HPP) |
|---|
| 11 | #define BOOST_SPIRIT_QUICKBOOK_DOC_INFO_HPP |
|---|
| 12 | |
|---|
| 13 | #include <boost/spirit/core.hpp> |
|---|
| 14 | #include <boost/spirit/actor.hpp> |
|---|
| 15 | #include <boost/spirit/utility/loops.hpp> |
|---|
| 16 | |
|---|
| 17 | namespace quickbook |
|---|
| 18 | { |
|---|
| 19 | using namespace boost::spirit; |
|---|
| 20 | |
|---|
| 21 | template <typename Actions> |
|---|
| 22 | struct doc_info_grammar |
|---|
| 23 | : public grammar<doc_info_grammar<Actions> > |
|---|
| 24 | { |
|---|
| 25 | doc_info_grammar(Actions& actions) |
|---|
| 26 | : actions(actions) {} |
|---|
| 27 | |
|---|
| 28 | template <typename Scanner> |
|---|
| 29 | struct definition |
|---|
| 30 | { |
|---|
| 31 | definition(doc_info_grammar const& self) |
|---|
| 32 | { |
|---|
| 33 | doc_info = |
|---|
| 34 | space |
|---|
| 35 | >> '[' |
|---|
| 36 | >> ( str_p("book") |
|---|
| 37 | | "article" |
|---|
| 38 | | "library" |
|---|
| 39 | | "chapter" |
|---|
| 40 | | "part" |
|---|
| 41 | ) [assign_a(self.actions.doc_type)] |
|---|
| 42 | >> hard_space |
|---|
| 43 | >> ( *(anychar_p - |
|---|
| 44 | (ch_p('[') | ']' | eol_p) |
|---|
| 45 | ) |
|---|
| 46 | ) [assign_a(self.actions.doc_title)] |
|---|
| 47 | >> *( doc_version |
|---|
| 48 | | doc_id |
|---|
| 49 | | doc_dirname |
|---|
| 50 | | doc_copyright |
|---|
| 51 | | doc_purpose |
|---|
| 52 | | doc_category |
|---|
| 53 | | doc_authors |
|---|
| 54 | | doc_license |
|---|
| 55 | | doc_last_revision |
|---|
| 56 | | doc_source_mode |
|---|
| 57 | ) |
|---|
| 58 | >> ']' >> +eol_p |
|---|
| 59 | ; |
|---|
| 60 | |
|---|
| 61 | doc_version = |
|---|
| 62 | space |
|---|
| 63 | >> "[version" >> hard_space |
|---|
| 64 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_version)] |
|---|
| 65 | >> ']' >> +eol_p |
|---|
| 66 | ; |
|---|
| 67 | |
|---|
| 68 | doc_id = |
|---|
| 69 | space |
|---|
| 70 | >> "[id" >> hard_space |
|---|
| 71 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_id)] |
|---|
| 72 | >> ']' >> +eol_p |
|---|
| 73 | ; |
|---|
| 74 | |
|---|
| 75 | doc_dirname = |
|---|
| 76 | space |
|---|
| 77 | >> "[dirname" >> hard_space |
|---|
| 78 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_dirname)] |
|---|
| 79 | >> ']' >> +eol_p |
|---|
| 80 | ; |
|---|
| 81 | |
|---|
| 82 | doc_copyright = |
|---|
| 83 | space |
|---|
| 84 | >> "[copyright" >> hard_space |
|---|
| 85 | >> +( repeat_p(4)[digit_p] [push_back_a(self.actions.doc_copyright_years)] |
|---|
| 86 | >> space |
|---|
| 87 | ) |
|---|
| 88 | >> space |
|---|
| 89 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_copyright_holder)] |
|---|
| 90 | >> ']' >> +eol_p |
|---|
| 91 | ; |
|---|
| 92 | |
|---|
| 93 | doc_purpose = |
|---|
| 94 | space |
|---|
| 95 | >> "[purpose" >> hard_space |
|---|
| 96 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_purpose)] |
|---|
| 97 | >> ']' >> +eol_p |
|---|
| 98 | ; |
|---|
| 99 | |
|---|
| 100 | doc_category = |
|---|
| 101 | space |
|---|
| 102 | >> "[category" >> hard_space |
|---|
| 103 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_category)] |
|---|
| 104 | >> ']' >> +eol_p |
|---|
| 105 | ; |
|---|
| 106 | |
|---|
| 107 | doc_author = |
|---|
| 108 | space |
|---|
| 109 | >> '[' >> space |
|---|
| 110 | >> (*(anychar_p - ',')) [assign_a(name.second)] // surname |
|---|
| 111 | >> ',' >> space |
|---|
| 112 | >> (*(anychar_p - ']')) [assign_a(name.first)] // firstname |
|---|
| 113 | >> ']' |
|---|
| 114 | ; |
|---|
| 115 | |
|---|
| 116 | doc_authors = |
|---|
| 117 | space |
|---|
| 118 | >> "[authors" >> hard_space |
|---|
| 119 | >> doc_author [push_back_a(self.actions.doc_authors, name)] |
|---|
| 120 | >> *( ',' |
|---|
| 121 | >> doc_author [push_back_a(self.actions.doc_authors, name)] |
|---|
| 122 | ) |
|---|
| 123 | >> ']' >> +eol_p |
|---|
| 124 | ; |
|---|
| 125 | |
|---|
| 126 | doc_license = |
|---|
| 127 | space |
|---|
| 128 | >> "[license" >> hard_space |
|---|
| 129 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_license)] |
|---|
| 130 | >> ']' >> +eol_p |
|---|
| 131 | ; |
|---|
| 132 | |
|---|
| 133 | doc_last_revision = |
|---|
| 134 | space |
|---|
| 135 | >> "[last-revision" >> hard_space |
|---|
| 136 | >> (*(anychar_p - ']')) [assign_a(self.actions.doc_last_revision)] |
|---|
| 137 | >> ']' >> +eol_p |
|---|
| 138 | ; |
|---|
| 139 | |
|---|
| 140 | doc_source_mode = |
|---|
| 141 | space |
|---|
| 142 | >> "[source-mode" >> hard_space |
|---|
| 143 | >> ( |
|---|
| 144 | str_p("c++") |
|---|
| 145 | | "python" |
|---|
| 146 | ) [assign_a(self.actions.source_mode)] |
|---|
| 147 | >> space >> ']' >> +eol_p |
|---|
| 148 | ; |
|---|
| 149 | |
|---|
| 150 | comment = |
|---|
| 151 | "[/" >> *(anychar_p - ']') >> ']' |
|---|
| 152 | ; |
|---|
| 153 | |
|---|
| 154 | space = |
|---|
| 155 | *(space_p | comment) |
|---|
| 156 | ; |
|---|
| 157 | |
|---|
| 158 | hard_space = |
|---|
| 159 | (eps_p - (alnum_p | '_')) >> space // must not be followed by |
|---|
| 160 | ; // alpha-numeric or underscore |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | std::pair<std::string, std::string> name; |
|---|
| 164 | rule<Scanner> doc_info, doc_title, doc_version, doc_id, doc_dirname, |
|---|
| 165 | doc_copyright, doc_purpose,doc_category, doc_authors, |
|---|
| 166 | doc_author, comment, space, hard_space, doc_license, |
|---|
| 167 | doc_last_revision, doc_source_mode; |
|---|
| 168 | |
|---|
| 169 | rule<Scanner> const& |
|---|
| 170 | start() const { return doc_info; } |
|---|
| 171 | }; |
|---|
| 172 | |
|---|
| 173 | Actions& actions; |
|---|
| 174 | }; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | #endif // BOOST_SPIRIT_QUICKBOOK_DOC_INFO_HPP |
|---|
| 178 | |
|---|