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.
27 Generalized simple lexical analizer.
28 It can be used for simple syntax parsers, like lyxrc,
29 texclass and others to come.
30 See lyxrc.C for an example of usage.
35 LyXLex (keyword_item *, int);
51 /// file is open and end of file is not reached
53 /// return true if able to open file, else false
54 bool setFile(string const & filename);
56 void setStream(std::istream & i);
58 std::istream & getStream();
59 /// Danger! Don't use it unless you know what you are doing.
60 void setLineNo(int 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.
74 /// Push a token, that next token got from lyxlex.
75 void pushToken(string const &);
78 int GetLineNo() const;
81 int GetInteger() const;
85 float GetFloat() const;
87 string const GetString() const;
90 * Get a long string, ended by the tag `endtag'
91 * This string can span several lines. The first line
92 * serves as a template for how many spaces the lines
93 * are indented. This much white space is skipped from
94 * each following line. This mechanism does not work
95 * perfectly if you use tabs.
97 string getLongString(string const & endtag);
102 int FindToken(char const * str[]);
104 int CheckToken(char const * str[], int print_error);
107 char const * text() const;
109 /** Pushes a token list on a stack and replaces it with a new one.
111 void pushTable(keyword_item *, int);
113 /** Pops a token list into void and replaces it with the one now
118 /** Prints an error message with the corresponding line number
119 and file name. If message contains the substring `$$Token',
120 it is replaced with the value of GetString()
122 void printError(string const & message) const;
125 Prints the current token table on the supplied ostream.
127 void printTable(std::ostream &);
134 // This is needed to ensure that the pop is done upon exit from methods
135 // with more than one exit point or that can return as a response to
137 struct pushpophelper {
138 pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) {
146 // To avoid wrong usage:
147 // pushpophelper(...); // wrong
148 // pushpophelper pph(...); // right
149 // we add this macro:
150 #define pushpophelper(x, y, z) unnamed_pushpophelper;
151 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal