4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
19 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE, MATHTEXT_MODE, TABLE_MODE};
21 mode_type asMode(mode_type oldmode, std::string const & str);
24 // These are TeX's catcodes
26 catEscape, // 0 backslash
37 catLetter, // 11 a-zA-Z
38 catOther, // 12 none of the above
41 catInvalid // 15 <delete>
45 CatCode catcode(unsigned char c);
49 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
50 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
51 FLAG_END = 1 << 3, // next \\end ends the parsing process
52 FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
53 FLAG_TEXTMODE = 1 << 5, // we are in a box
54 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
55 FLAG_LEAVE = 1 << 7, // leave the loop at the end
56 FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
57 FLAG_EQUATION = 1 << 9, // next \] leaves the loop
58 FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
59 FLAG_OPTION = 1 << 11, // read [...] style option
60 FLAG_BRACED = 1 << 12, // read {...} style argument
61 FLAG_CELL = 1 << 13, // read table cell
62 FLAG_TABBING = 1 << 14 // We are inside a tabbing environment
68 // Helper class for parsing
74 Token() : cs_(), char_(0), cat_(catIgnore) {}
76 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
78 Token(std::string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
81 std::string const & cs() const { return cs_; }
83 CatCode cat() const { return cat_; }
85 char character() const { return char_; }
87 std::string asString() const;
89 std::string asInput() const;
100 std::ostream & operator<<(std::ostream & os, Token const & t);
104 // Actual parser class
111 Parser(std::istream & is);
113 Parser(std::string const & s);
116 int lineno() const { return lineno_; }
119 /// dump contents to screen
123 std::string getArg(char left, char right);
124 /// getArg('[', ']') including the brackets
125 std::string getOpt();
129 void error(std::string const & msg);
131 void tokenize(std::istream & is);
133 void push_back(Token const & t);
137 Token const & prev_token() const;
139 Token const & next_token() const;
141 Token const & get_token();
142 /// skips spaces if any
145 void lex(std::string const & s);
149 std::string verbatim_item();
151 std::string verbatimOption();
152 /// resets the parser to initial state
155 void setCatCode(char c, CatCode cat);
157 CatCode getCatCode(char c) const;
163 std::vector<Token> tokens_;