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]
26 Generalized simple lexical analizer.
27 It can be used for simple syntax parsers, like lyxrc,
28 texclass and others to come.
29 See lyxrc.C for an example of usage.
34 LyXLex (keyword_item*, int);
36 ~LyXLex() { if (file && owns_file) fclose(file); };
50 /// file is open and end of file is not reached
52 /// return true if able to open file, else false
53 bool setFile(string const & filename);
54 /// if file is already read from, line numbers will be wrong.
56 void setFile(FILE *f);
59 FILE *getFile() { return file; }
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() { return lineno; }
84 string GetString() const;
86 /// get a long string, ended by the tag `endtag'
87 string getLongString(string const &endtoken);
92 int FindToken(char const* string[]);
94 int CheckToken(char const* string[], 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);
115 Prints the current token table on cerr.
126 struct pushed_table {
135 keyword_item *table_elem;
153 char buff[LEX_MAX_BUFF];
155 pushed_table *pushed;
157 int search_kw(char const * const) const;
166 return (file && !feof(file));