]> git.lyx.org Git - lyx.git/blobdiff - src/Lexer.h
Account for old versions of Pygments
[lyx.git] / src / Lexer.h
index 5419fab778afad6965a63863c24163cf4ba2c83c..6335fac8da28fc0dd258ba6726051c996d616002 100644 (file)
@@ -5,7 +5,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Alejandro Aguilar Sierra
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -18,7 +18,7 @@
 #define LEXER_H
 
 #include "support/strfwd.h"
-
+#include <string>
 
 namespace lyx {
 
@@ -64,10 +64,10 @@ class Lexer
 {
 public:
        /// initialize Lexer with no special keywords.
-       Lexer(); 
+       Lexer();
        /// initialize Lexer with a bunch of keywords
        template<int N> Lexer(LexerKeyword (&table)[N])
-               : pimpl_(0) { init(table, N); }
+       : pimpl_(0), lastReadOk_(false) { init(table, N); }
 
        ///
        ~Lexer();
@@ -110,16 +110,20 @@ public:
        /// returns a lex code
        int lex();
 
-       /** Just read the next word. If esc is true remember that
-           some chars might be escaped: "\ atleast
-       */
+       /// Read the next string, as delimited by double quotes or 
+       /// whitespace. If esc is true, then we remember that some chars 
+       /// might be escaped: \" at least.
        bool next(bool esc = false);
 
-       /** Read next token. This one is almost the same as next,
-           but it will consider " as a regular character and always
-           split a word if it contains a backslash.
-       */
+       /// Read next token. This one is almost the same as next(),
+       /// but it will consider " as a regular character and always
+       /// split a word if it contains a backslash.
        bool nextToken();
+
+       /// Puts the rest of the line in the buffer, where it will 
+       /// be available via getString() or getDocString().
+       bool eatLine();
+
        /// Push a token, that next token got from lyxlex.
        void pushToken(std::string const &);
 
@@ -133,11 +137,9 @@ public:
        ///
        double getFloat() const;
        ///
-       std::string const getString() const;
-
+       std::string const getString(bool trim = false) const;
        ///
-       docstring const getDocString() const;
-
+       docstring const getDocString(bool trim = false) const;
        /** Get a long string, ended by the tag `endtag'.
            This string can span several lines. The first line
            serves as a template for how many spaces the lines
@@ -145,10 +147,7 @@ public:
            each following line. This mechanism does not work
            perfectly if you use tabs.
        */
-       std::string const getLongString(std::string const & endtag);
-
-       ///
-       bool eatLine();
+       docstring getLongString(docstring const & endtag);
 
        /// Pushes a token list on a stack and replaces it with a new one.
        template<int N> void pushTable(LexerKeyword (&table)[N])
@@ -167,6 +166,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 +181,20 @@ 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 &);
+       /// Quotes a docstring so that reading it again with Lexer::next(true)
+       /// gets the original string
+       static docstring quoteString(docstring const &);
 
 private:
        /// noncopyable
@@ -206,6 +217,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