Interpret divelist printing templates

This is a first step of an efford to get rid of the Grantlee dependency. This
implements template processing for those constructs used in our divelist and
statistics printing templates.

It implements a template parser for loops over dives, cylinders and year and
variable replacement. As the previous Grantlee code, it does not really use
Qt's QObject introspection capabilities but reuses the old long chain of
if-else-statements.

The grantlee code is not yet removed.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2020-08-21 13:24:10 +02:00 committed by Dirk Hohndel
parent b3e28eed5d
commit c9106b9dbe
2 changed files with 389 additions and 0 deletions

View file

@ -16,6 +16,13 @@ void find_all_templates();
void set_bundled_templates_as_read_only();
void copy_bundled_templates(QString src, QString dst, QStringList *templateBackupList);
enum token_t {LITERAL, FORSTART, FORSTOP, BLOCKSTART, BLOCKSTOP, IFSTART, IFSTOP, PARSERERROR};
struct token {
enum token_t type;
QString contents;
};
extern QList<QString> grantlee_templates, grantlee_statistics_templates;
class TemplateLayout : public QObject {
@ -30,6 +37,12 @@ public:
private:
print_options *printOptions;
template_options *templateOptions;
QList<token> lexer(QString input);
void parser(QList<token> tokenList, int &pos, QTextStream &out, QHash<QString, QVariant> options);
QVariant getValue(QString list, QString property, QVariant option);
QString translate(QString s, QHash<QString, QVariant> options);
signals:
void progressUpdated(int value);