]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/grammar_impl.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / quickbook / src / grammar_impl.hpp
1 /*=============================================================================
2 Copyright (c) 2002 2004 2006 Joel de Guzman
3 Copyright (c) 2004 Eric Niebler
4 Copyright (c) 2010 Daniel James
5 http://spirit.sourceforge.net/
6
7 Use, modification and distribution is subject to the Boost Software
8 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 http://www.boost.org/LICENSE_1_0.txt)
10 =============================================================================*/
11 #if !defined(BOOST_SPIRIT_QUICKBOOK_GRAMMARS_IMPL_HPP)
12 #define BOOST_SPIRIT_QUICKBOOK_GRAMMARS_IMPL_HPP
13
14 #include "grammar.hpp"
15 #include "cleanup.hpp"
16 #include "values.hpp"
17 #include <boost/spirit/include/classic_symbols.hpp>
18
19 namespace quickbook
20 {
21 namespace cl = boost::spirit::classic;
22
23 // Information about a square bracket element (e.g. [* word]), and
24 // some other syntactic elements (such as lists and horizontal rules)..
25 struct element_info
26 {
27 // Types of elements.
28 //
29 // Used to determine:
30 //
31 // - where they can be used.
32 // - whether they end a paragraph
33 // - how following newlines are interpreted by the grammar.
34 // - and possibly other things.....
35 enum type_enum {
36 // Used when there's no element.
37 nothing = 0,
38
39 // A section tag. These can't be nested.
40 section_block = 1,
41
42 // Block elements that can be used in conditional phrases and lists,
43 // but not nested.
44 conditional_or_block = 2,
45
46 // Block elements that can be nested in other elements.
47 nested_block = 4,
48
49 // Phrase elements.
50 phrase = 8,
51
52 // Depending on the context this can be a block or phrase.
53 //
54 // Currently this is only used for elements that don't actually
55 // generate output (e.g. anchors, source mode tags). The main
56 // reason is so that lists can be preceeded by the element, e.g.
57 //
58 // [#anchor]
59 // * list item.
60 //
61 // If the anchor was considered to be a phrase element, then the
62 // list wouldn't be recognised.
63 maybe_block = 16
64 };
65
66 // Masks to determine which context elements can be used in (in_*), and
67 // whether they are consided to be a block element (is_*).
68 enum context {
69 // At the top level we allow everything.
70 in_top_level = phrase | maybe_block | nested_block |
71 conditional_or_block | section_block,
72
73 // In conditional phrases and list blocks we everything but section
74 // elements.
75 in_conditional = phrase | maybe_block | nested_block |
76 conditional_or_block,
77 in_list_block = phrase | maybe_block | nested_block |
78 conditional_or_block,
79
80 // In nested blocks we allow a more limited range of elements.
81 in_nested_block = phrase | maybe_block | nested_block,
82
83 // In a phrase we only allow phrase elements, ('maybe_block'
84 // elements are treated as phrase elements in this context)
85 in_phrase = phrase | maybe_block,
86
87 // At the start of a block these are all block elements.
88 is_contextual_block = maybe_block | nested_block |
89 conditional_or_block | section_block,
90
91 // These are all block elements in all other contexts.
92 is_block = nested_block | conditional_or_block | section_block
93 };
94
95 element_info()
96 : type(nothing), rule(), tag(0) {}
97
98 element_info(
99 type_enum t,
100 cl::rule<scanner>* r,
101 value::tag_type tag_ = value::default_tag,
102 unsigned int v = 0)
103 : type(t), rule(r), tag(tag_), qbk_version(v) {}
104
105 type_enum type;
106 cl::rule<scanner>* rule;
107 value::tag_type tag;
108 unsigned int qbk_version;
109 };
110
111 struct quickbook_grammar::impl
112 {
113 quickbook::state& state;
114 cleanup cleanup_;
115
116 // Main Grammar
117 cl::rule<scanner> block_start;
118 cl::rule<scanner> phrase_start;
119 cl::rule<scanner> nested_phrase;
120 cl::rule<scanner> inline_phrase;
121 cl::rule<scanner> paragraph_phrase;
122 cl::rule<scanner> extended_phrase;
123 cl::rule<scanner> table_title_phrase;
124 cl::rule<scanner> inside_preformatted;
125 cl::rule<scanner> inside_paragraph;
126 cl::rule<scanner> command_line;
127 cl::rule<scanner> attribute_template_body;
128 cl::rule<scanner> attribute_value_1_7;
129 cl::rule<scanner> escape;
130 cl::rule<scanner> raw_escape;
131 cl::rule<scanner> skip_entity;
132
133 // Miscellaneous stuff
134 cl::rule<scanner> hard_space; // Either non-empty space, or
135 // empty and not followed by
136 // alphanumeric/_. Use to match the
137 // the end of an itendifier.
138 cl::rule<scanner> space; // Space/tab/newline/comment (possibly empty)
139 cl::rule<scanner> blank; // Space/tab/comment (possibly empty)
140 cl::rule<scanner> eol; // blank >> eol
141 cl::rule<scanner> phrase_end; // End of phrase text, context sensitive
142 cl::rule<scanner> comment;
143 cl::rule<scanner> line_comment;
144 cl::rule<scanner> macro_identifier;
145
146 // Element Symbols
147 cl::symbols<element_info> elements;
148
149 // Source mode
150 cl::symbols<source_mode_type> source_modes;
151
152 // Doc Info
153 cl::rule<scanner> doc_info_details;
154
155 impl(quickbook::state&);
156
157 private:
158
159 void init_main();
160 void init_block_elements();
161 void init_phrase_elements();
162 void init_doc_info();
163 };
164 }
165
166 #endif // BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP