8 enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE, MATHTEXT_MODE, TABLE_MODE};
10 mode_type asMode(mode_type oldmode, std::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
50 FLAG_CELL = 1 << 13 // read table cell
56 // Helper class for parsing
62 Token() : cs_(), char_(0), cat_(catIgnore) {}
64 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
66 Token(std::string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
69 std::string const & cs() const { return cs_; }
71 CatCode cat() const { return cat_; }
73 char character() const { return char_; }
75 std::string asString() const;
77 std::string asInput() const;
88 std::ostream & operator<<(std::ostream & os, Token const & t);
92 // Actual parser class
99 Parser(std::istream & is);
101 Parser(std::string const & s);
104 int lineno() const { return lineno_; }
107 /// dump contents to screen
111 std::string getArg(char left, char right);
112 /// getArg('[', ']') including the brackets
113 std::string getOpt();
117 void error(std::string const & msg);
119 void tokenize(std::istream & is);
121 void push_back(Token const & t);
125 Token const & prev_token() const;
127 Token const & next_token() const;
129 Token const & get_token();
130 /// skips spaces if any
133 void lex(std::string const & s);
137 std::string verbatim_item();
139 std::string verbatimOption();
142 void setCatCode(char c, CatCode cat);
144 CatCode getCatCode(char c) const;
150 std::vector<Token> tokens_;