7 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE, MATHTEXT_MODE, TABLE_MODE};
9 mode_type asMode(mode_type oldmode, string const & str);
12 // These are TeX's catcodes
14 catEscape, // 0 backslash
25 catLetter, // 11 a-zA-Z
26 catOther, // 12 none of the above
29 catInvalid // 15 <delete>
33 CatCode catcode(unsigned char c);
37 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
38 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
39 FLAG_END = 1 << 3, // next \\end ends the parsing process
40 FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
41 FLAG_TEXTMODE = 1 << 5, // we are in a box
42 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
43 FLAG_LEAVE = 1 << 7, // leave the loop at the end
44 FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
45 FLAG_EQUATION = 1 << 9, // next \] leaves the loop
46 FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
47 FLAG_OPTION = 1 << 11, // read [...] style option
48 FLAG_BRACED = 1 << 12, // read {...} style argument
49 FLAG_CELL = 1 << 13 // read table cell
55 // Helper class for parsing
61 Token() : cs_(), char_(0), cat_(catIgnore) {}
63 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
65 Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
68 string const & cs() const { return cs_; }
70 CatCode cat() const { return cat_; }
72 char character() const { return char_; }
74 string asString() const;
76 string asInput() const;
87 std::ostream & operator<<(std::ostream & os, Token const & t);
91 // Actual parser class
98 Parser(std::istream & is);
100 Parser(string const & s);
103 int lineno() const { return lineno_; }
106 /// dump contents to screen
110 string getArg(char left, char right);
111 /// getArg('[', ']') including the brackets
116 void error(string const & msg);
118 void tokenize(std::istream & is);
120 void push_back(Token const & t);
124 Token const & prev_token() const;
126 Token const & next_token() const;
128 Token const & get_token();
129 /// skips spaces if any
132 void lex(string const & s);
136 string verbatim_item();
138 string verbatimOption();
141 void setCatCode(char c, CatCode cat);
143 CatCode getCatCode(char c) const;
149 std::vector<Token> tokens_;