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 "./phrase.hpp" |
---|
14 | #include <boost/spirit/core.hpp> |
---|
15 | #include <boost/spirit/actor.hpp> |
---|
16 | #include <boost/spirit/utility/loops.hpp> |
---|
17 | #include <boost/spirit/symbols/symbols.hpp> |
---|
18 | |
---|
19 | namespace quickbook |
---|
20 | { |
---|
21 | using namespace boost::spirit; |
---|
22 | extern unsigned qbk_major_version; |
---|
23 | extern unsigned qbk_minor_version; |
---|
24 | |
---|
25 | template <typename Actions> |
---|
26 | struct doc_info_grammar |
---|
27 | : public grammar<doc_info_grammar<Actions> > |
---|
28 | { |
---|
29 | doc_info_grammar(Actions& actions) |
---|
30 | : actions(actions) {} |
---|
31 | |
---|
32 | template <typename Scanner> |
---|
33 | struct definition |
---|
34 | { |
---|
35 | typedef uint_parser<int, 10, 1, 2> uint2_t; |
---|
36 | |
---|
37 | definition(doc_info_grammar const& self) |
---|
38 | : unused(false), common(self.actions, unused) |
---|
39 | { |
---|
40 | Actions& actions = self.actions; |
---|
41 | |
---|
42 | doc_types = |
---|
43 | "book", "article", "library", "chapter", "part" |
---|
44 | , "appendix", "preface", "qandadiv", "qandaset" |
---|
45 | , "reference", "set" |
---|
46 | ; |
---|
47 | |
---|
48 | doc_info = |
---|
49 | space |
---|
50 | >> '[' >> space |
---|
51 | >> (doc_types >> eps_p) [assign_a(actions.doc_type)] |
---|
52 | >> hard_space |
---|
53 | >> ( *(anychar_p - |
---|
54 | (ch_p('[') | ']' | eol_p) |
---|
55 | ) |
---|
56 | ) [assign_a(actions.doc_title)] |
---|
57 | >> !( |
---|
58 | space >> '[' >> |
---|
59 | quickbook_version |
---|
60 | >> space >> ']' |
---|
61 | ) |
---|
62 | >> |
---|
63 | *( |
---|
64 | space >> '[' >> |
---|
65 | ( |
---|
66 | doc_version |
---|
67 | | doc_id |
---|
68 | | doc_dirname |
---|
69 | | doc_copyright |
---|
70 | | doc_purpose [actions.extract_doc_purpose] |
---|
71 | | doc_category |
---|
72 | | doc_authors |
---|
73 | | doc_license [actions.extract_doc_license] |
---|
74 | | doc_last_revision |
---|
75 | | doc_source_mode |
---|
76 | ) |
---|
77 | >> space >> ']' >> +eol_p |
---|
78 | ) |
---|
79 | >> space >> ']' >> +eol_p |
---|
80 | ; |
---|
81 | |
---|
82 | quickbook_version = |
---|
83 | "quickbook" >> hard_space |
---|
84 | >> ( uint_p [assign_a(qbk_major_version)] |
---|
85 | >> '.' |
---|
86 | >> uint2_t() [assign_a(qbk_minor_version)] |
---|
87 | ) |
---|
88 | ; |
---|
89 | |
---|
90 | doc_version = |
---|
91 | "version" >> hard_space |
---|
92 | >> (*(anychar_p - ']')) [assign_a(actions.doc_version)] |
---|
93 | ; |
---|
94 | |
---|
95 | doc_id = |
---|
96 | "id" >> hard_space |
---|
97 | >> (*(anychar_p - ']')) [assign_a(actions.doc_id)] |
---|
98 | ; |
---|
99 | |
---|
100 | doc_dirname = |
---|
101 | "dirname" >> hard_space |
---|
102 | >> (*(anychar_p - ']')) [assign_a(actions.doc_dirname)] |
---|
103 | ; |
---|
104 | |
---|
105 | doc_copyright = |
---|
106 | "copyright" >> hard_space |
---|
107 | >> +( repeat_p(4)[digit_p] [push_back_a(actions.doc_copyright_years)] |
---|
108 | >> space |
---|
109 | ) |
---|
110 | >> space |
---|
111 | >> (*(anychar_p - ']')) [assign_a(actions.doc_copyright_holder)] |
---|
112 | ; |
---|
113 | |
---|
114 | doc_purpose = |
---|
115 | "purpose" >> hard_space |
---|
116 | >> phrase [assign_a(actions.doc_purpose_1_1)] |
---|
117 | ; |
---|
118 | |
---|
119 | doc_category = |
---|
120 | "category" >> hard_space |
---|
121 | >> (*(anychar_p - ']')) [assign_a(actions.doc_category)] |
---|
122 | ; |
---|
123 | |
---|
124 | doc_author = |
---|
125 | space |
---|
126 | >> '[' >> space |
---|
127 | >> (*(anychar_p - ',')) [assign_a(name.second)] // surname |
---|
128 | >> ',' >> space |
---|
129 | >> (*(anychar_p - ']')) [assign_a(name.first)] // firstname |
---|
130 | >> ']' |
---|
131 | ; |
---|
132 | |
---|
133 | doc_authors = |
---|
134 | "authors" >> hard_space |
---|
135 | >> doc_author [push_back_a(actions.doc_authors, name)] |
---|
136 | >> *( ',' |
---|
137 | >> doc_author [push_back_a(actions.doc_authors, name)] |
---|
138 | ) |
---|
139 | ; |
---|
140 | |
---|
141 | doc_license = |
---|
142 | "license" >> hard_space |
---|
143 | >> phrase [assign_a(actions.doc_license_1_1)] |
---|
144 | ; |
---|
145 | |
---|
146 | doc_last_revision = |
---|
147 | "last-revision" >> hard_space |
---|
148 | >> (*(anychar_p - ']')) [assign_a(actions.doc_last_revision)] |
---|
149 | ; |
---|
150 | |
---|
151 | doc_source_mode = |
---|
152 | "source-mode" >> hard_space |
---|
153 | >> ( |
---|
154 | str_p("c++") |
---|
155 | | "python" |
---|
156 | ) [assign_a(actions.source_mode)] |
---|
157 | ; |
---|
158 | |
---|
159 | comment = |
---|
160 | "[/" >> *(anychar_p - ']') >> ']' |
---|
161 | ; |
---|
162 | |
---|
163 | space = |
---|
164 | *(space_p | comment) |
---|
165 | ; |
---|
166 | |
---|
167 | hard_space = |
---|
168 | (eps_p - (alnum_p | '_')) >> space // must not be followed by |
---|
169 | ; // alpha-numeric or underscore |
---|
170 | |
---|
171 | phrase = |
---|
172 | *( common |
---|
173 | | comment |
---|
174 | | (anychar_p - ']') [actions.plain_char] |
---|
175 | ) |
---|
176 | ; |
---|
177 | } |
---|
178 | |
---|
179 | bool unused; |
---|
180 | std::pair<std::string, std::string> name; |
---|
181 | rule<Scanner> doc_info, doc_title, doc_version, doc_id, doc_dirname, |
---|
182 | doc_copyright, doc_purpose,doc_category, doc_authors, |
---|
183 | doc_author, comment, space, hard_space, doc_license, |
---|
184 | doc_last_revision, doc_source_mode, phrase, quickbook_version; |
---|
185 | phrase_grammar<Actions> common; |
---|
186 | symbols<> doc_types; |
---|
187 | |
---|
188 | rule<Scanner> const& |
---|
189 | start() const { return doc_info; } |
---|
190 | }; |
---|
191 | |
---|
192 | Actions& actions; |
---|
193 | }; |
---|
194 | } |
---|
195 | |
---|
196 | #endif // BOOST_SPIRIT_QUICKBOOK_DOC_INFO_HPP |
---|
197 | |
---|