8 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE, MATHTEXT_MODE};
10 mode_type asMode(mode_type oldmode, string const & str);
13 // These are TeX's catcodes
15 catEscape, // 0 backslash
26 catLetter, // 11 a-zA-Z
27 catOther, // 12 none of the above
30 catInvalid // 15 <delete>
34 CatCode catcode(unsigned char c);
38 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
39 FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
40 FLAG_END = 1 << 3, // next \\end ends the parsing process
41 FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
42 FLAG_TEXTMODE = 1 << 5, // we are in a box
43 FLAG_ITEM = 1 << 6, // read a (possibly braced token)
44 FLAG_LEAVE = 1 << 7, // leave the loop at the end
45 FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
46 FLAG_EQUATION = 1 << 9, // next \] leaves the loop
47 FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
48 FLAG_OPTION = 1 << 11, // read [...] style option
49 FLAG_BRACED = 1 << 12 // read {...} style argument
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);
101 int lineno() const { return lineno_; }
104 /// dump contents to screen
108 string getArg(char left, char right);
112 void error(string const & msg);
114 void tokenize(std::istream & is);
116 void push_back(Token const & t);
120 Token const & prevToken() const;
122 Token const & nextToken() const;
124 Token const & getToken();
125 /// skips spaces if any
128 void lex(string const & s);
132 string verbatimItem();
134 string verbatimOption();
140 std::vector<Token> tokens_;