Warning, file /office/kile/src/parser/bibtexparser.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /**********************************************************************************
0002 *   Copyright (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)           *
0003 *                 2005-2007 by Holger Danielsson (holger.danielsson@versanet.de)  *
0004 *                 2006-2011 by Michel Ludwig (michel.ludwig@kdemail.net)          *
0005 ***********************************************************************************/
0006 
0007 /***************************************************************************
0008  *                                                                         *
0009  *   This program is free software; you can redistribute it and/or modify  *
0010  *   it under the terms of the GNU General Public License as published by  *
0011  *   the Free Software Foundation; either version 2 of the License, or     *
0012  *   (at your option) any later version.                                   *
0013  *                                                                         *
0014  ***************************************************************************/
0015 
0016 #include "bibtexparser.h"
0017 
0018 #include <QFileInfo>
0019 #include <QRegExp>
0020 #include <QDebug>
0021 
0022 #include <KLocalizedString>
0023 
0024 #include "kiledebug.h"
0025 #include "codecompletion.h"
0026 #include "parserthread.h"
0027 
0028 namespace KileParser {
0029 
0030 BibTeXParserInput::BibTeXParserInput(const QUrl &url, const QStringList &textLines)
0031     : ParserInput(url),
0032       textLines(textLines)
0033 {
0034 }
0035 
0036 BibTeXParserOutput::BibTeXParserOutput()
0037 {
0038 }
0039 
0040 BibTeXParserOutput::~BibTeXParserOutput()
0041 {
0042     qCDebug(LOG_KILE_PARSER);
0043 }
0044 
0045 BibTeXParser::BibTeXParser(ParserThread *parserThread, BibTeXParserInput *input, QObject *parent)
0046     : Parser(parserThread, parent),
0047       m_textLines(input->textLines)
0048 {
0049 }
0050 
0051 BibTeXParser::~BibTeXParser()
0052 {
0053     qCDebug(LOG_KILE_PARSER);
0054 }
0055 
0056 ParserOutput* BibTeXParser::parse()
0057 {
0058     BibTeXParserOutput *parserOutput = new BibTeXParserOutput();
0059 
0060     qCDebug(LOG_KILE_PARSER);
0061 
0062     static QRegExp reItem("^(\\s*)@([a-zA-Z]+)");
0063     static QRegExp reSpecial("string|preamble|comment");
0064 
0065     QString key;
0066     int col = 0, startcol, startline = 0;
0067 
0068 //  emit(parsingStarted(m_doc->lines()));
0069     for(int i = 0; i < m_textLines.size(); ++i) {
0070         if(!m_parserThread->shouldContinueDocumentParsing()) {
0071             qCDebug(LOG_KILE_PARSER) << "stopping...";
0072             delete(parserOutput);
0073             return Q_NULLPTR;
0074         }
0075 //      emit(parsingUpdate(i));
0076         QString s = getTextLine(m_textLines, i);
0077         if((s.indexOf(reItem) != -1) && !reSpecial.exactMatch(reItem.cap(2).toLower())) {
0078             qCDebug(LOG_KILE_PARSER) << "found: " << reItem.cap(2);
0079             //start looking for key
0080             key = "";
0081             bool keystarted = false;
0082             int state = 0;
0083             startcol = reItem.cap(1).length();
0084             col  = startcol + reItem.cap(2).length();
0085 
0086             while(col < static_cast<int>(s.length())) {
0087                 ++col;
0088                 if(col == static_cast<int>(s.length())) {
0089                     do {
0090                         ++i;
0091                         s = getTextLine(m_textLines, i);
0092                     }
0093                     while((s.length() == 0) && (i < m_textLines.size()));
0094 
0095                     if(i == m_textLines.size()) {
0096                         break;
0097                     }
0098                     col = 0;
0099                 }
0100 
0101                 if(state == 0) {
0102                     if(s[col] == '{') {
0103                         state = 1;
0104                     }
0105                     else if(!s[col].isSpace()) {
0106                         break;
0107                     }
0108                 }
0109                 else if(state == 1) {
0110                     if(s[col] == ',') {
0111                         key = key.trimmed();
0112                         qCDebug(LOG_KILE_PARSER) << "found: " << key;
0113                         parserOutput->bibItems.append(key);
0114                         parserOutput->structureViewItems.push_back(new StructureViewItem(key, startline+1, startcol, KileStruct::BibItem, 0, startline+1, startcol, "viewbib", reItem.cap(2).toLower()));
0115                         break;
0116                     }
0117                     else {
0118                         key += s[col];
0119                         if(!keystarted) {
0120                             startcol = col;
0121                             startline = i;
0122                         }
0123                         keystarted = true;
0124                     }
0125                 }
0126             }
0127         }
0128     }
0129 
0130     return parserOutput;;
0131 }
0132 
0133 
0134 }
0135