X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLexer.h;h=7f1f1a00f091735cfaf6105b74ab05b144d92392;hb=4a75fe0310ac64a079edab0c07d8f8eebaf519c0;hp=5419fab778afad6965a63863c24163cf4ba2c83c;hpb=c88e7a7ef66a880b5fb6166ff9151001269bc7cd;p=lyx.git diff --git a/src/Lexer.h b/src/Lexer.h index 5419fab778..7f1f1a00f0 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -111,7 +111,7 @@ public: int lex(); /** Just read the next word. If esc is true remember that - some chars might be escaped: "\ atleast + some chars might be escaped: "\ at least */ bool next(bool esc = false); @@ -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 &); @@ -180,10 +182,17 @@ public: Lexer & operator>>(unsigned int &); /// extract bool Lexer & operator>>(bool &); + /// extract first char of the string + Lexer & operator>>(char &); + + /// read and check a required token + Lexer & operator>>(char const * required); + /// check for an optional token and swallow it if present. + bool checkFor(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 +215,16 @@ private: }; +/// extract something constructable from a string, i.e. a LaTeX length +template +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