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.
23 #include <boost/utility.hpp>
33 /** Generalized simple lexical analizer.
34 It can be used for simple syntax parsers, like lyxrc,
35 texclass and others to come.
36 @see lyxrc.C for an example of usage.
38 class LyXLex : boost::noncopyable {
41 LyXLex(keyword_item *, int);
57 /// file is open and end of file is not reached
59 /// return true if able to open file, else false
60 bool setFile(string const & filename);
62 void setStream(std::istream & is);
64 std::istream & getStream();
65 /// Danger! Don't use it unless you know what you are doing.
66 void setLineNo(int l);
67 /// Change the character that begins a comment. Default is '#'
68 void setCommentChar(char c);
70 /// returns a lex code
73 /** Just read athe next word. If esc is true remember that
74 some chars might be escaped: "\ atleast
76 bool next(bool esc = false);
78 /** Read next token. This one is almost the same as next,
79 but it will consider " as a regular character and always
80 split a word if it contains a backslash.
83 /// Push a token, that next token got from lyxlex.
84 void pushToken(string const &);
87 int getLineNo() const;
90 int getInteger() const;
94 float getFloat() const;
96 string const getString() const;
98 /** Get a long string, ended by the tag `endtag'.
99 This string can span several lines. The first line
100 serves as a template for how many spaces the lines
101 are indented. This much white space is skipped from
102 each following line. This mechanism does not work
103 perfectly if you use tabs.
105 string const getLongString(string const & endtag);
110 int findToken(char const * str[]);
112 /** Pushes a token list on a stack and replaces it with a new one.
114 void pushTable(keyword_item *, int);
116 /** Pops a token list into void and replaces it with the one now
121 /** Prints an error message with the corresponding line number
122 and file name. If message contains the substring `$$Token',
123 it is replaced with the value of GetString()
125 void printError(string const & message) const;
128 Prints the current token table on the supplied ostream.
130 void printTable(std::ostream &);
138 /** Use to enable multiple exit points.
139 This is needed to ensure that the pop is done upon exit from methods
140 with more than one exit point or that can return as a response to
144 struct pushpophelper {
146 pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) {
156 /** Avoid wrong usage of pushpophelper.
157 To avoid wrong usage:
158 pushpophelper(...); // wrong
159 pushpophelper pph(...); // right
161 #define pushpophelper(x, y, z) unnamed_pushpophelper;
162 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal