2 // Generalized simple lexical analizer.
3 // It can be used for simple syntax parsers, like lyxrc,
4 // texclass and others to come. [asierra30/03/96]
6 // Copyright 1996 Lyx Team.
17 #include "support/utility.hpp"
28 Generalized simple lexical analizer.
29 It can be used for simple syntax parsers, like lyxrc,
30 texclass and others to come.
31 See lyxrc.C for an example of usage.
33 class LyXLex : public noncopyable {
36 LyXLex (keyword_item *, int);
52 /// file is open and end of file is not reached
54 /// return true if able to open file, else false
55 bool setFile(string const & filename);
57 void setStream(std::istream & i);
59 std::istream & getStream();
60 /// Danger! Don't use it unless you know what you are doing.
61 void setLineNo(int l);
63 /// returns a lex code
66 /** Just read athe next word. If esc is true remember that
67 some chars might be escaped: "\ atleast */
68 bool next(bool esc = false);
70 /** Read next token. This one is almost the same as next,
71 but it will consider " as a regular character and always
72 split a word if it contains a backslash.
75 /// Push a token, that next token got from lyxlex.
76 void pushToken(string const &);
79 int GetLineNo() const;
82 int GetInteger() const;
86 float GetFloat() const;
88 string const GetString() const;
91 * Get a long string, ended by the tag `endtag'
92 * This string can span several lines. The first line
93 * serves as a template for how many spaces the lines
94 * are indented. This much white space is skipped from
95 * each following line. This mechanism does not work
96 * perfectly if you use tabs.
98 string const getLongString(string const & endtag);
103 int FindToken(char const * str[]);
105 int CheckToken(char const * str[], int print_error);
108 char const * const text() const;
110 /** Pushes a token list on a stack and replaces it with a new one.
112 void pushTable(keyword_item *, int);
114 /** Pops a token list into void and replaces it with the one now
119 /** Prints an error message with the corresponding line number
120 and file name. If message contains the substring `$$Token',
121 it is replaced with the value of GetString()
123 void printError(string const & message) const;
126 Prints the current token table on the supplied ostream.
128 void printTable(std::ostream &);
135 // This is needed to ensure that the pop is done upon exit from methods
136 // with more than one exit point or that can return as a response to
138 struct pushpophelper {
139 pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) {
147 // To avoid wrong usage:
148 // pushpophelper(...); // wrong
149 // pushpophelper pph(...); // right
150 // we add this macro:
151 #define pushpophelper(x, y, z) unnamed_pushpophelper;
152 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal