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/LIstream.h"
18 #include "support/LOstream.h"
31 Generalized simple lexical analizer.
32 It can be used for simple syntax parsers, like lyxrc,
33 texclass and others to come.
34 See lyxrc.C for an example of usage.
39 LyXLex (keyword_item *, int);
53 /// file is open and end of file is not reached
55 /// return true if able to open file, else false
56 bool setFile(string const & filename);
58 void setStream(istream & i);
60 istream & getStream() { return is; }
61 /// Danger! Don't use it unless you know what you are doing.
62 void setLineNo(int l) { lineno = 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.
77 int GetLineNo() const { return lineno; }
79 int GetInteger() const;
83 float GetFloat() const;
85 string GetString() const;
87 /// get a long string, ended by the tag `endtag'
88 string getLongString(string const & endtag);
93 int FindToken(char const * str[]);
95 int CheckToken(char const * str[], int print_error);
98 char const * text() const { return &buff[0]; }
100 /** Pushes a token list on a stack and replaces it with a new one.
102 void pushTable(keyword_item *, int);
104 /** Pops a token list into void and replaces it with the one now
109 /** Prints an error message with the corresponding line number
110 and file name. If message contains the substring `$$Token',
111 it is replaced with the value of GetString()
113 void printError(string const & message) const;
116 Prints the current token table on the supplied ostream.
118 void printTable(ostream &);
127 struct pushed_table {
136 keyword_item * table_elem;
141 /// fb__ is only used to open files, the stream is accessed through is
143 /// the stream that we use.
150 keyword_item * table;
154 char buff[LEX_MAX_BUFF];
156 pushed_table * pushed;
158 int search_kw(char const * const) const;
165 bool LyXLex::IsOK() const
171 // This is needed to ensure that the pop is done upon exit from methods
172 // with more than one exit point or that can return as a response to
174 struct pushpophelper {
175 pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) {
183 // To avoid wrong usage:
184 // pushpophelper(...); // wrong
185 // pushpophelper pph(...); // right
186 // we add this macro:
187 #define pushpophelper(x, y, z) unnamed_pushpophelper;
188 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal