1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/***************************************************************************
* Copyright (C) 2004-2015 by Pere Constans
* constans@molspaces.com
* cb2Bib version 1.9.2. Licensed under the GNU GPL version 3.
* See the LICENSE file that comes with this distribution.
***************************************************************************/
#ifndef TEXPARSER_H
#define TEXPARSER_H
#include <QString>
#include <QTextStream>
/**
Minimalist TeX parser
*/
class texParser
{
public:
inline texParser() : _stop_parsing(false) {}
inline virtual ~texParser() {}
protected:
virtual void parseComment(const QString& /* p */) {}
virtual void parseElement(const QString& /* p */, const QString& /* e */, const QString& /* v */) {}
virtual void parseEmptyLine() {}
virtual void parseLaTeXMarkup(const QString& /* p */, const QString& /* e */) {}
virtual void parseTextParagraph(const QString& /* p */) {}
void parse(QString tex);
inline void stop()
{
_stop_parsing = true;
}
private:
QString _element;
QString _line;
QString _paragraph;
QTextStream _stream;
bool _stop_parsing;
void doElement();
void gotoEnd(const QString& e);
void gotoEndBraces(const QString& e);
void gotoEndMacro(const QString& e);
inline const QString& readLine(const bool trim = false)
{
if (trim)
_line = _stream.readLine().trimmed();
else
_line = _stream.readLine();
return _line;
}
inline void flushElement(const QString& e, const QString& v)
{
flush();
parseElement(_element, e, v);
}
inline void flushLaTeXMarkup(const QString& e)
{
_element = _line;
flush();
parseLaTeXMarkup(_element, e);
}
inline void flush()
{
if (_paragraph.isEmpty())
return;
parseTextParagraph(_paragraph.mid(1));
_paragraph.clear();
}
};
#endif
|