Teletype source mode. Refs #1202.

[SVN r54815]
This commit is contained in:
Daniel James 2009-07-08 21:40:46 +00:00
parent 5e52d075fa
commit a087316841
9 changed files with 134 additions and 0 deletions

View File

@ -320,6 +320,14 @@ namespace quickbook
{
parse(first, last, python_p);
}
else if (source_mode == "teletype")
{
parse(first, last, teletype_p);
}
else
{
BOOST_ASSERT(0);
}
std::string str;
temp.swap(str);

View File

@ -432,6 +432,16 @@ namespace quickbook
, collector>
python_p_type;
typedef teletype_highlight<
plain_char_action
, string_symbols
, do_macro_action
, pre_escape_back
, post_escape_back
, actions
, collector>
teletype_p_type;
struct syntax_highlight
{
syntax_highlight(
@ -443,6 +453,7 @@ namespace quickbook
, source_mode(source_mode)
, cpp_p(temp, macro, do_macro_action(temp), escape_actions)
, python_p(temp, macro, do_macro_action(temp), escape_actions)
, teletype_p(temp, macro, do_macro_action(temp), escape_actions)
{
}
@ -452,6 +463,7 @@ namespace quickbook
std::string const& source_mode;
cpp_p_type cpp_p;
python_p_type python_p;
teletype_p_type teletype_p;
};
struct code_action

View File

@ -436,6 +436,7 @@ C++ comment `// looks like this` whereas a Python comment [python]
[[Mode] [Source Mode Markup]]
[[C++] [[^\[c++\]]]]
[[Python] [[^\[python\]]]]
[[Plain Text] [[^\[teletype\]]]]
]
[note The source mode strings are lowercase.]

View File

@ -153,6 +153,7 @@ namespace quickbook
>> (
str_p("c++")
| "python"
| "teletype"
) [assign_a(actions.source_mode)]
;

View File

@ -403,6 +403,7 @@ namespace quickbook
(
str_p("c++")
| "python"
| "teletype"
) [assign_a(actions.source_mode)]
;

View File

@ -323,6 +323,85 @@ namespace quickbook
DoMacro do_macro;
EscapeActions& escape_actions;
};
// Grammar for plain text (no actual highlighting)
template <
typename CharProcess
, typename Macro
, typename DoMacro
, typename PreEscape
, typename PostEscape
, typename EscapeActions
, typename Out>
struct teletype_highlight
: public grammar<teletype_highlight<CharProcess, Macro, DoMacro, PreEscape, PostEscape, EscapeActions, Out> >
{
teletype_highlight(Out& out, Macro const& macro, DoMacro do_macro, EscapeActions& escape_actions)
: out(out), macro(macro), do_macro(do_macro), escape_actions(escape_actions) {}
template <typename Scanner>
struct definition
{
definition(teletype_highlight const& self)
: common(self.escape_actions, unused)
, unused(false)
{
program
=
*( macro
| escape
| repeat_p(1)[anychar_p] [CharProcess(self.out)]
)
;
macro =
eps_p(self.macro // must not be followed by
>> (eps_p - (alpha_p | '_'))) // alpha or underscore
>> self.macro [self.do_macro]
;
qbk_phrase =
*( common
| (anychar_p - str_p("``")) [self.escape_actions.plain_char]
)
;
escape =
str_p("``") [PreEscape(self.escape_actions, save)]
>>
(
(
(
(+(anychar_p - "``") >> eps_p("``"))
& qbk_phrase
)
>> str_p("``")
)
|
(
eps_p [self.escape_actions.error]
>> *anychar_p
)
) [PostEscape(self.out, self.escape_actions, save)]
;
}
rule<Scanner> program, macro, qbk_phrase, escape;
phrase_grammar<EscapeActions> common;
std::string save;
bool unused;
rule<Scanner> const&
start() const { return program; }
};
Out& out;
Macro const& macro;
DoMacro do_macro;
EscapeActions& escape_actions;
};
}
#endif // BOOST_SPIRIT_QUICKBOOK_SYNTAX_HIGHLIGHT_HPP

View File

@ -15,6 +15,7 @@ test-suite quickbook.test :
[ quickbook-test code-block-1 ]
[ quickbook-test code-block-2 ]
[ quickbook-test code-block-3 ]
[ quickbook-test code-block-teletype ]
[ quickbook-test code-snippet ]
[ quickbook-test preformatted ]
[ quickbook-test link-side-by-side ]

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<article id="code_block_teletype_1" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Code Block Teletype 1</title>
<articleinfo>
</articleinfo>
<para>
</para>
<section id="code_block_teletype_1.a_code_block">
<title><link linkend="code_block_teletype_1.a_code_block">A code block</link></title>
<programlisting>Just some plain text.
With some <emphasis role="bold">quickbook</emphasis> thrown in?
</programlisting>
</section>
</article>

View File

@ -0,0 +1,14 @@
[article Code Block Teletype 1
[quickbook 1.5]
]
[teletype]
[section A code block]
[def __text__ text]
Just some plain __text__.
``With some *quickbook* thrown in?``
[endsect]