make Lexer interface a bit more friendly

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24108 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-04-03 22:38:14 +00:00
parent cda83b2a62
commit 193c25946b
2 changed files with 37 additions and 2 deletions

View File

@ -102,6 +102,8 @@ public:
string pushTok;
///
char commentChar;
/// used for error messages
string context;
private:
/// non-copyable
Pimpl(Pimpl const &);
@ -878,7 +880,7 @@ Lexer & Lexer::operator>>(bool & s)
// quotes a string, e.g. for use in preferences files or as an argument
// of the "log" dialog
string const Lexer::quoteString(string const & arg)
string Lexer::quoteString(string const & arg)
{
string res;
res += '"';
@ -888,4 +890,22 @@ string const Lexer::quoteString(string const & arg)
}
Lexer & Lexer::operator>>(char const * required)
{
string token;
*this >> token;
if (token != required) {
LYXERR0("Missing '" << required << "'-tag in " << pimpl_->context);
pushToken(token);
}
return *this;
}
void Lexer::setContext(std::string const & str)
{
pimpl_->context = str;
}
} // namespace lyx

View File

@ -167,6 +167,8 @@ public:
/// Prints the current token table on the supplied ostream.
void printTable(std::ostream &);
/// Used to dispaly context information in case of errors.
void setContext(std::string const & functionName);
/// extract string
Lexer & operator>>(std::string &);
@ -181,9 +183,12 @@ public:
/// extract bool
Lexer & operator>>(bool &);
/// read and check a required token
Lexer & operator>>(char const * required);
/// Quotes a string so that reading it again with Lexer::next(true)
/// gets the original string
static std::string const quoteString(std::string const &);
static std::string quoteString(std::string const &);
private:
/// noncopyable
@ -206,6 +211,16 @@ private:
};
/// extract something constructable from a string, i.e. a LaTeX length
template <class T>
Lexer & operator>>(Lexer & lex, T & t)
{
if (lex.next())
t = T(lex.getString());
return lex;
}
/** Use to enable multiple exit points.
This is needed to ensure that the pop is done upon exit from methods
with more than one exit point or that can return as a response to