#include "state.hpp"
#include "values.hpp"
#include "files.hpp"
-#include "native_text.hpp"
+#include "stream.hpp"
namespace quickbook
{
struct code_snippet_actions
{
- code_snippet_actions(std::vector<template_symbol>& storage,
- file_ptr source_file,
- char const* source_type)
- : last_code_pos(source_file->source().begin())
+ code_snippet_actions(std::vector<template_symbol>& storage_,
+ file_ptr source_file_,
+ char const* source_type_)
+ : last_code_pos(source_file_->source().begin())
, in_code(false)
, snippet_stack()
- , storage(storage)
- , source_file(source_file)
- , source_type(source_type)
+ , storage(storage_)
+ , source_file(source_file_)
+ , source_type(source_type_)
, error_count(0)
{
source_file->is_code_snippets = true;
struct snippet_data
{
- snippet_data(std::string const& id)
- : id(id)
+ snippet_data(std::string const& id_)
+ : id(id_)
, start_code(false)
{}
std::string id;
bool start_code;
string_iterator source_pos;
- mapped_file_builder::pos start_pos;
+ mapped_file_builder::pos_type start_pos;
boost::shared_ptr<snippet_data> next;
};
}
mapped_file_builder content;
- boost::string_ref::const_iterator mark_begin, mark_end;
- boost::string_ref::const_iterator last_code_pos;
+ string_iterator mark_begin, mark_end;
+ string_iterator last_code_pos;
bool in_code;
boost::shared_ptr<snippet_data> snippet_stack;
std::vector<template_symbol>& storage;
{
typedef code_snippet_actions actions_type;
- python_code_snippet_grammar(actions_type & actions)
- : actions(actions)
+ python_code_snippet_grammar(actions_type & actions_)
+ : actions(actions_)
{}
template <typename Scanner>
definition(python_code_snippet_grammar const& self)
{
- actions_type& actions = self.actions;
-
- start_ = (*code_elements) [boost::bind(&actions_type::end_file, &actions, _1, _2)]
+ start_ = (*code_elements) [boost::bind(&actions_type::end_file, &self.actions, _1, _2)]
;
identifier =
;
code_elements =
- start_snippet [boost::bind(&actions_type::start_snippet, &actions, _1, _2)]
- | end_snippet [boost::bind(&actions_type::end_snippet, &actions, _1, _2)]
- | escaped_comment [boost::bind(&actions_type::escaped_comment, &actions, _1, _2)]
- | pass_thru_comment [boost::bind(&actions_type::pass_thru, &actions, _1, _2)]
- | ignore [boost::bind(&actions_type::append_code, &actions, _1, _2)]
+ start_snippet [boost::bind(&actions_type::start_snippet, &self.actions, _1, _2)]
+ | end_snippet [boost::bind(&actions_type::end_snippet, &self.actions, _1, _2)]
+ | escaped_comment [boost::bind(&actions_type::escaped_comment, &self.actions, _1, _2)]
+ | pass_thru_comment [boost::bind(&actions_type::pass_thru, &self.actions, _1, _2)]
+ | ignore [boost::bind(&actions_type::append_code, &self.actions, _1, _2)]
| cl::anychar_p
;
>> !(cl::eol_p >> *cl::blank_p)
>> "#["
>> *cl::blank_p
- >> identifier [boost::bind(&actions_type::mark, &actions, _1, _2)]
+ >> identifier [boost::bind(&actions_type::mark, &self.actions, _1, _2)]
>> *(cl::anychar_p - cl::eol_p)
;
escaped_comment =
cl::confix_p(
*cl::space_p >> "#`",
- (*cl::anychar_p) [boost::bind(&actions_type::mark, &actions, _1, _2)],
+ (*cl::anychar_p) [boost::bind(&actions_type::mark, &self.actions, _1, _2)],
(cl::eol_p | cl::end_p)
)
| cl::confix_p(
*cl::space_p >> "\"\"\"`",
- (*cl::anychar_p) [boost::bind(&actions_type::mark, &actions, _1, _2)],
+ (*cl::anychar_p) [boost::bind(&actions_type::mark, &self.actions, _1, _2)],
"\"\"\""
)
;
= "#=" >> (cl::eps_p - '=')
>> ( *(cl::anychar_p - cl::eol_p)
>> (cl::eol_p | cl::end_p)
- ) [boost::bind(&actions_type::mark, &actions, _1, _2)]
+ ) [boost::bind(&actions_type::mark, &self.actions, _1, _2)]
| cl::confix_p(
"\"\"\"=" >> (cl::eps_p - '='),
- (*cl::anychar_p) [boost::bind(&actions_type::mark, &actions, _1, _2)],
+ (*cl::anychar_p) [boost::bind(&actions_type::mark, &self.actions, _1, _2)],
"\"\"\""
)
;
{
typedef code_snippet_actions actions_type;
- cpp_code_snippet_grammar(actions_type & actions)
- : actions(actions)
+ cpp_code_snippet_grammar(actions_type & actions_)
+ : actions(actions_)
{}
template <typename Scanner>
{
definition(cpp_code_snippet_grammar const& self)
{
- actions_type& actions = self.actions;
-
- start_ = (*code_elements) [boost::bind(&actions_type::end_file, &actions, _1, _2)]
+ start_ = (*code_elements) [boost::bind(&actions_type::end_file, &self.actions, _1, _2)]
;
identifier =
;
code_elements =
- start_snippet [boost::bind(&actions_type::start_snippet, &actions, _1, _2)]
- | end_snippet [boost::bind(&actions_type::end_snippet, &actions, _1, _2)]
- | escaped_comment [boost::bind(&actions_type::escaped_comment, &actions, _1, _2)]
- | ignore [boost::bind(&actions_type::append_code, &actions, _1, _2)]
- | pass_thru_comment [boost::bind(&actions_type::pass_thru, &actions, _1, _2)]
+ start_snippet [boost::bind(&actions_type::start_snippet, &self.actions, _1, _2)]
+ | end_snippet [boost::bind(&actions_type::end_snippet, &self.actions, _1, _2)]
+ | escaped_comment [boost::bind(&actions_type::escaped_comment, &self.actions, _1, _2)]
+ | ignore [boost::bind(&actions_type::append_code, &self.actions, _1, _2)]
+ | pass_thru_comment [boost::bind(&actions_type::pass_thru, &self.actions, _1, _2)]
| cl::anychar_p
;
>> !(cl::eol_p >> *cl::blank_p)
>> "//["
>> *cl::blank_p
- >> identifier [boost::bind(&actions_type::mark, &actions, _1, _2)]
+ >> identifier [boost::bind(&actions_type::mark, &self.actions, _1, _2)]
>> *(cl::anychar_p - cl::eol_p)
|
*cl::blank_p
>> *cl::blank_p
>> "/*["
>> *cl::space_p
- >> identifier [boost::bind(&actions_type::mark, &actions, _1, _2)]
+ >> identifier [boost::bind(&actions_type::mark, &self.actions, _1, _2)]
>> *cl::space_p
>> "*/"
>> *cl::blank_p
|
"/*["
>> *cl::space_p
- >> identifier [boost::bind(&actions_type::mark, &actions, _1, _2)]
+ >> identifier [boost::bind(&actions_type::mark, &self.actions, _1, _2)]
>> *cl::space_p
>> "*/"
;
escaped_comment
= cl::confix_p(
*cl::space_p >> "//`",
- (*cl::anychar_p) [boost::bind(&actions_type::mark, &actions, _1, _2)],
+ (*cl::anychar_p) [boost::bind(&actions_type::mark, &self.actions, _1, _2)],
(cl::eol_p | cl::end_p)
)
| cl::confix_p(
*cl::space_p >> "/*`",
- (*cl::anychar_p) [boost::bind(&actions_type::mark, &actions, _1, _2)],
+ (*cl::anychar_p) [boost::bind(&actions_type::mark, &self.actions, _1, _2)],
"*/"
)
;
= "//=" >> (cl::eps_p - '=')
>> ( *(cl::anychar_p - cl::eol_p)
>> (cl::eol_p | cl::end_p)
- ) [boost::bind(&actions_type::mark, &actions, _1, _2)]
+ ) [boost::bind(&actions_type::mark, &self.actions, _1, _2)]
| cl::confix_p(
"/*=" >> (cl::eps_p - '='),
- (*cl::anychar_p) [boost::bind(&actions_type::mark, &actions, _1, _2)],
+ (*cl::anychar_p) [boost::bind(&actions_type::mark, &self.actions, _1, _2)],
"*/"
)
;
assert(load_type == block_tags::include ||
load_type == block_tags::import);
- bool is_python = extension == ".py";
+ bool is_python = extension == ".py" || extension == ".jam";
code_snippet_actions a(storage, load(filename, qbk_version_n), is_python ? "[python]" : "[c++]");
string_iterator first(a.source_file->source().begin());
in_code = true;
}
- content.add(boost::string_ref(last_code_pos, first - last_code_pos));
+ content.add(quickbook::string_view(last_code_pos, first - last_code_pos));
}
}
in_code = true;
}
- content.add(boost::string_ref(mark_begin, mark_end - mark_begin));
+ content.add(quickbook::string_view(mark_begin, mark_end - mark_begin));
}
void code_snippet_actions::escaped_comment(string_iterator first, string_iterator last)
snippet_data& snippet = *snippet_stack;
content.add_at_pos("\n", mark_begin);
- content.unindent_and_add(boost::string_ref(mark_begin, mark_end - mark_begin));
+ content.unindent_and_add(quickbook::string_view(mark_begin, mark_end - mark_begin));
if (snippet.id == "!")
{