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/
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
14 #include "grammar.hpp"
15 #include "cleanup.hpp"
17 #include <boost/spirit/include/classic_symbols.hpp>
21 namespace cl = boost::spirit::classic;
23 // Information about a square bracket element (e.g. [* word]), and
24 // some other syntactic elements (such as lists and horizontal rules)..
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.....
36 // Used when there's no element.
39 // A section tag. These can't be nested.
42 // Block elements that can be used in conditional phrases and lists,
44 conditional_or_block = 2,
46 // Block elements that can be nested in other elements.
52 // Depending on the context this can be a block or phrase.
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.
61 // If the anchor was considered to be a phrase element, then the
62 // list wouldn't be recognised.
66 // Masks to determine which context elements can be used in (in_*), and
67 // whether they are consided to be a block element (is_*).
69 // At the top level we allow everything.
70 in_top_level = phrase | maybe_block | nested_block |
71 conditional_or_block | section_block,
73 // In conditional phrases and list blocks we everything but section
75 in_conditional = phrase | maybe_block | nested_block |
77 in_list_block = phrase | maybe_block | nested_block |
80 // In nested blocks we allow a more limited range of elements.
81 in_nested_block = phrase | maybe_block | nested_block,
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,
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,
91 // These are all block elements in all other contexts.
92 is_block = nested_block | conditional_or_block | section_block
96 : type(nothing), rule(), tag(0) {}
100 cl::rule<scanner>* r,
101 value::tag_type tag_ = value::default_tag,
103 : type(t), rule(r), tag(tag_), qbk_version(v) {}
106 cl::rule<scanner>* rule;
108 unsigned int qbk_version;
111 struct quickbook_grammar::impl
113 quickbook::state& state;
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;
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;
147 cl::symbols<element_info> elements;
150 cl::symbols<source_mode_type> source_modes;
153 cl::rule<scanner> doc_info_details;
155 impl(quickbook::state&);
160 void init_block_elements();
161 void init_phrase_elements();
162 void init_doc_info();
166 #endif // BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP