4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
13 // Generalized simple lexical analizer.
14 // It can be used for simple syntax parsers, like lyxrc,
15 // texclass and others to come.
20 #include <boost/utility.hpp>
34 /** Generalized simple lexical analizer.
35 It can be used for simple syntax parsers, like lyxrc,
36 texclass and others to come.
37 @see lyxrc.C for an example of usage.
39 class LyXLex : boost::noncopyable {
42 LyXLex(keyword_item *, int);
58 /// file is open and end of file is not reached
60 /// return true if able to open file, else false
61 bool setFile(std::string const & filename);
63 void setStream(std::istream & is);
65 std::istream & getStream();
66 /// Danger! Don't use it unless you know what you are doing.
67 void setLineNo(int l);
68 /// Change the character that begins a comment. Default is '#'
69 void setCommentChar(char c);
71 /// returns a lex code
74 /** Just read athe next word. If esc is true remember that
75 some chars might be escaped: "\ atleast
77 bool next(bool esc = false);
79 /** Read next token. This one is almost the same as next,
80 but it will consider " as a regular character and always
81 split a word if it contains a backslash.
84 /// Push a token, that next token got from lyxlex.
85 void pushToken(std::string const &);
88 int getLineNo() const;
91 int getInteger() const;
95 float getFloat() const;
97 std::string const getString() const;
99 /** Get a long string, ended by the tag `endtag'.
100 This string can span several lines. The first line
101 serves as a template for how many spaces the lines
102 are indented. This much white space is skipped from
103 each following line. This mechanism does not work
104 perfectly if you use tabs.
106 std::string const getLongString(std::string const & endtag);
111 int findToken(char const * str[]);
113 /** Pushes a token list on a stack and replaces it with a new one.
115 void pushTable(keyword_item *, int);
117 /** Pops a token list into void and replaces it with the one now
122 /** Prints an error message with the corresponding line number
123 and file name. If message contains the substring `$$Token',
124 it is replaced with the value of GetString()
126 void printError(std::string const & message) const;
129 Prints the current token table on the supplied ostream.
131 void printTable(std::ostream &);
139 /** Use to enable multiple exit points.
140 This is needed to ensure that the pop is done upon exit from methods
141 with more than one exit point or that can return as a response to
145 struct pushpophelper {
147 pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) {
157 /** Avoid wrong usage of pushpophelper.
158 To avoid wrong usage:
159 pushpophelper(...); // wrong
160 pushpophelper pph(...); // right
162 #define pushpophelper(x, y, z) unnamed_pushpophelper;
163 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal