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.
13 #include <boost/utility.hpp>
23 /** Generalized simple lexical analizer.
24 It can be used for simple syntax parsers, like lyxrc,
25 texclass and others to come.
26 @see lyxrc.C for an example of usage.
28 class LyXLex : boost::noncopyable {
31 LyXLex(keyword_item *, int);
47 /// file is open and end of file is not reached
49 /// return true if able to open file, else false
50 bool setFile(string const & filename);
52 void setStream(std::istream & is);
54 std::istream & getStream();
55 /// Danger! Don't use it unless you know what you are doing.
56 void setLineNo(int l);
57 /// Change the character that begins a comment. Default is '#'
58 void setCommentChar(char c);
60 /// returns a lex code
63 /** Just read athe next word. If esc is true remember that
64 some chars might be escaped: "\ atleast
66 bool next(bool esc = false);
68 /** Read next token. This one is almost the same as next,
69 but it will consider " as a regular character and always
70 split a word if it contains a backslash.
73 /// Push a token, that next token got from lyxlex.
74 void pushToken(string const &);
77 int getLineNo() const;
80 int getInteger() const;
84 float getFloat() const;
86 string const getString() const;
88 /** Get a long string, ended by the tag `endtag'.
89 This string can span several lines. The first line
90 serves as a template for how many spaces the lines
91 are indented. This much white space is skipped from
92 each following line. This mechanism does not work
93 perfectly if you use tabs.
95 string const getLongString(string const & endtag);
100 int findToken(char const * str[]);
102 /** Pushes a token list on a stack and replaces it with a new one.
104 void pushTable(keyword_item *, int);
106 /** Pops a token list into void and replaces it with the one now
111 /** Prints an error message with the corresponding line number
112 and file name. If message contains the substring `$$Token',
113 it is replaced with the value of GetString()
115 void printError(string const & message) const;
118 Prints the current token table on the supplied ostream.
120 void printTable(std::ostream &);
128 /** Use to enable multiple exit points.
129 This is needed to ensure that the pop is done upon exit from methods
130 with more than one exit point or that can return as a response to
134 struct pushpophelper {
136 pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) {
146 /** Avoid wrong usage of pushpophelper.
147 To avoid wrong usage:
148 pushpophelper(...); // wrong
149 pushpophelper pph(...); // right
151 #define pushpophelper(x, y, z) unnamed_pushpophelper;
152 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal