}
-string const Parser::verbatimStuff(string const & end_string)
+Parser::Arg Parser::verbatimStuff(string const & end_string, bool const allow_linebreak)
{
if (!good())
- return string();
+ return Arg(false, string());
+ pushPosition();
ostringstream oss;
size_t match_index = 0;
setCatcodes(VERBATIM_CATCODES);
match_index += t.asInput().length();
if (match_index >= end_string.length())
break;
- } else if (match_index) {
- oss << end_string.substr(0, match_index) << t.asInput();
- match_index = 0;
- } else
- oss << t.asInput();
+ } else {
+ if (!allow_linebreak && t.asInput() == "\n") {
+ cerr << "unexpected end of input" << endl;
+ popPosition();
+ setCatcodes(NORMAL_CATCODES);
+ return Arg(false, string());
+ }
+ if (match_index) {
+ oss << end_string.substr(0, match_index)
+ << t.asInput();
+ match_index = 0;
+ } else
+ oss << t.asInput();
+ }
}
- setCatcodes(NORMAL_CATCODES);
- if (!good())
+
+ if (!good()) {
cerr << "unexpected end of input" << endl;
- return oss.str();
+ popPosition();
+ setCatcodes(NORMAL_CATCODES);
+ return Arg(false, string());
+ }
+ setCatcodes(NORMAL_CATCODES);
+ dropPosition();
+ return Arg(true, oss.str());
}
string const Parser::verbatimEnvironment(string const & name)
{
- string s = verbatimStuff("\\end{" + name + "}");
+ //FIXME: do something if endstring is not found
+ string s = verbatimStuff("\\end{" + name + "}").second;
// ignore one newline at beginning or end of string
if (prefixIs(s, "\n"))
s.erase(0,1);
* stopped at string \p end_string. Contrary to the other
* methods, this uses proper catcode setting. This function is
* designed to parse verbatim environments and command. The
- * intention is to eventually replace all of its siblings.
+ * intention is to eventually replace all of its siblings. the
+ * member \p first of the result tells whether the arg was
+ * found and the member \p second is the value. If \p
+ * allow_linebreak is false, then the parsing is limited to one line
*/
- std::string const verbatimStuff(std::string const & end_string);
+ Arg verbatimStuff(std::string const & end_string,
+ bool allow_linebreak = true);
/*
* \returns the contents of the environment \p name.
* <tt>\begin{name}</tt> must be parsed already,
// set catcodes to verbatim early, just in case.
p.setCatcodes(VERBATIM_CATCODES);
string delim = p.get_token().asInput();
- s = p.verbatimStuff(delim);
+ //FIXME: handler error condition
+ s = p.verbatimStuff(delim).second;
// context.new_paragraph(os);
} else
s = p.verbatimEnvironment("lstlisting");
// set catcodes to verbatim early, just in case.
p.setCatcodes(VERBATIM_CATCODES);
string delim = p.get_token().asInput();
- string const arg = p.verbatimStuff(delim);
+ //FIXME: handle error condition
+ string const arg = p.verbatimStuff(delim).second;
output_ert_inset(os, "\\verb" + delim + arg + delim, context);
}
string delim = p.get_token().asInput();
if (delim != "{")
cerr << "Warning: bad delimiter for command " << t.asInput() << endl;
- string const arg = p.verbatimStuff("}");
+ //FIXME: handle error condition
+ string const arg = p.verbatimStuff("}").second;
Context newcontext(true, context.textclass);
if (newinsetlayout->forcePlainLayout())
newcontext.layout = &context.textclass.plainLayout();