Skip to content

"bibitem" command #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions texpp/base/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
39 changes: 34 additions & 5 deletions texpp/base/files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool Read::invokeWithPrefixes(Parser& parser, shared_ptr<Node> node,
Token::ptr ltoken = tokenNode->value(Token::ptr());

// Get assosiated lexer
InFile infile =
InFile infile =
parser.symbol("read" + boost::lexical_cast<string>(stream), InFile());

shared_ptr<Lexer> lexer = infile.lexer;
Expand Down Expand Up @@ -190,7 +190,7 @@ bool Read::invokeWithPrefixes(Parser& parser, shared_ptr<Node> node,
}
if(infile.lexer)
parser.setSymbol("read" + boost::lexical_cast<string>(stream),
InFile(), true);
InFile(), true);
}

// sync if reading from the terminal
Expand Down Expand Up @@ -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());
Expand All @@ -405,7 +405,7 @@ bool Write::invokeWithPrefixes(Parser& parser,
*/
}

OutFile outfile =
OutFile outfile =
parser.symbol("write" + boost::lexical_cast<string>(stream), OutFile());

if(outfile.ostream) {
Expand All @@ -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());
Expand All @@ -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<string>(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<string>(m_num), parser, parser.lastToken());
return true;
}

bool Input::invoke(Parser& parser, shared_ptr<Node> node)
{
Node::ptr fnameNode = parser.parseFileName();
Expand Down
9 changes: 9 additions & 0 deletions texpp/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ class Message: public Command
bool invoke(Parser& parser, shared_ptr<Node> node);
};

class Bibitem: public Command
{
public:
explicit Bibitem(const string& name): Command(name), m_num(0) {}
bool invoke(Parser& parser, shared_ptr<Node> node);
private:
size_t m_num;
};

class Input: public Command
{
public:
Expand Down
1 change: 1 addition & 0 deletions texpp/base/show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ bool parseThe(Parser& parser, shared_ptr<Node> node, bool show)
Command::ptr c = parser.prevCommand();
if(dynamic_pointer_cast<base::Write>(c) ||
dynamic_pointer_cast<base::Message>(c) ||
dynamic_pointer_cast<base::Bibitem>(c) ||
(dynamic_pointer_cast<base::Def>(c) &&
static_pointer_cast<base::Def>(c)->expand())) {
parser.addNoexpand((*toks_copy)[n]);
Expand Down
33 changes: 17 additions & 16 deletions texpp/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void Parser::init()
shared_ptr<Logger>(new NullLogger);

base::initSymbols(*this);

string banner = BANNER;
if(!lexer()->interactive()) {
char t[256];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -769,7 +769,7 @@ Token::ptr Parser::nextToken(vector< Token::ptr >* tokens, bool expand)
}

if(tokens) tokens->push_back(token);

if(token->isLastInLine()) {
break;
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -845,7 +845,7 @@ Token::ptr Parser::peekToken(bool expand)
}

tokenSource.push_back(token);

if(token->isLastInLine()) {
break;
}
Expand Down Expand Up @@ -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<ConditionalBegin>(cmd)) {
ConditionalInfo cinfo;
cinfo.parsed = false;
Expand Down Expand Up @@ -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])) ||
Expand All @@ -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') {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -2150,6 +2150,7 @@ void Parser::traceCommand(Token::ptr token, bool expanding)
if(mode() == NULLMODE ||
dynamic_pointer_cast<base::Write>(c) ||
dynamic_pointer_cast<base::Message>(c) ||
dynamic_pointer_cast<base::Bibitem>(c) ||
(dynamic_pointer_cast<base::Def>(c) &&
static_pointer_cast<base::Def>(c)->expand())) {
return;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down