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"
30 Generalized simple lexical analizer.
31 It can be used for simple syntax parsers, like lyxrc,
32 texclass and others to come.
33 See lyxrc.C for an example of usage.
38 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(istream & i);
59 istream & getStream() { return is; }
60 /// Danger! Don't use it unless you know what you are doing.
61 void setLineNo(int l) { lineno = l; }
62 /// returns a lex code
65 /** Just read athe next word. If esc is true remember that
66 some chars might be escaped: "\ atleast */
67 bool next(bool esc = false);
69 /** Read next token. This one is almost the same as next,
70 but it will consider " as a regular character and always
71 split a word if it contains a backslash.
76 int GetLineNo() const { return lineno; }
78 int GetInteger() const;
82 float GetFloat() const;
84 string GetString() const;
86 /// get a long string, ended by the tag `endtag'
87 string getLongString(string const & endtag);
92 int FindToken(char const * str[]);
94 int CheckToken(char const * str[], int print_error);
97 char const * text() const { return &buff[0]; }
99 /** Pushes a token list on a stack and replaces it with a new one.
101 void pushTable(keyword_item *, int);
103 /** Pops a token list into void and replaces it with the one now
108 /** Prints an error message with the corresponding line number
109 and file name. If message contains the substring `$$Token',
110 it is replaced with the value of GetString()
112 void printError(string const & message) const;
115 Prints the current token table on the supplied ostream.
117 void printTable(ostream &);
126 struct pushed_table {
135 keyword_item * table_elem;
140 /// fb__ is only used to open files, the stream is accessed through is
142 /// the stream that we use.
149 keyword_item * table;
153 char buff[LEX_MAX_BUFF];
155 pushed_table * pushed;
157 int search_kw(char const * const) const;
164 bool LyXLex::IsOK() const
170 // This is needed to ensure that the pop is done upon exit from methods
171 // with more than one exit point or that can return as a response to
173 struct pushpophelper {
174 pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) {
182 // To avoid wrong usage:
183 // pushpophelper(...); // wrong
184 // pushpophelper pph(...); // right
185 // we add this macro:
186 #define pushpophelper(x, y, z) unnamed_pushpophelper;
187 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal