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]).
25 // TODO: The naming is a bit confused as element is also sometimes used for
26 // syntactic/implicit elements (such as lists and horizontal rules). Maybe
27 // should use entity as a more general name instead of element. Or it might
28 // be better to use 'tag' for square bracket elements, although that is
29 // currently used for the type of entities.
36 // - where they can be used.
37 // - whether they end a paragraph
38 // - how following newlines are interpreted by the grammar.
39 // - and possibly other things.....
41 // Used when there's no element.
44 // A section tag. These can't be nested.
47 // Block elements that can be used in conditional phrases and lists,
48 // but not nested. (TODO: not a good name).
49 conditional_or_block = 2,
51 // Block elements that can be nested in other elements.
57 // Depending on the context this can be a block or phrase.
59 // Currently this is only used for elements that don't actually
60 // generate output (e.g. anchors, source mode tags). The main
61 // reason is so that lists can be preceeded by the element, e.g.
66 // If the anchor was considered to be a phrase element, then the
67 // list wouldn't be recognised.
71 // Masks to determine which context elements can be used in (in_*), and
72 // whether they are consided to be a block element (is_*).
74 // At the top level we allow everything.
75 in_top_level = phrase | maybe_block | nested_block |
76 conditional_or_block | section_block,
78 // In conditional phrases and list blocks we everything but section
80 in_conditional = phrase | maybe_block | nested_block |
82 in_list_block = phrase | maybe_block | nested_block |
85 // In nested blocks we allow a more limited range of elements.
86 in_nested_block = phrase | maybe_block | nested_block,
88 // In a phrase we only allow phrase elements, ('maybe_block'
89 // elements are treated as phrase elements in this context)
90 in_phrase = phrase | maybe_block,
92 // At the start of a block these are all block elements.
93 is_contextual_block = maybe_block | nested_block |
94 conditional_or_block | section_block,
96 // These are all block elements in all other contexts.
97 is_block = nested_block | conditional_or_block | section_block,
101 : type(nothing), rule(), tag(0) {}
105 cl::rule<scanner>* r,
106 value::tag_type tag = value::default_tag,
108 : type(t), rule(r), tag(tag), qbk_version(v) {}
111 cl::rule<scanner>* rule;
113 unsigned int qbk_version;
116 struct quickbook_grammar::impl
118 quickbook::state& state;
122 cl::rule<scanner> block_start;
123 cl::rule<scanner> phrase_start;
124 cl::rule<scanner> nested_phrase;
125 cl::rule<scanner> inline_phrase;
126 cl::rule<scanner> paragraph_phrase;
127 cl::rule<scanner> extended_phrase;
128 cl::rule<scanner> table_title_phrase;
129 cl::rule<scanner> inside_preformatted;
130 cl::rule<scanner> inside_paragraph;
131 cl::rule<scanner> command_line;
132 cl::rule<scanner> attribute_template_body;
133 cl::rule<scanner> attribute_value_1_7;
134 cl::rule<scanner> escape;
135 cl::rule<scanner> raw_escape;
136 cl::rule<scanner> skip_entity;
138 // Miscellaneous stuff
139 cl::rule<scanner> hard_space;
140 cl::rule<scanner> space;
141 cl::rule<scanner> blank;
142 cl::rule<scanner> eol;
143 cl::rule<scanner> phrase_end;
144 cl::rule<scanner> comment;
145 cl::rule<scanner> line_comment;
146 cl::rule<scanner> macro_identifier;
149 cl::symbols<element_info> elements;
152 cl::symbols<source_mode_type> source_modes;
155 cl::rule<scanner> doc_info_details;
157 impl(quickbook::state&);
162 void init_block_elements();
163 void init_phrase_elements();
164 void init_doc_info();
168 #endif // BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP