mirror of
https://github.com/boostorg/quickbook.git
synced 2026-02-02 21:12:15 +00:00
Fixes #1399 Merged revisions 49231,49459,49988,50068,50084,50091,50109,50125,50142,50159,50163,50175,50193,50207,50210-50213,50215,50222,50246,50513 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r49231 | danieljames | 2008-10-09 23:14:14 +0100 (Thu, 09 Oct 2008) | 4 lines Work around the problems with window newlines in position_iterator. (I'm about to fix them, but this will get quickbook working immediately). ........ r49459 | eric_niebler | 2008-10-26 20:24:59 +0000 (Sun, 26 Oct 2008) | 1 line give data members with <purpose> in synopses the same treatment as functions and typedefs ........ r49988 | danieljames | 2008-11-28 15:05:21 +0000 (Fri, 28 Nov 2008) | 1 line When processing template arguments, deal with the case when there's no content after the last space or there are more arguments than expected. ........ r50068 | johnmaddock | 2008-12-02 13:13:57 +0000 (Tue, 02 Dec 2008) | 1 line Fix Jamfile by adding <preserve-test-targets>on to test requirements. ........ r50084 | johnmaddock | 2008-12-03 09:42:52 +0000 (Wed, 03 Dec 2008) | 1 line Added quickbook-fail-test rule and two tests that make use of it: note that these currently fail. ........ r50091 | danieljames | 2008-12-03 19:14:42 +0000 (Wed, 03 Dec 2008) | 2 lines Keep a count of errors in quickbook, and return an error code when appropriate. ........ r50109 | johnmaddock | 2008-12-04 10:14:19 +0000 (Thu, 04 Dec 2008) | 1 line Added dependency to the test file. ........ r50125 | djowel | 2008-12-05 02:13:59 +0000 (Fri, 05 Dec 2008) | 1 line updated to use "classic" spirit includes and namespace ........ r50142 | danieljames | 2008-12-05 19:03:19 +0000 (Fri, 05 Dec 2008) | 1 line Defined BOOST_CYGWIN_PATH when building quickbook on cygwin. ........ r50159 | danieljames | 2008-12-06 14:07:35 +0000 (Sat, 06 Dec 2008) | 1 line Copy boostbook.dtd into the correct position for the 1.1 uri. I'm not sure what should be done with the existing location. ........ r50163 | danieljames | 2008-12-06 19:22:32 +0000 (Sat, 06 Dec 2008) | 1 line Revert my change to the quickbook jamfile, it isn't adequately tested. ........ r50175 | danieljames | 2008-12-07 12:37:07 +0000 (Sun, 07 Dec 2008) | 1 line Fix processing of unmatched escape characters in code - and issue a warning for unexpected characters. ........ r50193 | danieljames | 2008-12-08 16:17:13 +0000 (Mon, 08 Dec 2008) | 1 line Use new include paths for classic spirit in quickbook text_diff utility. ........ r50207 | danieljames | 2008-12-08 21:51:56 +0000 (Mon, 08 Dec 2008) | 1 line Fail on a mismatched '' in the python and c++ syntax highlighters. And then ignore the rest of the code block to avoid further errors and warnings. ........ r50210 | danieljames | 2008-12-08 23:14:23 +0000 (Mon, 08 Dec 2008) | 1 line Hard fail on quickbook post process errors. ........ r50211 | danieljames | 2008-12-08 23:20:26 +0000 (Mon, 08 Dec 2008) | 1 line Since I accidently added a quickbook fail tests to the Jamfile in the last checkin, I might as well add them. ........ r50212 | danieljames | 2008-12-08 23:35:08 +0000 (Mon, 08 Dec 2008) | 1 line Remove an unused variable in order to avoid a gcc warning. ........ r50213 | danieljames | 2008-12-08 23:35:20 +0000 (Mon, 08 Dec 2008) | 1 line Run the docbook chunker quietly, unless boostbook.verbose is set. ........ r50215 | danieljames | 2008-12-08 23:38:29 +0000 (Mon, 08 Dec 2008) | 1 line Put the markup strings in their own cpp file to avoid gcc warnings. ........ r50222 | danieljames | 2008-12-09 13:52:07 +0000 (Tue, 09 Dec 2008) | 1 line Fix some xsl type errors. ........ r50246 | speedsnail | 2008-12-12 15:06:44 +0000 (Fri, 12 Dec 2008) | 1 line Make doxygen command "\throw" work with boostbook. ........ r50513 | danieljames | 2009-01-08 12:01:50 +0000 (Thu, 08 Jan 2009) | 1 line Support both windows and cygwin paths in cygwin quickbook. ........ [SVN r51281]
439 lines
16 KiB
C++
439 lines
16 KiB
C++
/*=============================================================================
|
|
Copyright (c) 2002 2004 2006Joel de Guzman
|
|
Copyright (c) 2004 Eric Niebler
|
|
http://spirit.sourceforge.net/
|
|
|
|
Use, modification and distribution is subject to the Boost Software
|
|
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
http://www.boost.org/LICENSE_1_0.txt)
|
|
=============================================================================*/
|
|
#if !defined(BOOST_SPIRIT_QUICKBOOK_BLOCK_HPP)
|
|
#define BOOST_SPIRIT_QUICKBOOK_BLOCK_HPP
|
|
|
|
#include "./detail/utils.hpp"
|
|
#include "./phrase.hpp"
|
|
#include <boost/spirit/include/classic_core.hpp>
|
|
#include <boost/spirit/include/classic_confix.hpp>
|
|
#include <boost/spirit/include/classic_chset.hpp>
|
|
#include <boost/spirit/include/classic_assign_actor.hpp>
|
|
#include <boost/spirit/include/classic_if.hpp>
|
|
#include <boost/spirit/include/classic_symbols.hpp>
|
|
|
|
namespace quickbook
|
|
{
|
|
using namespace boost::spirit::classic;
|
|
|
|
template <typename Actions, bool skip_initial_spaces = false>
|
|
struct block_grammar : grammar<block_grammar<Actions> >
|
|
{
|
|
block_grammar(Actions& actions_)
|
|
: actions(actions_) {}
|
|
|
|
template <typename Scanner>
|
|
struct definition
|
|
{
|
|
definition(block_grammar const& self)
|
|
: no_eols(true)
|
|
, common(self.actions, no_eols)
|
|
{
|
|
using detail::var;
|
|
Actions& actions = self.actions;
|
|
|
|
if (skip_initial_spaces)
|
|
{
|
|
start_ =
|
|
*(space_p | comment) >> blocks >> blank
|
|
;
|
|
}
|
|
else
|
|
{
|
|
start_ =
|
|
blocks >> blank
|
|
;
|
|
}
|
|
|
|
blocks =
|
|
+( block_markup
|
|
| code
|
|
| list [actions.list]
|
|
| hr [actions.hr]
|
|
| comment >> *eol
|
|
| paragraph [actions.paragraph]
|
|
| eol
|
|
)
|
|
;
|
|
|
|
space =
|
|
*(space_p | comment)
|
|
;
|
|
|
|
blank =
|
|
*(blank_p | comment)
|
|
;
|
|
|
|
eol = blank >> eol_p
|
|
;
|
|
|
|
phrase_end =
|
|
']' |
|
|
if_p(var(no_eols))
|
|
[
|
|
eol >> eol // Make sure that we don't go
|
|
] // past a single block, except
|
|
; // when preformatted.
|
|
|
|
hard_space =
|
|
(eps_p - (alnum_p | '_')) >> space // must not be preceded by
|
|
; // alpha-numeric or underscore
|
|
|
|
comment =
|
|
"[/" >> *(dummy_block | (anychar_p - ']')) >> ']'
|
|
;
|
|
|
|
dummy_block =
|
|
'[' >> *(dummy_block | (anychar_p - ']')) >> ']'
|
|
;
|
|
|
|
hr =
|
|
str_p("----")
|
|
>> *(anychar_p - eol)
|
|
>> +eol
|
|
;
|
|
|
|
block_markup =
|
|
'[' >> space
|
|
>> ( begin_section
|
|
| end_section
|
|
| headings
|
|
| blurb
|
|
| blockquote
|
|
| admonition
|
|
| preformatted
|
|
| def_macro
|
|
| table
|
|
| variablelist
|
|
| xinclude
|
|
| include
|
|
| import
|
|
| template_
|
|
)
|
|
>> ( (space >> ']' >> +eol)
|
|
| eps_p [actions.error]
|
|
)
|
|
;
|
|
|
|
begin_section =
|
|
"section"
|
|
>> hard_space
|
|
>> (':' >> (*(alnum_p | '_')) [assign_a(actions.section_id)]
|
|
| eps_p [assign_a(actions.section_id)]
|
|
)
|
|
>> phrase [actions.begin_section]
|
|
;
|
|
|
|
end_section =
|
|
str_p("endsect") [actions.end_section]
|
|
;
|
|
|
|
headings =
|
|
h1 | h2 | h3 | h4 | h5 | h6 | h
|
|
;
|
|
|
|
h = "heading" >> hard_space >> phrase [actions.h];
|
|
h1 = "h1" >> hard_space >> phrase [actions.h1];
|
|
h2 = "h2" >> hard_space >> phrase [actions.h2];
|
|
h3 = "h3" >> hard_space >> phrase [actions.h3];
|
|
h4 = "h4" >> hard_space >> phrase [actions.h4];
|
|
h5 = "h5" >> hard_space >> phrase [actions.h5];
|
|
h6 = "h6" >> hard_space >> phrase [actions.h6];
|
|
|
|
static const bool true_ = true;
|
|
static const bool false_ = false;
|
|
|
|
inside_paragraph =
|
|
phrase [actions.inside_paragraph]
|
|
>> *(
|
|
eol >> eol >> phrase [actions.inside_paragraph]
|
|
)
|
|
;
|
|
|
|
blurb =
|
|
"blurb" >> hard_space
|
|
>> inside_paragraph [actions.blurb]
|
|
>> eps_p
|
|
;
|
|
|
|
blockquote =
|
|
':' >> blank >>
|
|
inside_paragraph [actions.blockquote]
|
|
;
|
|
|
|
admonition =
|
|
"warning" >> blank >>
|
|
inside_paragraph [actions.warning]
|
|
|
|
|
"caution" >> blank >>
|
|
inside_paragraph [actions.caution]
|
|
|
|
|
"important" >> blank >>
|
|
inside_paragraph [actions.important]
|
|
|
|
|
"note" >> blank >>
|
|
inside_paragraph [actions.note]
|
|
|
|
|
"tip" >> blank >>
|
|
inside_paragraph [actions.tip]
|
|
;
|
|
|
|
preformatted =
|
|
"pre" >> hard_space [assign_a(no_eols, false_)]
|
|
>> !eol >> phrase [actions.preformatted]
|
|
>> eps_p [assign_a(no_eols, true_)]
|
|
;
|
|
|
|
macro_identifier =
|
|
+(anychar_p - (space_p | ']'))
|
|
;
|
|
|
|
def_macro =
|
|
"def" >> hard_space
|
|
>> macro_identifier [actions.macro_identifier]
|
|
>> blank >> phrase [actions.macro_definition]
|
|
;
|
|
|
|
identifier =
|
|
(alpha_p | '_') >> *(alnum_p | '_')
|
|
;
|
|
|
|
template_id =
|
|
identifier | (punct_p - (ch_p('[') | ']'))
|
|
;
|
|
|
|
template_ =
|
|
"template"
|
|
>> hard_space >> template_id [push_back_a(actions.template_info)]
|
|
>>
|
|
!(
|
|
space >> '['
|
|
>> *(
|
|
space >> template_id [push_back_a(actions.template_info)]
|
|
)
|
|
>> space >> ']'
|
|
)
|
|
>> template_body [actions.template_body]
|
|
;
|
|
|
|
template_body =
|
|
*(('[' >> template_body >> ']') | (anychar_p - ']'))
|
|
>> space >> eps_p(']')
|
|
;
|
|
|
|
variablelist =
|
|
"variablelist"
|
|
>> (eps_p(*blank_p >> eol_p) | hard_space)
|
|
>> (*(anychar_p - eol)) [assign_a(actions.table_title)]
|
|
>> +eol
|
|
>> *varlistentry
|
|
>> eps_p [actions.variablelist]
|
|
;
|
|
|
|
varlistentry =
|
|
space
|
|
>> ch_p('[') [actions.start_varlistentry]
|
|
>>
|
|
(
|
|
(
|
|
varlistterm
|
|
>> +varlistitem
|
|
>> ch_p(']') [actions.end_varlistentry]
|
|
>> space
|
|
)
|
|
| eps_p [actions.error]
|
|
)
|
|
;
|
|
|
|
varlistterm =
|
|
space
|
|
>> ch_p('[') [actions.start_varlistterm]
|
|
>>
|
|
(
|
|
(
|
|
phrase
|
|
>> ch_p(']') [actions.end_varlistterm]
|
|
>> space
|
|
)
|
|
| eps_p [actions.error]
|
|
)
|
|
;
|
|
|
|
varlistitem =
|
|
space
|
|
>> ch_p('[') [actions.start_varlistitem]
|
|
>>
|
|
(
|
|
(
|
|
inside_paragraph
|
|
>> ch_p(']') [actions.end_varlistitem]
|
|
>> space
|
|
)
|
|
| eps_p [actions.error]
|
|
)
|
|
;
|
|
|
|
table =
|
|
"table"
|
|
>> (eps_p(*blank_p >> eol_p) | hard_space)
|
|
>> (*(anychar_p - eol)) [assign_a(actions.table_title)]
|
|
>> +eol
|
|
>> *table_row
|
|
>> eps_p [actions.table]
|
|
;
|
|
|
|
table_row =
|
|
space
|
|
>> ch_p('[') [actions.start_row]
|
|
>>
|
|
(
|
|
(
|
|
*table_cell
|
|
>> ch_p(']') [actions.end_row]
|
|
>> space
|
|
)
|
|
| eps_p [actions.error]
|
|
)
|
|
;
|
|
|
|
table_cell =
|
|
space
|
|
>> ch_p('[') [actions.start_cell]
|
|
>>
|
|
(
|
|
(
|
|
inside_paragraph
|
|
>> ch_p(']') [actions.end_cell]
|
|
>> space
|
|
)
|
|
| eps_p [actions.error]
|
|
)
|
|
;
|
|
|
|
xinclude =
|
|
"xinclude"
|
|
>> hard_space
|
|
>> (*(anychar_p -
|
|
phrase_end)) [actions.xinclude]
|
|
;
|
|
|
|
import =
|
|
"import"
|
|
>> hard_space
|
|
>> (*(anychar_p -
|
|
phrase_end)) [actions.import]
|
|
;
|
|
|
|
include =
|
|
"include"
|
|
>> hard_space
|
|
>>
|
|
!(
|
|
':'
|
|
>> (*((alnum_p | '_') - space_p))[assign_a(actions.include_doc_id)]
|
|
>> space
|
|
)
|
|
>> (*(anychar_p -
|
|
phrase_end)) [actions.include]
|
|
;
|
|
|
|
code =
|
|
(
|
|
code_line
|
|
>> *(*eol >> code_line)
|
|
) [actions.code]
|
|
>> +eol
|
|
;
|
|
|
|
code_line =
|
|
((ch_p(' ') | '\t'))
|
|
>> *(anychar_p - eol) >> eol
|
|
;
|
|
|
|
list =
|
|
eps_p(ch_p('*') | '#') >>
|
|
+(
|
|
(*blank_p
|
|
>> (ch_p('*') | '#')) [actions.list_format]
|
|
>> *blank_p
|
|
>> list_item
|
|
) [actions.list_item]
|
|
;
|
|
|
|
list_item =
|
|
*( common
|
|
| (anychar_p -
|
|
( eol_p >> *blank_p >> eps_p(ch_p('*') | '#')
|
|
| (eol >> eol)
|
|
)
|
|
) [actions.plain_char]
|
|
)
|
|
>> +eol
|
|
;
|
|
|
|
paragraph_end_markups =
|
|
"section", "endsect", "h1", "h2", "h3", "h4", "h5", "h6",
|
|
"blurb", ":", "pre", "def", "table", "include", "xinclude",
|
|
"variablelist", "import", "template", "warning", "caution",
|
|
"important", "note", "tip", ":"
|
|
;
|
|
|
|
paragraph_end =
|
|
'[' >> space >> paragraph_end_markups >> hard_space | eol >> eol
|
|
;
|
|
|
|
paragraph =
|
|
*( common
|
|
| (anychar_p - // Make sure we don't go past
|
|
paragraph_end // a single block.
|
|
) [actions.plain_char]
|
|
)
|
|
>> (eps_p('[') | +eol)
|
|
;
|
|
|
|
phrase =
|
|
*( common
|
|
| comment
|
|
| (anychar_p -
|
|
phrase_end) [actions.plain_char]
|
|
)
|
|
;
|
|
}
|
|
|
|
bool no_eols;
|
|
|
|
rule<Scanner> start_, blocks, block_markup, code, code_line,
|
|
paragraph, space, blank, comment, headings, h, h1, h2,
|
|
h3, h4, h5, h6, hr, blurb, blockquote, admonition,
|
|
phrase, list, phrase_end, ordered_list, def_macro,
|
|
macro_identifier, table, table_row, variablelist,
|
|
varlistentry, varlistterm, varlistitem, table_cell,
|
|
preformatted, list_item, begin_section, end_section,
|
|
xinclude, include, hard_space, eol, paragraph_end,
|
|
template_, template_id, template_formal_arg,
|
|
template_body, identifier, dummy_block, import,
|
|
inside_paragraph;
|
|
|
|
symbols<> paragraph_end_markups;
|
|
|
|
phrase_grammar<Actions> common;
|
|
|
|
rule<Scanner> const&
|
|
start() const { return start_; }
|
|
};
|
|
|
|
Actions& actions;
|
|
};
|
|
}
|
|
|
|
#endif // BOOST_SPIRIT_QUICKBOOK_BLOCK_HPP
|
|
|
|
|