#include "syntax_highlight.hpp"
#include "utils.hpp"
#include "files.hpp"
-#include "native_text.hpp"
+#include "stream.hpp"
#include "phrase_tags.hpp"
namespace quickbook
// State
bool support_callouts;
- boost::string_ref marked_text;
+ quickbook::string_view marked_text;
- syntax_highlight_actions(quickbook::state& state, bool is_block) :
- state(state),
- do_macro_impl(state),
- support_callouts(is_block && (qbk_version_n >= 107u ||
+ syntax_highlight_actions(quickbook::state& state_, bool is_block_) :
+ state(state_),
+ do_macro_impl(state_),
+ support_callouts(is_block_ && (qbk_version_n >= 107u ||
state.current_file->is_code_snippets)),
marked_text()
{}
void syntax_highlight_actions::mark_text(parse_iterator first,
parse_iterator last)
{
- marked_text = boost::string_ref(first.base(), last.base() - first.base());
+ marked_text = quickbook::string_view(first.base(), last.base() - first.base());
}
void syntax_highlight_actions::callout(parse_iterator, parse_iterator)
// Grammar for C++ highlighting
struct cpp_highlight : public cl::grammar<cpp_highlight>
{
- cpp_highlight(syntax_highlight_actions& actions)
- : actions(actions) {}
+ explicit cpp_highlight(syntax_highlight_actions& actions_)
+ : actions(actions_) {}
template <typename Scanner>
struct definition
// http://docs.python.org/ref/ref.html
struct python_highlight : public cl::grammar<python_highlight>
{
- python_highlight(syntax_highlight_actions& actions)
- : actions(actions) {}
+ explicit python_highlight(syntax_highlight_actions& actions_)
+ : actions(actions_) {}
template <typename Scanner>
struct definition
=
*( (+cl::space_p) [plain_char]
| macro
- | escape
+ | escape
+ | cl::eps_p(ph::var(self.actions.support_callouts))
+ >> ( line_callout [callout]
+ | inline_callout [callout]
+ )
| comment
| keyword [span("keyword")]
| identifier [span("identifier")]
) [post_escape_back]
;
+ inline_callout
+ = "#<" >> *cl::space_p >>
+ (*(cl::anychar_p - cl::eol_p)) [mark_text]
+ ;
+
+ line_callout
+ = cl::confix_p(
+ "#<<" >> *cl::space_p,
+ (*cl::anychar_p) [mark_text],
+ (cl::eol_p | cl::end_p)
+ )
+ ;
+
comment
= cl::str_p("#") [span_start("comment")]
>> *( escape
}
cl::rule<Scanner>
- program, macro, comment, special, string_, string_prefix,
+ program, macro, inline_callout, line_callout,
+ comment, special, string_, string_prefix,
short_string, long_string, number, identifier, keyword,
escape, string_char;
// Grammar for plain text (no actual highlighting)
struct teletype_highlight : public cl::grammar<teletype_highlight>
{
- teletype_highlight(syntax_highlight_actions& actions)
- : actions(actions) {}
+ teletype_highlight(syntax_highlight_actions& actions_)
+ : actions(actions_) {}
template <typename Scanner>
struct definition