From d8b487499beb8a854ce36d8b6b044de7d361edb4 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 16 May 2013 21:30:01 +0000 Subject: [PATCH] Merge quickbook to release. [SVN r84300] --- doc/1_6.qbk | 25 ++- doc/change_log.qbk | 13 ++ src/block_element_grammar.cpp | 5 +- src/dependency_tracker.cpp | 65 +++++- src/dependency_tracker.hpp | 9 +- src/doc_info_grammar.cpp | 20 +- src/files.cpp | 210 ++++++++++++------ src/grammar_impl.hpp | 1 + src/main_grammar.cpp | 90 +++++++- src/quickbook.cpp | 134 ++++++++--- src/syntax_highlight.cpp | 54 +++-- test/code_cpp-1_5.gold | 15 +- test/code_cpp-1_5.quickbook | 12 + test/doc-info/Jamfile.v2 | 2 + test/doc-info/macros1-1_5.gold | 11 + test/doc-info/macros1-1_5.quickbook | 6 + test/doc-info/macros1-1_6.gold | 8 + test/doc-info/macros1-1_6.quickbook | 7 + test/doc-info/macros1-inc_1_6.quickbook | 4 + test/{empty.qbk => empty-inc.quickbook} | 0 test/include-1_5.quickbook | 14 +- test/include-1_6.quickbook | 10 +- ..._sub-1_5.qbk => include-inc-1_5.quickbook} | 0 ...{include_sub.qbk => include-inc.quickbook} | 0 test/include/compatibility-1_1.quickbook | 8 +- test/include/compatibility-1_5.quickbook | 8 +- test/include/compatibility-1_6.quickbook | 8 +- ...ty-inc.qbk => compatibility-inc.quickbook} | 0 ..._1.qbk => compatibility-inc_1_1.quickbook} | 0 ..._5.qbk => compatibility-inc_1_5.quickbook} | 0 ..._6.qbk => compatibility-inc_1_6.quickbook} | 0 test/include/in_section-1_5.quickbook | 12 +- test/include/in_section-1_6.quickbook | 12 +- ...include1.qbk => in_section-inc1.quickbook} | 0 ...include2.qbk => in_section-inc2.quickbook} | 0 .../include_id_unbalanced-1_6.quickbook | 4 +- ...k => include_id_unbalanced-inc1.quickbook} | 2 +- ... => include_id_unbalanced-inc1a.quickbook} | 0 ...k => include_id_unbalanced-inc2.quickbook} | 2 +- ... => include_id_unbalanced-inc2a.quickbook} | 0 .../nested_compatibility-1_5.quickbook | 8 +- .../nested_compatibility-1_6.quickbook | 8 +- ...=> nested_compatibility-inc-1_5.quickbook} | 0 ...=> nested_compatibility-inc-1_6.quickbook} | 0 test/include/source_mode-1_5.quickbook | 2 +- test/include/source_mode-1_6.quickbook | 2 +- ...de-inc1.qbk => source_mode-inc1.quickbook} | 0 test/include2-1_6.quickbook | 6 +- test/include_win_path-1_6-fail.quickbook | 2 +- test/python/include_path.qbk | 8 + test/python/missing_relative.qbk | 8 + test/python/sub1/a.qbk | 8 + test/python/sub2/b.qbk | 8 + test/python/svg_missing.qbk | 8 + test/snippets/unbalanced_snippet1.cpp | 2 +- test/snippets/unbalanced_snippet2.cpp | 2 +- test/unit/source_map_test.cpp | 79 +++++++ test/versions/invalid_macro-1_6.quickbook | 4 +- ..._1.qbk => invalid_macro-inc-1_1.quickbook} | 0 ...es-1_1.qbk => templates-inc-1_1.quickbook} | 0 ...es-1_4.qbk => templates-inc-1_4.quickbook} | 0 ...es-1_5.qbk => templates-inc-1_5.quickbook} | 0 test/versions/versions-1_6.quickbook | 12 +- 63 files changed, 726 insertions(+), 212 deletions(-) create mode 100644 test/doc-info/macros1-1_5.gold create mode 100644 test/doc-info/macros1-1_5.quickbook create mode 100644 test/doc-info/macros1-1_6.gold create mode 100644 test/doc-info/macros1-1_6.quickbook create mode 100644 test/doc-info/macros1-inc_1_6.quickbook rename test/{empty.qbk => empty-inc.quickbook} (100%) rename test/{include_sub-1_5.qbk => include-inc-1_5.quickbook} (100%) rename test/{include_sub.qbk => include-inc.quickbook} (100%) rename test/include/{compatibility-inc.qbk => compatibility-inc.quickbook} (100%) rename test/include/{compatibility-inc_1_1.qbk => compatibility-inc_1_1.quickbook} (100%) rename test/include/{compatibility-inc_1_5.qbk => compatibility-inc_1_5.quickbook} (100%) rename test/include/{compatibility-inc_1_6.qbk => compatibility-inc_1_6.quickbook} (100%) rename test/include/{in_section-include1.qbk => in_section-inc1.quickbook} (100%) rename test/include/{in_section-include2.qbk => in_section-inc2.quickbook} (100%) rename test/include/{include_id_unbalanced-inc1.qbk => include_id_unbalanced-inc1.quickbook} (57%) rename test/include/{include_id_unbalanced-inc1a.qbk => include_id_unbalanced-inc1a.quickbook} (100%) rename test/include/{include_id_unbalanced-inc2.qbk => include_id_unbalanced-inc2.quickbook} (61%) rename test/include/{include_id_unbalanced-inc2a.qbk => include_id_unbalanced-inc2a.quickbook} (100%) rename test/include/{nested_compatibility_inc-1_5.qbk => nested_compatibility-inc-1_5.quickbook} (100%) rename test/include/{nested_compatibility_inc-1_6.qbk => nested_compatibility-inc-1_6.quickbook} (100%) rename test/include/{source_mode-inc1.qbk => source_mode-inc1.quickbook} (100%) rename test/versions/{invalid_macro-inc-1_1.qbk => invalid_macro-inc-1_1.quickbook} (100%) rename test/versions/{templates-1_1.qbk => templates-inc-1_1.quickbook} (100%) rename test/versions/{templates-1_4.qbk => templates-inc-1_4.quickbook} (100%) rename test/versions/{templates-1_5.qbk => templates-inc-1_5.quickbook} (100%) diff --git a/doc/1_6.qbk b/doc/1_6.qbk index e9ce035..eac1ea2 100644 --- a/doc/1_6.qbk +++ b/doc/1_6.qbk @@ -70,6 +70,19 @@ before. [endsect] [/docinfo] +[section:doc-info-macros Macros in docinfo block] + +You can now expand macros in text fields in the docinfo block. In the top +docinfo block only the predefined macros are available, but in nested documents +macros defined in the parent document are also available. + +There's a small bug here - this leaks into older versions for the `license` +and `purpose` fields, but since only the predefined macros are available, it's +unlikely to break any existing documents. So I'd rather not complicate the code +further by fixing that. + +[endsect] + [section:scope Scoping templates and macros] A long standing quickbook bug is that macros are scoped by file, but templates @@ -241,8 +254,13 @@ if you're totally sure that you will need it. so that they aren't wrapped in paragraph tags. The main use is for escaped docbook block tags, such as: - [template chapter[title] [block''''''[title]'''''']] - [template chapterend [block'''''']] + [template chapter[title] + [block''''''[title]''''''] + ] + + [template chapterend + [block''''''] + ] [chapter An example chapter] @@ -253,6 +271,9 @@ for escaped docbook block tags, such as: Without the `block` element, the `chapter` and `chapterend` templates would be wrapped in paragraph tags. +[note In this example, the template body has to start with a newline so that +the template will be interpreted in block mode.] + [endsect] [section:lists `ordered_list` and `itemized_list`] diff --git a/doc/change_log.qbk b/doc/change_log.qbk index aacd813..77413eb 100644 --- a/doc/change_log.qbk +++ b/doc/change_log.qbk @@ -279,6 +279,19 @@ Boost 1.46.1: * When code blocks are indented using a mixture of tabs and spaces, convert indentation to spaces. +* In the C++ systax highlighter, fix syntax highlighting for `#`, so that it's + used for preprocessor statements at the start of a line, and as a 'special' + character elsewhere + ([@https://svn.boost.org/trac/boost/ticket/8510 #8510], + [@https://svn.boost.org/trac/boost/ticket/8511 #8511]). +* Add C++11 keywords to syntax highlighter + ([@https://svn.boost.org/trac/boost/ticket/8541 #8541]). +* Hidden options for formatting of `--output-deps`. Not really for public use +* yet. +* 1.6 changes: + * Better template argument parsing, so that it understands things + like escaped markup. + * Support for using macros in the doc info block. * Internal changes: * Convert to use `boost::string_ref`. * Clean up the source map implementation (used to get the correct diff --git a/src/block_element_grammar.cpp b/src/block_element_grammar.cpp index 1f5d5da..1d998b9 100644 --- a/src/block_element_grammar.cpp +++ b/src/block_element_grammar.cpp @@ -169,7 +169,10 @@ namespace quickbook ; local.template_body = - *(('[' >> local.template_body >> ']') | (cl::anychar_p - ']')) + qbk_ver(106u) + >> *(~cl::eps_p(']') >> skip_entity) + | qbk_ver(0,106u) + >> *(('[' >> local.template_body >> ']') | (cl::anychar_p - ']')) >> cl::eps_p(space >> ']') >> space ; diff --git a/src/dependency_tracker.cpp b/src/dependency_tracker.cpp index 53d24d2..ff28198 100644 --- a/src/dependency_tracker.cpp +++ b/src/dependency_tracker.cpp @@ -56,28 +56,69 @@ namespace quickbook return fs::canonical(p) / extra; } + static char const* control_escapes[16] = { + "\\000", "\\001", "\\002", "\\003", + "\\004", "\\005", "\\006", "\\a", + "\\b", "\\t", "\\n", "\\v", + "\\f", "\\r", "\\016", "\\017" + }; + + static std::string escaped_path(std::string const& generic) + { + std::string result; + result.reserve(generic.size()); + + BOOST_FOREACH(char c, generic) + { + if (c >= 0 && c < 16) { + result += control_escapes[(unsigned int) c]; + } + else if (c == '\\') { + result += "\\\\"; + } + else if (c == 127) { + result += "\\177"; + } + else { + result += c; + } + } + + return result; + } + + static std::string get_path(fs::path const& path, + dependency_tracker::flags f) + { + std::string generic = detail::path_to_generic(path); + + if (f & dependency_tracker::escaped) { + generic = escaped_path(generic); + } + + return generic; + } + bool dependency_tracker::add_dependency(fs::path const& f) { bool found = fs::exists(fs::status(f)); dependencies[normalize_path(f)] |= found; return found; } - void dependency_tracker::write_dependencies(std::ostream& out) + void dependency_tracker::write_dependencies(std::ostream& out, + flags f) { BOOST_FOREACH(dependency_list::value_type const& d, dependencies) { - if (d.second) { - out << detail::path_to_generic(d.first) << std::endl; + if (f & checked) { + out << (d.second ? "+ " : "- ") + << get_path(d.first, f) << std::endl; + } + else { + if (d.second) { + out << get_path(d.first, f) << std::endl; + } } } } - - void dependency_tracker::write_checked_locations(std::ostream& out) - { - BOOST_FOREACH(dependency_list::value_type const& d, dependencies) - { - out << (d.second ? "+ " : "- ") - << detail::path_to_generic(d.first) << std::endl; - } - } } diff --git a/src/dependency_tracker.hpp b/src/dependency_tracker.hpp index bbf991c..6b477b9 100644 --- a/src/dependency_tracker.hpp +++ b/src/dependency_tracker.hpp @@ -25,12 +25,17 @@ namespace quickbook public: + enum flags { + default_ = 0, + checked = 1, + escaped = 2 + }; + // Call this before loading any file so that it will be included in the // list of dependencies. Returns true if file exists. bool add_dependency(fs::path const&); - void write_dependencies(std::ostream&); - void write_checked_locations(std::ostream&); + void write_dependencies(std::ostream&, flags = default_); }; } diff --git a/src/doc_info_grammar.cpp b/src/doc_info_grammar.cpp index 862d0ce..563efc3 100644 --- a/src/doc_info_grammar.cpp +++ b/src/doc_info_grammar.cpp @@ -75,7 +75,7 @@ namespace quickbook doc_authors, doc_author, doc_copyright, doc_copyright_holder, doc_source_mode, doc_biblioid, doc_compatibility_mode, - quickbook_version, char_; + quickbook_version, macro, char_; cl::uint_parser doc_copyright_year; cl::symbols<> doc_types; cl::symbols doc_info_attributes; @@ -119,6 +119,7 @@ namespace quickbook // Actions error_action error(state); plain_char_action plain_char(state.phrase, state); + do_macro_action do_macro(state.phrase, state); scoped_parser to_value(state); doc_info_details = @@ -302,6 +303,21 @@ namespace quickbook local.attribute_rules[doc_info_attributes::biblioid] = &local.doc_biblioid; - local.char_ = escape | cl::anychar_p[plain_char]; + local.char_ = + escape + | local.macro + | cl::anychar_p[plain_char]; + ; + + local.macro = + cl::eps_p + ( ( state.macro + >> ~cl::eps_p(cl::alpha_p | '_') + // must not be followed by alpha or underscore + ) + & macro_identifier // must be a valid macro for the current version + ) + >> state.macro [do_macro] + ; } } diff --git a/src/files.cpp b/src/files.cpp index fddd3b1..97c67c2 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -195,15 +195,13 @@ namespace quickbook std::string::size_type original_pos; std::string::size_type our_pos; section_types section_type; - int indentation; mapped_file_section( std::string::size_type original_pos, std::string::size_type our_pos, - section_types section_type = normal, - int indentation = 0) : + section_types section_type = normal) : original_pos(original_pos), our_pos(our_pos), - section_type(section_type), indentation(indentation) {} + section_type(section_type) {} }; struct mapped_section_original_cmp @@ -278,12 +276,11 @@ namespace quickbook pos - original->source().begin(), source().size())); } - void add_indented_mapped_file_section(boost::string_ref::const_iterator pos, - int indentation) + void add_indented_mapped_file_section(boost::string_ref::const_iterator pos) { mapped_sections.push_back(mapped_file_section( pos - original->source().begin(), source().size(), - mapped_file_section::indented, indentation)); + mapped_file_section::indented)); } std::string::size_type to_original_pos( @@ -293,10 +290,16 @@ namespace quickbook switch (section->section_type) { case mapped_file_section::normal: return pos - section->our_pos + section->original_pos; + case mapped_file_section::empty: return section->original_pos; + case mapped_file_section::indented: { + // Will contain the start of the current line. boost::string_ref::size_type our_line = section->our_pos; + + // Will contain the number of lines in the block before + // the current line. unsigned newline_count = 0; for(boost::string_ref::size_type i = section->our_pos; @@ -307,10 +310,8 @@ namespace quickbook ++newline_count; } } - - if (newline_count == 0) - return pos - section->our_pos + section->original_pos; + // The start of the line in the original source. boost::string_ref::size_type original_line = section->original_pos; @@ -319,18 +320,23 @@ namespace quickbook --newline_count; ++original_line; } - - for(unsigned i = section->indentation; i > 0; --i) { - if (original->source()[original_line] == '\n' || - original->source()[original_line] == '\0') break; - assert(original->source()[original_line] == ' ' || - original->source()[original_line] == '\t'); - ++original_line; - } - + + // The start of line content (i.e. after indentation). + our_line = skip_indentation(source(), our_line); + + // The position is in the middle of indentation, so + // just return the start of the whitespace, which should + // be good enough. + if (our_line > pos) return original_line; + + original_line = + skip_indentation(original->source(), original_line); + + // Confirm that we are actually in the same position. assert(original->source()[original_line] == source()[our_line]); + // Calculate the position return original_line + (pos - our_line); } default: @@ -353,6 +359,16 @@ namespace quickbook } virtual file_position position_of(boost::string_ref::const_iterator) const; + + private: + + static std::string::size_type skip_indentation( + boost::string_ref src, std::string::size_type i) + { + while (i != src.size() && (src[i] == ' ' || src[i] == '\t')) ++i; + return i; + } + }; namespace { @@ -436,14 +452,14 @@ namespace quickbook data->new_file->mapped_sections.push_back(mapped_file_section( x.data->new_file->to_original_pos(start, begin), - size, start->section_type, start->indentation)); + size, start->section_type)); for (++start; start != x.data->new_file->mapped_sections.end() && start->our_pos < end; ++start) { data->new_file->mapped_sections.push_back(mapped_file_section( start->original_pos, start->our_pos - begin + size, - start->section_type, start->indentation)); + start->section_type)); } data->new_file->source_.append( @@ -452,68 +468,130 @@ namespace quickbook } } + boost::string_ref::size_type indentation_count(boost::string_ref x) + { + unsigned count = 0; + + for(boost::string_ref::const_iterator begin = x.begin(), end = x.end(); + begin != end; ++begin) + { + switch(*begin) + { + case ' ': + ++count; + break; + case '\t': + // hardcoded tab to 4 for now + count = count - (count % 4) + 4; + break; + default: + assert(false); + } + } + + return count; + } + void mapped_file_builder::unindent_and_add(boost::string_ref x) { - std::string program(x.begin(), x.end()); + // I wanted to do everything using a string_ref, but unfortunately + // they don't have all the overloads used in here. So... + std::string const program(x.begin(), x.end()); // Erase leading blank lines and newlines: std::string::size_type start = program.find_first_not_of(" \t\r\n"); if (start == std::string::npos) return; start = program.find_last_of("\r\n", start); - if (start != std::string::npos) - { - ++start; - program.erase(0, start); - } + start = start == std::string::npos ? 0 : start + 1; - assert(program.size() != 0); + assert(start < program.size()); - // Get the first line indent - std::string::size_type indent = program.find_first_not_of(" \t"); - std::string::size_type pos = 0; - if (std::string::npos == indent) - { - // Nothing left to do here. The code is empty (just spaces). - // We clear the program to signal the caller that it is empty - // and return early. - program.clear(); - return; - } + // Get the first line indentation + std::string::size_type indent = program.find_first_not_of(" \t", start) - start; + boost::string_ref::size_type full_indent = indentation_count( + boost::string_ref(&program[start], indent)); + + std::string::size_type pos = start; // Calculate the minimum indent from the rest of the lines - do - { - pos = program.find_first_not_of("\r\n", pos); - if (std::string::npos == pos) - break; - - std::string::size_type n = program.find_first_not_of(" \t", pos); - if (n != std::string::npos) - { - char ch = program[n]; - if (ch != '\r' && ch != '\n') // ignore empty lines - indent = (std::min)(indent, n-pos); - } - } - while (std::string::npos != (pos = program.find_first_of("\r\n", pos))); - - // Trim white spaces from column 0..indent - pos = 0; - program.erase(0, indent); + // Detecting a mix of spaces and tabs. while (std::string::npos != (pos = program.find_first_of("\r\n", pos))) { - if (std::string::npos == (pos = program.find_first_not_of("\r\n", pos))) - { - break; - } + pos = program.find_first_not_of("\r\n", pos); + if (std::string::npos == pos) break; - std::string::size_type next = program.find_first_of("\r\n", pos); - program.erase(pos, (std::min)(indent, next-pos)); + std::string::size_type n = program.find_first_not_of(" \t", pos); + if (n == std::string::npos) break; + + char ch = program[n]; + if (ch == '\r' || ch == '\n') continue; // ignore empty lines + + indent = (std::min)(indent, n-pos); + full_indent = (std::min)(full_indent, indentation_count( + boost::string_ref(&program[pos], n-pos))); } - data->new_file->add_indented_mapped_file_section(x.begin() + indent, indent); - data->new_file->source_.append(program); + // Detect if indentation is mixed. + bool mixed_indentation = false; + boost::string_ref first_indent(&program[start], indent); + pos = start; + + while (std::string::npos != (pos = program.find_first_of("\r\n", pos))) + { + pos = program.find_first_not_of("\r\n", pos); + if (std::string::npos == pos) break; + + std::string::size_type n = program.find_first_not_of(" \t", pos); + if (n == std::string::npos || n-pos < indent) continue; + + if (boost::string_ref(&program[pos], indent) != first_indent) { + mixed_indentation = true; + break; + } + } + + // Trim white spaces from column 0..indent + std::string unindented_program; + std::string::size_type copy_start = start; + pos = start; + + do { + if (std::string::npos == (pos = program.find_first_not_of("\r\n", pos))) + break; + + unindented_program.append(program.begin() + copy_start, program.begin() + pos); + copy_start = pos; + + // Find the end of the indentation. + std::string::size_type next = program.find_first_not_of(" \t", pos); + if (next == std::string::npos) next = program.size(); + + if (mixed_indentation) + { + unsigned length = indentation_count(boost::string_ref( + &program[pos], next - pos)); + + if (length > full_indent) { + std::string new_indentation(length - full_indent, ' '); + unindented_program.append(new_indentation); + } + + copy_start = next; + } + else + { + copy_start = (std::min)(pos + indent, next); + } + + pos = next; + } while (std::string::npos != + (pos = program.find_first_of("\r\n", pos))); + + unindented_program.append(program.begin() + copy_start, program.end()); + + data->new_file->add_indented_mapped_file_section(x.begin()); + data->new_file->source_.append(unindented_program); } file_position mapped_file::position_of(boost::string_ref::const_iterator pos) const diff --git a/src/grammar_impl.hpp b/src/grammar_impl.hpp index 090b399..800e9f8 100644 --- a/src/grammar_impl.hpp +++ b/src/grammar_impl.hpp @@ -77,6 +77,7 @@ namespace quickbook cl::rule attribute_value_1_7; cl::rule escape; cl::rule raw_escape; + cl::rule skip_entity; // Miscellaneous stuff cl::rule hard_space; diff --git a/src/main_grammar.cpp b/src/main_grammar.cpp index c494350..a01c00a 100644 --- a/src/main_grammar.cpp +++ b/src/main_grammar.cpp @@ -128,17 +128,19 @@ namespace quickbook top_level, indent_check, paragraph_separator, code, code_line, blank_line, hr, - inline_code, + inline_code, skip_inline_code, template_, - code_block, macro, + code_block, skip_code_block, macro, template_args, template_args_1_4, template_arg_1_4, template_inner_arg_1_4, brackets_1_4, template_args_1_5, template_arg_1_5, template_arg_1_5_content, template_inner_arg_1_5, brackets_1_5, + template_args_1_6, template_arg_1_6, template_arg_1_6_content, break_, command_line_macro_identifier, - dummy_block, line_dummy_block, square_brackets + dummy_block, line_dummy_block, square_brackets, + skip_escape ; struct simple_markup_closure @@ -540,6 +542,17 @@ namespace quickbook | cl::anychar_p [plain_char] ; + skip_entity = + '[' + >> *(~cl::eps_p(']') >> skip_entity) + >> !cl::ch_p(']') + | local.skip_code_block + | local.skip_inline_code + | local.skip_escape + | comment + | (cl::anychar_p - '[' - ']') + ; + local.square_brackets = ( cl::ch_p('[') [plain_char] >> paragraph_phrase @@ -580,7 +593,8 @@ namespace quickbook ; local.template_args = - qbk_ver(105u) >> local.template_args_1_5 + qbk_ver(106u) >> local.template_args_1_6 + | qbk_ver(105u, 106u) >> local.template_args_1_5 | qbk_ver(0, 105u) >> local.template_args_1_4 ; @@ -622,6 +636,19 @@ namespace quickbook '[' >> local.template_inner_arg_1_5 >> ']' ; + local.template_args_1_6 = local.template_arg_1_6 >> *(".." >> local.template_arg_1_6); + + local.template_arg_1_6 = + ( cl::eps_p(*cl::blank_p >> cl::eol_p) + >> local.template_arg_1_6_content [state.values.entry(ph::arg1, ph::arg2, template_tags::block)] + | local.template_arg_1_6_content [state.values.entry(ph::arg1, ph::arg2, template_tags::phrase)] + ) + ; + + local.template_arg_1_6_content = + + ( ~cl::eps_p("..") >> skip_entity ) + ; + local.break_ = ( '[' >> space @@ -645,6 +672,48 @@ namespace quickbook ] [element] ; + local.skip_inline_code = + '`' + >> *(cl::anychar_p - + ( '`' + | (cl::eol_p >> *cl::blank_p >> cl::eol_p) + // Make sure that we don't go + ) // past a single block + ) + >> !cl::ch_p('`') + ; + + local.skip_code_block = + "```" + >> ~cl::eps_p("`") + >> ( !( *(*cl::blank_p >> cl::eol_p) + >> ( *( "````" >> *cl::ch_p('`') + | ( cl::anychar_p + - (*cl::space_p >> "```" >> ~cl::eps_p("`")) + ) + ) + >> !(*cl::blank_p >> cl::eol_p) + ) + >> (*cl::space_p >> "```") + ) + | *cl::anychar_p + ) + | "``" + >> ~cl::eps_p("`") + >> ( ( *(*cl::blank_p >> cl::eol_p) + >> ( *( "```" >> *cl::ch_p('`') + | ( cl::anychar_p + - (*cl::space_p >> "``" >> ~cl::eps_p("`")) + ) + ) + >> !(*cl::blank_p >> cl::eol_p) + ) + >> (*cl::space_p >> "``") + ) + | *cl::anychar_p + ) + ; + local.code_block = "```" >> ~cl::eps_p("`") @@ -746,6 +815,19 @@ namespace quickbook ] ; + local.skip_escape = + cl::str_p("\\n") + | cl::str_p("\\ ") + | '\\' >> cl::punct_p + | "\\u" >> cl::repeat_p(4) [cl::chset<>("0-9a-fA-F")] + | "\\U" >> cl::repeat_p(8) [cl::chset<>("0-9a-fA-F")] + | ("'''" >> !eol) + >> (*(cl::anychar_p - "'''")) + >> ( cl::str_p("'''") + | cl::eps_p + ) + ; + raw_escape = cl::str_p("\\n") [error("Newlines invalid here.")] | cl::str_p("\\ ") // ignore an escaped space diff --git a/src/quickbook.cpp b/src/quickbook.cpp index 8890dcb..2af638c 100644 --- a/src/quickbook.cpp +++ b/src/quickbook.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -111,16 +113,29 @@ namespace quickbook } } + struct parse_document_options + { + parse_document_options() : + indent(-1), + linewidth(-1), + pretty_print(true), + deps_out_flags(quickbook::dependency_tracker::default_) + {} + + int indent; + int linewidth; + bool pretty_print; + fs::path deps_out; + quickbook::dependency_tracker::flags deps_out_flags; + fs::path locations_out; + fs::path xinclude_base; + }; + static int parse_document( fs::path const& filein_ , fs::path const& fileout_ - , fs::path const& deps_out_ - , fs::path const& locations_out_ - , fs::path const& xinclude_base_ - , int indent - , int linewidth - , bool pretty_print) + , parse_document_options const& options_) { string_stream buffer; id_manager ids; @@ -128,7 +143,7 @@ namespace quickbook int result = 0; try { - quickbook::state state(filein_, xinclude_base_, buffer, ids); + quickbook::state state(filein_, options_.xinclude_base, buffer, ids); set_macros(state); if (state.error_count == 0) { @@ -145,16 +160,18 @@ namespace quickbook result = state.error_count ? 1 : 0; - if (!deps_out_.empty()) + if (!options_.deps_out.empty()) { - fs::ofstream out(deps_out_); - state.dependencies.write_dependencies(out); + fs::ofstream out(options_.deps_out); + state.dependencies.write_dependencies(out, + options_.deps_out_flags); } - if (!locations_out_.empty()) + if (!options_.locations_out.empty()) { - fs::ofstream out(locations_out_); - state.dependencies.write_checked_locations(out); + fs::ofstream out(options_.locations_out); + state.dependencies.write_dependencies(out, + dependency_tracker::checked); } } catch (load_error& e) { @@ -177,11 +194,12 @@ namespace quickbook return 1; } - if (pretty_print) + if (options_.pretty_print) { try { - fileout << post_process(stage2, indent, linewidth); + fileout << post_process(stage2, options_.indent, + options_.linewidth); } catch (quickbook::post_process_failure&) { @@ -243,6 +261,8 @@ main(int argc, char* argv[]) quickbook::detail::initialise_output(); quickbook::detail::initialise_markups(); + // Declare the program options + options_description desc("Allowed options"); options_description hidden("Hidden options"); options_description all("All options"); @@ -277,10 +297,15 @@ main(int argc, char* argv[]) ("xinclude-base", PO_VALUE(), "Generate xincludes as if generating for this target " "directory.") + ("output-deps-format", PO_VALUE(), + "Comma separated list of formatting options for output-deps, " + "options are: escaped, checked") ("output-checked-locations", PO_VALUE(), "Writes a file listing all the file locations that were " "checked, starting with '+' if they were found, or '-' " - "if they weren't.") + "if they weren't.\n" + "This is deprecated, use 'output-deps-format=checked' to " + "write the deps file in this format.") ; all.add(desc).add(hidden); @@ -288,10 +313,9 @@ main(int argc, char* argv[]) positional_options_description p; p.add("input-file", -1); + // Read option from the command line + variables_map vm; - int indent = -1; - int linewidth = -1; - bool pretty_print = true; #if QUICKBOOK_WIDE_PATHS quickbook::ignore_variable(&argc); @@ -321,6 +345,9 @@ main(int argc, char* argv[]) notify(vm); + // Process the command line options + + quickbook::parse_document_options parse_document_options; bool expect_errors = vm.count("expect-errors"); int error_count = 0; @@ -352,15 +379,15 @@ main(int argc, char* argv[]) quickbook::ms_errors = true; if (vm.count("no-pretty-print")) - pretty_print = false; + parse_document_options.pretty_print = false; quickbook::self_linked_headers = !vm.count("no-self-link-headers"); if (vm.count("indent")) - indent = vm["indent"].as(); + parse_document_options.indent = vm["indent"].as(); if (vm.count("linewidth")) - linewidth = vm["linewidth"].as(); + parse_document_options.linewidth = vm["linewidth"].as(); if (vm.count("debug")) { @@ -410,22 +437,56 @@ main(int argc, char* argv[]) fs::path filein = quickbook::detail::input_to_path( vm["input-file"].as()); fs::path fileout; - fs::path deps_out; - fs::path locations_out; bool default_output = true; if (vm.count("output-deps")) { - deps_out = quickbook::detail::input_to_path( - vm["output-deps"].as()); + parse_document_options.deps_out = + quickbook::detail::input_to_path( + vm["output-deps"].as()); default_output = false; } + if (vm.count("output-deps-format")) + { + std::string format_flags = + quickbook::detail::input_to_utf8( + vm["output-deps-format"].as()); + + std::vector flag_names; + boost::algorithm::split(flag_names, format_flags, + boost::algorithm::is_any_of(", "), + boost::algorithm::token_compress_on); + + unsigned flags = 0; + + BOOST_FOREACH(std::string const& flag, flag_names) { + if (flag == "checked") { + flags |= quickbook::dependency_tracker::checked; + } + else if (flag == "escaped") { + flags |= quickbook::dependency_tracker::escaped; + } + else if (!flag.empty()) { + quickbook::detail::outerr() + << "Unknown dependency format flag: " + << flag + <()); + parse_document_options.locations_out = + quickbook::detail::input_to_path( + vm["output-checked-locations"].as()); default_output = false; } @@ -440,20 +501,20 @@ main(int argc, char* argv[]) fileout.replace_extension(".xml"); } - fs::path xinclude_base; if (vm.count("xinclude-base")) { - xinclude_base = quickbook::detail::input_to_path( - vm["xinclude-base"].as()); + parse_document_options.xinclude_base = + quickbook::detail::input_to_path( + vm["xinclude-base"].as()); } else { - xinclude_base = fileout.parent_path(); - if (xinclude_base.empty()) - xinclude_base = "."; + parse_document_options.xinclude_base = fileout.parent_path(); + if (parse_document_options.xinclude_base.empty()) + parse_document_options.xinclude_base = "."; } - if (!fs::is_directory(xinclude_base)) + if (!fs::is_directory(parse_document_options.xinclude_base)) { quickbook::detail::outerr() << (vm.count("xinclude-base") ? @@ -480,8 +541,7 @@ main(int argc, char* argv[]) if (!error_count) error_count += quickbook::parse_document( - filein, fileout, deps_out, locations_out, - xinclude_base, indent, linewidth, pretty_print); + filein, fileout, parse_document_options); if (expect_errors) { diff --git a/src/syntax_highlight.cpp b/src/syntax_highlight.cpp index bb164c5..fdeaef5 100644 --- a/src/syntax_highlight.cpp +++ b/src/syntax_highlight.cpp @@ -205,20 +205,23 @@ namespace quickbook keywords_holder() { cpp - = "and_eq", "and", "asm", "auto", "bitand", "bitor", - "bool", "break", "case", "catch", "char", "class", - "compl", "const_cast", "const", "continue", "default", - "delete", "do", "double", "dynamic_cast", "else", - "enum", "explicit", "export", "extern", "false", - "float", "for", "friend", "goto", "if", "inline", - "int", "long", "mutable", "namespace", "new", "not_eq", - "not", "operator", "or_eq", "or", "private", - "protected", "public", "register", "reinterpret_cast", - "return", "short", "signed", "sizeof", "static", + = "alignas", "alignof", "and_eq", "and", "asm", "auto", + "bitand", "bitor", "bool", "break", "case", "catch", + "char", "char16_t", "char32_t", "class", "compl", + "const", "const_cast", "constexpr", "continue", + "decltype", "default", "delete", "do", "double", + "dynamic_cast", "else", "enum", "explicit", "export", + "extern", "false", "float", "for", "friend", "goto", + "if", "inline", "int", "long", "mutable", "namespace", + "new", "noexcept", "not_eq", "not", "nullptr", + "operator", "or_eq", "or", "private", "protected", + "public", "register", "reinterpret_cast", "return", + "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", - "throw", "true", "try", "typedef", "typeid", - "typename", "union", "unsigned", "using", "virtual", - "void", "volatile", "wchar_t", "while", "xor_eq", "xor" + "thread_local", "throw", "true", "try", "typedef", + "typeid", "typename", "union", "unsigned", "using", + "virtual", "void", "volatile", "wchar_t", "while", + "xor_eq", "xor" ; python @@ -270,12 +273,21 @@ namespace quickbook do_macro(self.actions, &syntax_highlight_actions::do_macro); error_action error(self.actions.state); - program - = - *( (+cl::space_p) [plain_char] + program = + *( (*cl::space_p) [plain_char] + >> (line_start | rest_of_line) + >> *rest_of_line + ) + ; + + line_start = + preprocessor [span("preprocessor")] + ; + + rest_of_line = + (+cl::blank_p) [plain_char] | macro | escape - | preprocessor [span("preprocessor")] | cl::eps_p(ph::var(self.actions.support_callouts)) >> ( line_callout [callout] | inline_callout [callout] @@ -287,8 +299,8 @@ namespace quickbook | string_ [span("string")] | char_ [span("char")] | number [span("number")] - | u8_codepoint_p [unexpected_char] - ) + | ~cl::eps_p(cl::eol_p) + >> u8_codepoint_p [unexpected_char] ; macro = @@ -359,7 +371,7 @@ namespace quickbook ; // make sure we recognize whole words only special - = +cl::chset_p("~!%^&*()+={[}]:;,<.>?/|\\-") + = +cl::chset_p("~!%^&*()+={[}]:;,<.>?/|\\#-") ; string_char = ('\\' >> u8_codepoint_p) | (cl::anychar_p - '\\'); @@ -387,7 +399,7 @@ namespace quickbook } cl::rule - program, macro, preprocessor, + program, line_start, rest_of_line, macro, preprocessor, inline_callout, line_callout, comment, special, string_, char_, number, identifier, keyword, escape, diff --git a/test/code_cpp-1_5.gold b/test/code_cpp-1_5.gold index be33bfd..d0bc79a 100644 --- a/test/code_cpp-1_5.gold +++ b/test/code_cpp-1_5.gold @@ -3,7 +3,11 @@
C++ Code Blocks -// No escape +#include <some_header> + #include "another_header.hpp" +# define A_MACRO value +#define stringize(hello) #hello +// No escape /* No escape */ /* No escape * with newlines @@ -13,6 +17,7 @@ /* Multiple escapes: italic * underlinebold */ +/* Token pasting: */ a##b A badly formed comment: @@ -24,4 +29,12 @@ /* Oh dear bold + + Just some code: + +int main() { + constexpr char32_t x = 'a'; + const auto y = x - ' '; +} +
diff --git a/test/code_cpp-1_5.quickbook b/test/code_cpp-1_5.quickbook index be8043a..fdaa926 100644 --- a/test/code_cpp-1_5.quickbook +++ b/test/code_cpp-1_5.quickbook @@ -2,6 +2,10 @@ [quickbook 1.5] ] + #include + #include "another_header.hpp" + # define A_MACRO value + #define stringize(hello) #hello // No escape /* No escape */ /* No escape @@ -12,6 +16,7 @@ /* Multiple escapes: ``/italic/`` * ``_underline_````*bold*`` */ + /* Token pasting: */ a##b A badly formed comment: @@ -20,3 +25,10 @@ A badly formed comment: A badly formed comment with an escape: /* Oh dear ``*bold*`` + +Just some code: + + int main() { + constexpr char32_t x = 'a'; + const auto y = x - ' '; + } diff --git a/test/doc-info/Jamfile.v2 b/test/doc-info/Jamfile.v2 index 9d4913b..bfb06cf 100644 --- a/test/doc-info/Jamfile.v2 +++ b/test/doc-info/Jamfile.v2 @@ -20,6 +20,8 @@ test-suite quickbook.test : [ quickbook-test escaped_attributes2-1_7 ] [ quickbook-test duplicates-1.1 ] [ quickbook-test duplicates-1.5 ] + [ quickbook-test macros1-1_5 ] + [ quickbook-test macros1-1_6 ] [ quickbook-test source-mode-1.4 ] [ quickbook-test source-mode-1.5 ] [ quickbook-test source-mode-1.6 ] diff --git a/test/doc-info/macros1-1_5.gold b/test/doc-info/macros1-1_5.gold new file mode 100644 index 0000000..0b76b9d --- /dev/null +++ b/test/doc-info/macros1-1_5.gold @@ -0,0 +1,11 @@ + + +
+ Macro shouldn't expand: __DATE__ + + + Unfortunately this does expand: 2000-Dec-20, but I'm not fixing it, as I don't + think it'll cause any real problems. + + +
diff --git a/test/doc-info/macros1-1_5.quickbook b/test/doc-info/macros1-1_5.quickbook new file mode 100644 index 0000000..c66a1de --- /dev/null +++ b/test/doc-info/macros1-1_5.quickbook @@ -0,0 +1,6 @@ +[article Macro shouldn't expand: __DATE__ + [quickbook 1.5] + [last-revision __DATE__] + [purpose Unfortunately this does expand: __DATE__, but I'm not fixing it, + as I don't think it'll cause any real problems.] +] diff --git a/test/doc-info/macros1-1_6.gold b/test/doc-info/macros1-1_6.gold new file mode 100644 index 0000000..92ac1a1 --- /dev/null +++ b/test/doc-info/macros1-1_6.gold @@ -0,0 +1,8 @@ + + +
+ Testing date: 2000-Dec-20 + + Testing macro date: 5 May 2013 + +
diff --git a/test/doc-info/macros1-1_6.quickbook b/test/doc-info/macros1-1_6.quickbook new file mode 100644 index 0000000..058c349 --- /dev/null +++ b/test/doc-info/macros1-1_6.quickbook @@ -0,0 +1,7 @@ +[article Testing date: __DATE__ + [quickbook 1.6] + [last-revision __DATE__] +] + +[def NESTED_MACRO 5 May 2013] +[include macros1-inc_1_6.quickbook] diff --git a/test/doc-info/macros1-inc_1_6.quickbook b/test/doc-info/macros1-inc_1_6.quickbook new file mode 100644 index 0000000..47fc84a --- /dev/null +++ b/test/doc-info/macros1-inc_1_6.quickbook @@ -0,0 +1,4 @@ +[chapter Testing macro date: NESTED_MACRO + [quickbook 1.6] + [last-revision NESTED_MACRO] +] diff --git a/test/empty.qbk b/test/empty-inc.quickbook similarity index 100% rename from test/empty.qbk rename to test/empty-inc.quickbook diff --git a/test/include-1_5.quickbook b/test/include-1_5.quickbook index 849d19c..9720121 100644 --- a/test/include-1_5.quickbook +++ b/test/include-1_5.quickbook @@ -3,15 +3,15 @@ [id include-test] ] -[include include_sub-1_5.qbk] -[include .\include_sub.qbk] -[include:foo include_sub.qbk] -[include empty.qbk] +[include include-inc-1_5.quickbook] +[include .\include-inc.quickbook] +[include:foo include-inc.quickbook] +[include empty-inc.quickbook] [def __defined__] -[? __undefined__ [include:foo1 include_sub.qbk] ] -[? __undefined__ [include:foo1 not_a_file.qbk] ] +[? __undefined__ [include:foo1 include-inc.quickbook] ] +[? __undefined__ [include:foo1 not_a_file.quickbook] ] [? __defined__ - Just trying including in a conditional macro. [include:foo2 include_sub.qbk] + Just trying including in a conditional macro. [include:foo2 include-inc.quickbook] With some text around it.] diff --git a/test/include-1_6.quickbook b/test/include-1_6.quickbook index 00d6033..29a7611 100644 --- a/test/include-1_6.quickbook +++ b/test/include-1_6.quickbook @@ -3,13 +3,13 @@ [id include-test] ] -[include include_sub.qbk] -[include:foo include_sub.qbk] +[include include-inc.quickbook] +[include:foo include-inc.quickbook] [def __defined__] -[? __undefined__ [include:foo1 include_sub.qbk] ] -[? __undefined__ [include:foo1 not-a-file.qbk] ] +[? __undefined__ [include:foo1 include-inc.quickbook] ] +[? __undefined__ [include:foo1 not-a-file.quickbook] ] [? __defined__ - Just trying including in a conditional macro. [include:foo2 include_sub.qbk] + Just trying including in a conditional macro. [include:foo2 include-inc.quickbook] With some text around it.] diff --git a/test/include_sub-1_5.qbk b/test/include-inc-1_5.quickbook similarity index 100% rename from test/include_sub-1_5.qbk rename to test/include-inc-1_5.quickbook diff --git a/test/include_sub.qbk b/test/include-inc.quickbook similarity index 100% rename from test/include_sub.qbk rename to test/include-inc.quickbook diff --git a/test/include/compatibility-1_1.quickbook b/test/include/compatibility-1_1.quickbook index ec5d62f..afdd39d 100644 --- a/test/include/compatibility-1_1.quickbook +++ b/test/include/compatibility-1_1.quickbook @@ -5,14 +5,14 @@ ] [section:collision Outer] -[include compatibility-inc.qbk] +[include compatibility-inc.quickbook] [endsect] [section:collision Include compatibility 1.1] -[include compatibility-inc_1_1.qbk] +[include compatibility-inc_1_1.quickbook] [endsect] [section:collision Include compatibility 1.5] -[include compatibility-inc_1_5.qbk] +[include compatibility-inc_1_5.quickbook] [endsect] [section:collision Include compatibility 1.6] -[include compatibility-inc_1_6.qbk] +[include compatibility-inc_1_6.quickbook] [endsect] diff --git a/test/include/compatibility-1_5.quickbook b/test/include/compatibility-1_5.quickbook index c16ddac..9593df7 100644 --- a/test/include/compatibility-1_5.quickbook +++ b/test/include/compatibility-1_5.quickbook @@ -5,14 +5,14 @@ ] [section:collision Outer] -[include compatibility-inc.qbk] +[include compatibility-inc.quickbook] [endsect] [section:collision Include compatibility 1.1] -[include compatibility-inc_1_1.qbk] +[include compatibility-inc_1_1.quickbook] [endsect] [section:collision Include compatibility 1.5] -[include compatibility-inc_1_5.qbk] +[include compatibility-inc_1_5.quickbook] [endsect] [section:collision Include compatibility 1.6] -[include compatibility-inc_1_6.qbk] +[include compatibility-inc_1_6.quickbook] [endsect] diff --git a/test/include/compatibility-1_6.quickbook b/test/include/compatibility-1_6.quickbook index 276674a..46880a8 100644 --- a/test/include/compatibility-1_6.quickbook +++ b/test/include/compatibility-1_6.quickbook @@ -4,14 +4,14 @@ ] [section:collision Outer] -[include compatibility-inc.qbk] +[include compatibility-inc.quickbook] [endsect] [section:collision Include compatibility 1.1] -[include compatibility-inc_1_1.qbk] +[include compatibility-inc_1_1.quickbook] [endsect] [section:collision Include compatibility 1.5] -[include compatibility-inc_1_5.qbk] +[include compatibility-inc_1_5.quickbook] [endsect] [section:collision Include compatibility 1.6] -[include compatibility-inc_1_6.qbk] +[include compatibility-inc_1_6.quickbook] [endsect] diff --git a/test/include/compatibility-inc.qbk b/test/include/compatibility-inc.quickbook similarity index 100% rename from test/include/compatibility-inc.qbk rename to test/include/compatibility-inc.quickbook diff --git a/test/include/compatibility-inc_1_1.qbk b/test/include/compatibility-inc_1_1.quickbook similarity index 100% rename from test/include/compatibility-inc_1_1.qbk rename to test/include/compatibility-inc_1_1.quickbook diff --git a/test/include/compatibility-inc_1_5.qbk b/test/include/compatibility-inc_1_5.quickbook similarity index 100% rename from test/include/compatibility-inc_1_5.qbk rename to test/include/compatibility-inc_1_5.quickbook diff --git a/test/include/compatibility-inc_1_6.qbk b/test/include/compatibility-inc_1_6.quickbook similarity index 100% rename from test/include/compatibility-inc_1_6.qbk rename to test/include/compatibility-inc_1_6.quickbook diff --git a/test/include/in_section-1_5.quickbook b/test/include/in_section-1_5.quickbook index 9cd15f6..2818309 100644 --- a/test/include/in_section-1_5.quickbook +++ b/test/include/in_section-1_5.quickbook @@ -3,14 +3,14 @@ ] [section:container Container] -[include in_section-include1.qbk] -[include in_section-include2.qbk] +[include in_section-inc1.quickbook] +[include in_section-inc2.quickbook] [endsect] -[include in_section-include1.qbk] -[include in_section-include2.qbk] +[include in_section-inc1.quickbook] +[include in_section-inc2.quickbook] [section:container2 Container2] -[include in_section-include1.qbk] -[include in_section-include2.qbk] +[include in_section-inc1.quickbook] +[include in_section-inc2.quickbook] [endsect] diff --git a/test/include/in_section-1_6.quickbook b/test/include/in_section-1_6.quickbook index 45be441..686f97e 100644 --- a/test/include/in_section-1_6.quickbook +++ b/test/include/in_section-1_6.quickbook @@ -3,14 +3,14 @@ ] [section:container Container] -[include in_section-include1.qbk] -[include in_section-include2.qbk] +[include in_section-inc1.quickbook] +[include in_section-inc2.quickbook] [endsect] -[include in_section-include1.qbk] -[include in_section-include2.qbk] +[include in_section-inc1.quickbook] +[include in_section-inc2.quickbook] [section:container2 Container2] -[include in_section-include1.qbk] -[include in_section-include2.qbk] +[include in_section-inc1.quickbook] +[include in_section-inc2.quickbook] [endsect] diff --git a/test/include/in_section-include1.qbk b/test/include/in_section-inc1.quickbook similarity index 100% rename from test/include/in_section-include1.qbk rename to test/include/in_section-inc1.quickbook diff --git a/test/include/in_section-include2.qbk b/test/include/in_section-inc2.quickbook similarity index 100% rename from test/include/in_section-include2.qbk rename to test/include/in_section-inc2.quickbook diff --git a/test/include/include_id_unbalanced-1_6.quickbook b/test/include/include_id_unbalanced-1_6.quickbook index 0b299a6..b1568d4 100644 --- a/test/include/include_id_unbalanced-1_6.quickbook +++ b/test/include/include_id_unbalanced-1_6.quickbook @@ -5,7 +5,7 @@ [/ Sections start in included files ] -[include:include1 include_id_unbalanced-inc1.qbk] +[include:include1 include_id_unbalanced-inc1.quickbook] [heading:x1 X1] [endsect] [heading:x2 X2] @@ -16,4 +16,4 @@ [heading:x1 X1] [section:sect2 Section 2] [heading:x2 X2] -[include:include2 include_id_unbalanced-inc2.qbk] +[include:include2 include_id_unbalanced-inc2.quickbook] diff --git a/test/include/include_id_unbalanced-inc1.qbk b/test/include/include_id_unbalanced-inc1.quickbook similarity index 57% rename from test/include/include_id_unbalanced-inc1.qbk rename to test/include/include_id_unbalanced-inc1.quickbook index 3170f26..d321481 100644 --- a/test/include/include_id_unbalanced-inc1.qbk +++ b/test/include/include_id_unbalanced-inc1.quickbook @@ -1,4 +1,4 @@ [section:inc1 Include 1] [heading:inc1_1 Heading 1] -[include:include1a include_id_unbalanced-inc1a.qbk] +[include:include1a include_id_unbalanced-inc1a.quickbook] [heading:inc1_2 Heading 2] diff --git a/test/include/include_id_unbalanced-inc1a.qbk b/test/include/include_id_unbalanced-inc1a.quickbook similarity index 100% rename from test/include/include_id_unbalanced-inc1a.qbk rename to test/include/include_id_unbalanced-inc1a.quickbook diff --git a/test/include/include_id_unbalanced-inc2.qbk b/test/include/include_id_unbalanced-inc2.quickbook similarity index 61% rename from test/include/include_id_unbalanced-inc2.qbk rename to test/include/include_id_unbalanced-inc2.quickbook index b719324..37c313c 100644 --- a/test/include/include_id_unbalanced-inc2.qbk +++ b/test/include/include_id_unbalanced-inc2.quickbook @@ -1,5 +1,5 @@ [heading:inc2_1 Heading 1] [endsect] [heading:inc2_2 Heading 2] -[include:include2a include_id_unbalanced-inc2a.qbk] +[include:include2a include_id_unbalanced-inc2a.quickbook] [heading:inc2_3 Heading 3] diff --git a/test/include/include_id_unbalanced-inc2a.qbk b/test/include/include_id_unbalanced-inc2a.quickbook similarity index 100% rename from test/include/include_id_unbalanced-inc2a.qbk rename to test/include/include_id_unbalanced-inc2a.quickbook diff --git a/test/include/nested_compatibility-1_5.quickbook b/test/include/nested_compatibility-1_5.quickbook index 8276715..f9d78b1 100644 --- a/test/include/nested_compatibility-1_5.quickbook +++ b/test/include/nested_compatibility-1_5.quickbook @@ -2,11 +2,11 @@ [article Nested Compatibility Test] [section Duplicate Name] -[include nested_compatibility_inc-1_5.qbk] -[include nested_compatibility_inc-1_6.qbk] +[include nested_compatibility-inc-1_5.quickbook] +[include nested_compatibility-inc-1_6.quickbook] [endsect] [section Duplicate Name] -[include nested_compatibility_inc-1_5.qbk] -[include nested_compatibility_inc-1_6.qbk] +[include nested_compatibility-inc-1_5.quickbook] +[include nested_compatibility-inc-1_6.quickbook] [endsect] diff --git a/test/include/nested_compatibility-1_6.quickbook b/test/include/nested_compatibility-1_6.quickbook index 72c4b65..8beeb8a 100644 --- a/test/include/nested_compatibility-1_6.quickbook +++ b/test/include/nested_compatibility-1_6.quickbook @@ -2,11 +2,11 @@ [article Nested Compatibility Test] [section Duplicate Name] -[include nested_compatibility_inc-1_5.qbk] -[include nested_compatibility_inc-1_6.qbk] +[include nested_compatibility-inc-1_5.quickbook] +[include nested_compatibility-inc-1_6.quickbook] [endsect] [section Duplicate Name] -[include nested_compatibility_inc-1_5.qbk] -[include nested_compatibility_inc-1_6.qbk] +[include nested_compatibility-inc-1_5.quickbook] +[include nested_compatibility-inc-1_6.quickbook] [endsect] diff --git a/test/include/nested_compatibility_inc-1_5.qbk b/test/include/nested_compatibility-inc-1_5.quickbook similarity index 100% rename from test/include/nested_compatibility_inc-1_5.qbk rename to test/include/nested_compatibility-inc-1_5.quickbook diff --git a/test/include/nested_compatibility_inc-1_6.qbk b/test/include/nested_compatibility-inc-1_6.quickbook similarity index 100% rename from test/include/nested_compatibility_inc-1_6.qbk rename to test/include/nested_compatibility-inc-1_6.quickbook diff --git a/test/include/source_mode-1_5.quickbook b/test/include/source_mode-1_5.quickbook index 24e52a0..9700cd1 100644 --- a/test/include/source_mode-1_5.quickbook +++ b/test/include/source_mode-1_5.quickbook @@ -1,3 +1,3 @@ [article Souce Mode Include [source-mode teletype][quickbook 1.5]] -[include source_mode-inc1.qbk] \ No newline at end of file +[include source_mode-inc1.quickbook] \ No newline at end of file diff --git a/test/include/source_mode-1_6.quickbook b/test/include/source_mode-1_6.quickbook index 9eb81d9..77ccae4 100644 --- a/test/include/source_mode-1_6.quickbook +++ b/test/include/source_mode-1_6.quickbook @@ -1,4 +1,4 @@ [source-mode teletype][quickbook 1.6] [article Souce Mode Include] -[include source_mode-inc1.qbk] \ No newline at end of file +[include source_mode-inc1.quickbook] \ No newline at end of file diff --git a/test/include/source_mode-inc1.qbk b/test/include/source_mode-inc1.quickbook similarity index 100% rename from test/include/source_mode-inc1.qbk rename to test/include/source_mode-inc1.quickbook diff --git a/test/include2-1_6.quickbook b/test/include2-1_6.quickbook index be78fcc..66b4897 100644 --- a/test/include2-1_6.quickbook +++ b/test/include2-1_6.quickbook @@ -3,6 +3,6 @@ [id include-test] ] -[include include_sub-1_5.qbk] -[include include_sub.qbk] -[include:foo include_sub.qbk] +[include include-inc-1_5.quickbook] +[include include-inc.quickbook] +[include:foo include-inc.quickbook] diff --git a/test/include_win_path-1_6-fail.quickbook b/test/include_win_path-1_6-fail.quickbook index 2e25423..aff5fd2 100644 --- a/test/include_win_path-1_6-fail.quickbook +++ b/test/include_win_path-1_6-fail.quickbook @@ -2,4 +2,4 @@ [quickbook 1.6] ] -[include .\empty.qbk] +[include .\empty-inc.quickbook] diff --git a/test/python/include_path.qbk b/test/python/include_path.qbk index c9a4dcd..3af3b37 100644 --- a/test/python/include_path.qbk +++ b/test/python/include_path.qbk @@ -1,3 +1,11 @@ +[/ + Copyright 2012-2013 Daniel James + + Distributed under 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) +] + [quickbook 1.5] [article Include Path] [include a.qbk] diff --git a/test/python/missing_relative.qbk b/test/python/missing_relative.qbk index 8fdc0ee..ff96b10 100644 --- a/test/python/missing_relative.qbk +++ b/test/python/missing_relative.qbk @@ -1,3 +1,11 @@ +[/ + Copyright 2012-2013 Daniel James + + Distributed under 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) +] + [quickbook 1.5] [article Missing Relative] diff --git a/test/python/sub1/a.qbk b/test/python/sub1/a.qbk index 7898192..f3abe6e 100644 --- a/test/python/sub1/a.qbk +++ b/test/python/sub1/a.qbk @@ -1 +1,9 @@ +[/ + Copyright 2012-2013 Daniel James + + Distributed under 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) +] + a diff --git a/test/python/sub2/b.qbk b/test/python/sub2/b.qbk index 6178079..9b4336b 100644 --- a/test/python/sub2/b.qbk +++ b/test/python/sub2/b.qbk @@ -1 +1,9 @@ +[/ + Copyright 2012-2013 Daniel James + + Distributed under 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) +] + b diff --git a/test/python/svg_missing.qbk b/test/python/svg_missing.qbk index 2b25c2f..1b54ece 100644 --- a/test/python/svg_missing.qbk +++ b/test/python/svg_missing.qbk @@ -1,3 +1,11 @@ +[/ + Copyright 2012-2013 Daniel James + + Distributed under 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) +] + [article Dependencies for missing svg] [$missing.svg] diff --git a/test/snippets/unbalanced_snippet1.cpp b/test/snippets/unbalanced_snippet1.cpp index ec49a78..c9a0c88 100644 --- a/test/snippets/unbalanced_snippet1.cpp +++ b/test/snippets/unbalanced_snippet1.cpp @@ -1,3 +1,3 @@ //[unclosed -int main() {} \ No newline at end of file +int main() {} diff --git a/test/snippets/unbalanced_snippet2.cpp b/test/snippets/unbalanced_snippet2.cpp index b057517..a7d8b04 100644 --- a/test/snippets/unbalanced_snippet2.cpp +++ b/test/snippets/unbalanced_snippet2.cpp @@ -1 +1 @@ -//] \ No newline at end of file +//] diff --git a/test/unit/source_map_test.cpp b/test/unit/source_map_test.cpp index ead5b5f..3eb3057 100644 --- a/test/unit/source_map_test.cpp +++ b/test/unit/source_map_test.cpp @@ -303,14 +303,93 @@ void indented_map_leading_blanks_test() BOOST_TEST_EQ(f1->source(), boost::string_ref("Code line1\n\nCode line2")); } +} + +void indented_map_trailing_blanks_test() +{ + quickbook::mapped_file_builder builder; + + { + boost::string_ref source("\n\n Code line1\n "); + quickbook::file_ptr fake_file = new quickbook::file( + "(fake file)", source, 105u); + builder.start(fake_file); + builder.unindent_and_add(fake_file->source()); + quickbook::file_ptr f1 = builder.release(); + BOOST_TEST_EQ(f1->source(), + boost::string_ref("Code line1\n")); + } + + { + boost::string_ref source(" \n \n Code line1\n "); + quickbook::file_ptr fake_file = new quickbook::file( + "(fake file)", source, 105u); + builder.start(fake_file); + builder.unindent_and_add(fake_file->source()); + quickbook::file_ptr f1 = builder.release(); + BOOST_TEST_EQ(f1->source(), + boost::string_ref("Code line1\n ")); + } + + { + boost::string_ref source(" Code line1\n \n Code line2\n "); + quickbook::file_ptr fake_file = new quickbook::file( + "(fake file)", source, 105u); + builder.start(fake_file); + builder.unindent_and_add(fake_file->source()); + quickbook::file_ptr f1 = builder.release(); + BOOST_TEST_EQ(f1->source(), + boost::string_ref("Code line1\n\nCode line2\n")); + } } +void indented_map_mixed_test() +{ + quickbook::mapped_file_builder builder; + + { + boost::string_ref source("\tCode line 1\n Code line 2\n\t Code line 3\n \tCode line 4"); + quickbook::file_ptr fake_file = new quickbook::file( + "(fake file)", source, 105u); + builder.start(fake_file); + builder.unindent_and_add(fake_file->source()); + quickbook::file_ptr f1 = builder.release(); + BOOST_TEST_EQ(f1->source(), + boost::string_ref("Code line 1\nCode line 2\n Code line 3\n Code line 4")); + } + + { + boost::string_ref source(" Code line 1\n\tCode line 2"); + quickbook::file_ptr fake_file = new quickbook::file( + "(fake file)", source, 105u); + builder.start(fake_file); + builder.unindent_and_add(fake_file->source()); + quickbook::file_ptr f1 = builder.release(); + BOOST_TEST_EQ(f1->source(), + boost::string_ref("Code line 1\n Code line 2")); + } + + { + boost::string_ref source(" Code line 1\n \tCode line 2"); + quickbook::file_ptr fake_file = new quickbook::file( + "(fake file)", source, 105u); + builder.start(fake_file); + builder.unindent_and_add(fake_file->source()); + quickbook::file_ptr f1 = builder.release(); + BOOST_TEST_EQ(f1->source(), + boost::string_ref("Code line 1\n\tCode line 2")); + } +} + + int main() { simple_map_tests(); indented_map_tests(); indented_map_tests2(); indented_map_leading_blanks_test(); + indented_map_trailing_blanks_test(); + indented_map_mixed_test(); return boost::report_errors(); } diff --git a/test/versions/invalid_macro-1_6.quickbook b/test/versions/invalid_macro-1_6.quickbook index f579f72..860d58b 100644 --- a/test/versions/invalid_macro-1_6.quickbook +++ b/test/versions/invalid_macro-1_6.quickbook @@ -4,11 +4,11 @@ Import: -[import invalid_macro-inc-1_1.qbk] +[import invalid_macro-inc-1_1.quickbook] * __valid__ * __invalid\macro__ Include: -[include invalid_macro-inc-1_1.qbk] +[include invalid_macro-inc-1_1.quickbook] diff --git a/test/versions/invalid_macro-inc-1_1.qbk b/test/versions/invalid_macro-inc-1_1.quickbook similarity index 100% rename from test/versions/invalid_macro-inc-1_1.qbk rename to test/versions/invalid_macro-inc-1_1.quickbook diff --git a/test/versions/templates-1_1.qbk b/test/versions/templates-inc-1_1.quickbook similarity index 100% rename from test/versions/templates-1_1.qbk rename to test/versions/templates-inc-1_1.quickbook diff --git a/test/versions/templates-1_4.qbk b/test/versions/templates-inc-1_4.quickbook similarity index 100% rename from test/versions/templates-1_4.qbk rename to test/versions/templates-inc-1_4.quickbook diff --git a/test/versions/templates-1_5.qbk b/test/versions/templates-inc-1_5.quickbook similarity index 100% rename from test/versions/templates-1_5.qbk rename to test/versions/templates-inc-1_5.quickbook diff --git a/test/versions/versions-1_6.quickbook b/test/versions/versions-1_6.quickbook index baac8e0..fed5a93 100644 --- a/test/versions/versions-1_6.quickbook +++ b/test/versions/versions-1_6.quickbook @@ -1,9 +1,9 @@ [quickbook 1.6] [article Mixed version tests] -[import templates-1_1.qbk] -[import templates-1_4.qbk] -[import templates-1_5.qbk] +[import templates-inc-1_1.quickbook] +[import templates-inc-1_4.quickbook] +[import templates-inc-1_5.quickbook] [/ This test calls a 1.4 template -> 1.5 template -> 1.4 template. The name lookup in the 1.4 template should skip the 1.5 template @@ -21,6 +21,6 @@ [/ For comparison] -[include templates-1_1.qbk] -[include templates-1_4.qbk] -[include templates-1_5.qbk] +[include templates-inc-1_1.quickbook] +[include templates-inc-1_4.quickbook] +[include templates-inc-1_5.quickbook]