+void Parser::catInit()
+{
+ if (curr_cat_ == theCatcodesType_)
+ return;
+ curr_cat_ = theCatcodesType_;
+
+ fill(theCatcode_, theCatcode_ + 256, catOther);
+ fill(theCatcode_ + 'a', theCatcode_ + 'z' + 1, catLetter);
+ fill(theCatcode_ + 'A', theCatcode_ + 'Z' + 1, catLetter);
+ // This is wrong!
+ theCatcode_[int('@')] = catLetter;
+
+ if (theCatcodesType_ == NORMAL_CATCODES) {
+ theCatcode_[int('\\')] = catEscape;
+ theCatcode_[int('{')] = catBegin;
+ theCatcode_[int('}')] = catEnd;
+ theCatcode_[int('$')] = catMath;
+ theCatcode_[int('&')] = catAlign;
+ theCatcode_[int('\n')] = catNewline;
+ theCatcode_[int('#')] = catParameter;
+ theCatcode_[int('^')] = catSuper;
+ theCatcode_[int('_')] = catSub;
+ theCatcode_[0x7f] = catIgnore;
+ theCatcode_[int(' ')] = catSpace;
+ theCatcode_[int('\t')] = catSpace;
+ theCatcode_[int('\r')] = catNewline;
+ theCatcode_[int('~')] = catActive;
+ theCatcode_[int('%')] = catComment;
+ }
+}
+
+CatCode Parser::catcode(char_type c) const
+{
+ if (c < 256)
+ return theCatcode_[(unsigned char)c];
+ return catOther;
+}
+
+
+void Parser::setCatcode(char c, CatCode cat)
+{
+ theCatcode_[(unsigned char)c] = cat;
+ deparse();
+}
+
+
+void Parser::setCatcodes(cat_type t)
+{
+ theCatcodesType_ = t;
+ deparse();
+}
+
+
+bool Parser::setEncoding(std::string const & e)
+{
+ //cerr << "setting encoding to " << e << std::endl;
+ encoding_iconv_ = e;
+ // If the encoding is fixed, we must not change the stream encoding
+ // (because the whole input uses that encoding, e.g. if it comes from
+ // the clipboard). We still need to track the original encoding in
+ // encoding_iconv_, so that the generated output is correct.
+ if (!fixed_enc_)
+ is_.setEncoding(e);
+ return true;
+}
+
+
+void Parser::push_back(Token const & t)
+{
+ tokens_.push_back(t);
+}
+
+
+// We return a copy here because the tokens_ vector may get reallocated
+Token const Parser::prev_token() const