mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 11:16:55 +00:00
Don't crash on nested tables anymore
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9716 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
69eb781b4b
commit
0153a52b57
@ -1,3 +1,8 @@
|
|||||||
|
2005-03-11 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||||
|
|
||||||
|
* table.C (parse_table): handle nested tables
|
||||||
|
* texparser.[Ch] (verbatimEnvironment): new
|
||||||
|
|
||||||
2005-03-07 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
2005-03-07 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||||
|
|
||||||
* table.C (verbose_valign): new
|
* table.C (verbose_valign): new
|
||||||
|
@ -653,6 +653,7 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
|
|||||||
if (n.cat() == catMath) {
|
if (n.cat() == catMath) {
|
||||||
// TeX's $$...$$ syntax for displayed math
|
// TeX's $$...$$ syntax for displayed math
|
||||||
os << "\\[";
|
os << "\\[";
|
||||||
|
// This does only work because parse_math outputs TeX
|
||||||
parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
|
parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
|
||||||
os << "\\]";
|
os << "\\]";
|
||||||
p.get_token(); // skip the second '$' token
|
p.get_token(); // skip the second '$' token
|
||||||
@ -660,6 +661,7 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
|
|||||||
// simple $...$ stuff
|
// simple $...$ stuff
|
||||||
p.putback();
|
p.putback();
|
||||||
os << '$';
|
os << '$';
|
||||||
|
// This does only work because parse_math outputs TeX
|
||||||
parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
|
parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
|
||||||
os << '$';
|
os << '$';
|
||||||
}
|
}
|
||||||
@ -699,12 +701,14 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
|
|||||||
|
|
||||||
else if (t.cs() == "(") {
|
else if (t.cs() == "(") {
|
||||||
os << "\\(";
|
os << "\\(";
|
||||||
|
// This does only work because parse_math outputs TeX
|
||||||
parse_math(p, os, FLAG_SIMPLE2, MATH_MODE);
|
parse_math(p, os, FLAG_SIMPLE2, MATH_MODE);
|
||||||
os << "\\)";
|
os << "\\)";
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs() == "[") {
|
else if (t.cs() == "[") {
|
||||||
os << "\\[";
|
os << "\\[";
|
||||||
|
// This does only work because parse_math outputs TeX
|
||||||
parse_math(p, os, FLAG_EQUATION, MATH_MODE);
|
parse_math(p, os, FLAG_EQUATION, MATH_MODE);
|
||||||
os << "\\]";
|
os << "\\]";
|
||||||
}
|
}
|
||||||
@ -713,12 +717,10 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
|
|||||||
string const name = p.getArg('{', '}');
|
string const name = p.getArg('{', '}');
|
||||||
active_environments.push_back(name);
|
active_environments.push_back(name);
|
||||||
os << "\\begin{" << name << '}';
|
os << "\\begin{" << name << '}';
|
||||||
if (is_math_env(name)) {
|
// treat the nested environment as a block, don't
|
||||||
parse_math(p, os, FLAG_END, MATH_MODE);
|
// parse &, \\ etc, because they don't belong to our
|
||||||
} else {
|
// table if they appear.
|
||||||
parse_table(p, os, is_long_tabular, pos,
|
os << p.verbatimEnvironment(name);
|
||||||
FLAG_END);
|
|
||||||
}
|
|
||||||
os << "\\end{" << name << '}';
|
os << "\\end{" << name << '}';
|
||||||
active_environments.pop_back();
|
active_environments.pop_back();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ using std::endl;
|
|||||||
using std::fill;
|
using std::fill;
|
||||||
using std::istream;
|
using std::istream;
|
||||||
using std::istringstream;
|
using std::istringstream;
|
||||||
|
using std::ostringstream;
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
@ -323,6 +324,36 @@ string Parser::getOpt()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string const Parser::verbatimEnvironment(string const & name)
|
||||||
|
{
|
||||||
|
if (!good())
|
||||||
|
return string();
|
||||||
|
|
||||||
|
ostringstream os;
|
||||||
|
for (Token t = get_token(); good(); t = get_token()) {
|
||||||
|
if (t.cat() == catBegin) {
|
||||||
|
putback();
|
||||||
|
os << '{' << verbatim_item() << '}';
|
||||||
|
} else if (t.asInput() == "\\begin") {
|
||||||
|
string const env = getArg('{', '}');
|
||||||
|
os << "\\begin{" << env << '}'
|
||||||
|
<< verbatimEnvironment(env)
|
||||||
|
<< "\\end{" << env << '}';
|
||||||
|
} else if (t.asInput() == "\\end") {
|
||||||
|
string const end = getArg('{', '}');
|
||||||
|
if (end != name)
|
||||||
|
cerr << "\\end{" << end
|
||||||
|
<< "} does not match \\begin{" << name
|
||||||
|
<< "}." << endl;
|
||||||
|
return os.str();
|
||||||
|
} else
|
||||||
|
os << t.asInput();
|
||||||
|
}
|
||||||
|
cerr << "unexpected end of input" << endl;
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Parser::tokenize(istream & is)
|
void Parser::tokenize(istream & is)
|
||||||
{
|
{
|
||||||
static bool init_done = false;
|
static bool init_done = false;
|
||||||
|
@ -150,6 +150,12 @@ public:
|
|||||||
std::string getFullOpt();
|
std::string getFullOpt();
|
||||||
/// \returns getArg('[', ']') including the brackets
|
/// \returns getArg('[', ']') including the brackets
|
||||||
std::string getOpt();
|
std::string getOpt();
|
||||||
|
/*!
|
||||||
|
* \returns the contents of the environment \p name.
|
||||||
|
* <tt>\begin{name}</tt> must be parsed already, <tt>\end{name}</tt>
|
||||||
|
* is parsed but not returned.
|
||||||
|
*/
|
||||||
|
std::string const verbatimEnvironment(std::string const & name);
|
||||||
/// Returns the character of the current token and increments the token position.
|
/// Returns the character of the current token and increments the token position.
|
||||||
char getChar();
|
char getChar();
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user