diff --git a/texpp/base/base.cc b/texpp/base/base.cc index 39a6b26..c62f2cd 100644 --- a/texpp/base/base.cc +++ b/texpp/base/base.cc @@ -78,7 +78,7 @@ void initSymbols(Parser& parser) __TEXPP_SET_COMMAND("ifvbox", Ifvbox); __TEXPP_SET_COMMAND("ifcase", Ifcase); - + __TEXPP_SET_COMMAND("ifeof", Ifeof); __TEXPP_SET_COMMAND("or", ConditionalOr); @@ -115,7 +115,9 @@ void initSymbols(Parser& parser) __TEXPP_SET_COMMAND("write", Write); __TEXPP_SET_COMMAND("message", Message); - + + __TEXPP_SET_COMMAND("bibitem", Bibitem); + // various commands __TEXPP_SET_COMMAND("end", End); __TEXPP_SET_COMMAND("par", Par); diff --git a/texpp/base/files.cc b/texpp/base/files.cc index c3f7f2e..33a39e6 100644 --- a/texpp/base/files.cc +++ b/texpp/base/files.cc @@ -119,7 +119,7 @@ bool Read::invokeWithPrefixes(Parser& parser, shared_ptr node, Token::ptr ltoken = tokenNode->value(Token::ptr()); // Get assosiated lexer - InFile infile = + InFile infile = parser.symbol("read" + boost::lexical_cast(stream), InFile()); shared_ptr lexer = infile.lexer; @@ -190,7 +190,7 @@ bool Read::invokeWithPrefixes(Parser& parser, shared_ptr node, } if(infile.lexer) parser.setSymbol("read" + boost::lexical_cast(stream), - InFile(), true); + InFile(), true); } // sync if reading from the terminal @@ -383,7 +383,7 @@ bool Write::invokeWithPrefixes(Parser& parser, parser.setMode(prevMode); node->appendChild("text", text); - + string str; Token::list_ptr tokens = text->child("balanced_text")->value(Token::list_ptr()); @@ -405,7 +405,7 @@ bool Write::invokeWithPrefixes(Parser& parser, */ } - OutFile outfile = + OutFile outfile = parser.symbol("write" + boost::lexical_cast(stream), OutFile()); if(outfile.ostream) { @@ -425,7 +425,7 @@ bool Message::invoke(Parser& parser, Node::ptr node) Node::ptr text = parser.parseGeneralText(true); node->appendChild("text", text); - + string str; Token::list_ptr tokens = text->child("balanced_text")->value(Token::list_ptr()); @@ -452,6 +452,35 @@ bool Message::invoke(Parser& parser, Node::ptr node) return true; } +bool Bibitem::invoke(Parser& parser, Node::ptr node) +{ + // TODO: implement + using boost::lexical_cast; + // TODO: expand text later + + Node::ptr text = parser.parseGeneralText(true); + node->appendChild("text", text); + + string str; + Token::list_ptr tokens = + text->child("balanced_text")->value(Token::list_ptr()); + + ++m_num; + if(tokens) { + // lexical_cast(m_num); + str = Token::texReprList(*tokens, &parser); + size_t pos = 0; + while((pos = str.find("\\bibitem ", pos)) != string::npos) { + ++m_num; + ++pos; + } + } + + // TODO: implement + parser.logger()->log(Logger::MESSAGE, string("bibitems count: ") + lexical_cast(m_num), parser, parser.lastToken()); + return true; +} + bool Input::invoke(Parser& parser, shared_ptr node) { Node::ptr fnameNode = parser.parseFileName(); diff --git a/texpp/base/files.h b/texpp/base/files.h index b728766..2ecfcdb 100644 --- a/texpp/base/files.h +++ b/texpp/base/files.h @@ -105,6 +105,15 @@ class Message: public Command bool invoke(Parser& parser, shared_ptr node); }; +class Bibitem: public Command +{ +public: + explicit Bibitem(const string& name): Command(name), m_num(0) {} + bool invoke(Parser& parser, shared_ptr node); +private: + size_t m_num; +}; + class Input: public Command { public: diff --git a/texpp/base/show.cc b/texpp/base/show.cc index e7c95d7..1923df0 100644 --- a/texpp/base/show.cc +++ b/texpp/base/show.cc @@ -84,6 +84,7 @@ bool parseThe(Parser& parser, shared_ptr node, bool show) Command::ptr c = parser.prevCommand(); if(dynamic_pointer_cast(c) || dynamic_pointer_cast(c) || + dynamic_pointer_cast(c) || (dynamic_pointer_cast(c) && static_pointer_cast(c)->expand())) { parser.addNoexpand((*toks_copy)[n]); diff --git a/texpp/parser.cc b/texpp/parser.cc index e06fc3a..5fd3392 100644 --- a/texpp/parser.cc +++ b/texpp/parser.cc @@ -263,7 +263,7 @@ void Parser::init() shared_ptr(new NullLogger); base::initSymbols(*this); - + string banner = BANNER; if(!lexer()->interactive()) { char t[256]; @@ -476,7 +476,7 @@ Node::ptr Parser::rawExpandToken(Token::ptr token) child->setValue(token); node->appendChild("control_sequence", child); bool expanded = true; - + pushBack(NULL); if(m_conditionals.empty() || m_conditionals.back().active) @@ -769,7 +769,7 @@ Token::ptr Parser::nextToken(vector< Token::ptr >* tokens, bool expand) } if(tokens) tokens->push_back(token); - + if(token->isLastInLine()) { break; } @@ -817,7 +817,7 @@ Token::ptr Parser::peekToken(bool expand) m_logger->log(Logger::ERROR, "Text line contains an invalid character", *this, token); } - + tokenSource.push_back(token); } @@ -845,7 +845,7 @@ Token::ptr Parser::peekToken(bool expand) } tokenSource.push_back(token); - + if(token->isLastInLine()) { break; } @@ -1014,7 +1014,7 @@ Node::ptr Parser::parseFalseConditional(size_t level, bool sElse, bool sOr) while((token = peekToken(false)) && m_conditionals.size() >= level) { Command::ptr cmd = symbol(token, Command::ptr()); nextToken(&node->tokens(), false); - + if(dynamic_pointer_cast(cmd)) { ConditionalInfo cinfo; cinfo.parsed = false; @@ -1322,14 +1322,14 @@ Node::ptr Parser::parseNormalInteger() resetNoexpand(); return node; } - + int result = 0; int digits = 0; if(peekToken()->isCharacter('\"', Token::CC_OTHER)) { nextToken(&node->tokens()); - while(peekToken() && ( + while(peekToken() && ( (peekToken()->isCharacterCat(Token::CC_OTHER) && std::isxdigit(peekToken()->value()[0]) && !std::islower(peekToken()->value()[0])) || @@ -1354,7 +1354,7 @@ Node::ptr Parser::parseNormalInteger() } else if(peekToken()->isCharacter('\'', Token::CC_OTHER)) { nextToken(&node->tokens()); - while(peekToken() && + while(peekToken() && peekToken()->isCharacterCat(Token::CC_OTHER) && std::isdigit(peekToken()->value()[0]) && peekToken()->value()[0] < '8') { @@ -1372,7 +1372,7 @@ Node::ptr Parser::parseNormalInteger() } } else { - while(peekToken() && + while(peekToken() && peekToken()->isCharacterCat(Token::CC_OTHER) && std::isdigit(peekToken()->value()[0])) { if(result != TEXPP_INT_INV) { @@ -1736,7 +1736,7 @@ Node::ptr Parser::parseDimenFactor() int frac = 0; int digits = 0; - while(peekToken() && + while(peekToken() && peekToken()->isCharacterCat(Token::CC_OTHER) && std::isdigit(peekToken()->value()[0])) { if(result != TEXPP_INT_INV) { @@ -1758,9 +1758,9 @@ Node::ptr Parser::parseDimenFactor() if(peekToken() && (peekToken()->isCharacter('.', Token::CC_OTHER) || peekToken()->isCharacter(',', Token::CC_OTHER))) { nextToken(&node->tokens()); ++digits; - + string fracDigits; - while(peekToken() && + while(peekToken() && peekToken()->isCharacterCat(Token::CC_OTHER) && std::isdigit(peekToken()->value()[0])) { if(fracDigits.size() < 17) @@ -1780,7 +1780,7 @@ Node::ptr Parser::parseDimenFactor() "Missing number, treated as zero", *this, lastToken()); } - + node->setValue(std::make_pair(int(result), frac)); resetNoexpand(); return node; @@ -2150,6 +2150,7 @@ void Parser::traceCommand(Token::ptr token, bool expanding) if(mode() == NULLMODE || dynamic_pointer_cast(c) || dynamic_pointer_cast(c) || + dynamic_pointer_cast(c) || (dynamic_pointer_cast(c) && static_pointer_cast(c)->expand())) { return; @@ -2365,7 +2366,7 @@ Node::ptr Parser::parseGroup(GroupType groupType) t = Token::create(Token::TOK_CHARACTER, Token::CC_MATHSHIFT, "$"); } else if(groupType == GROUP_DMATH) { - logger()->log(Logger::ERROR, + logger()->log(Logger::ERROR, "Missing $ inserted", *this, lastToken()); msg = "Display math should end with $$"; t = Token::create(Token::TOK_CHARACTER, @@ -2450,7 +2451,7 @@ Node::ptr Parser::parse() setMode(VERTICAL); Node::ptr document = parseGroup(GROUP_DOCUMENT); document->setType("document"); - + // Some skipped tokens may still exists even when // peekToken reports EOF. Lets add that tokens to the last node. Node::ptr node = document;