mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
printing: refactor if and loop code
The loop code was buggy: the current position was only increased inside when executing the loop once. This would obviously fail for empty lists. Moreover, the whole thing was quite difficult to reason about, since a reference to the current position was passed down in the call hierarchy. Instead, pass from and to values to the parse function and create a generic function that can search for the end of loop and if blocks. This function handles nested if and for loops. The if-code now formats the block only if the condition is true. The old code would format the block and throw it away if not needed. This should now provide better diagnostics for mismatched tags. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f42a70586b
commit
0310eb31da
2 changed files with 50 additions and 26 deletions
|
@ -51,9 +51,9 @@ private:
|
|||
const print_options &printOptions;
|
||||
const template_options &templateOptions;
|
||||
QList<token> lexer(QString input);
|
||||
void parser(QList<token> tokenList, int &pos, QTextStream &out, State &state);
|
||||
void parser(QList<token> tokenList, int from, int to, QTextStream &out, State &state);
|
||||
template<typename V, typename T>
|
||||
void parser_for(QList<token> tokenList, int &pos, QTextStream &out, State &state, const V &data, const T *&act);
|
||||
void parser_for(QList<token> tokenList, int from, int to, QTextStream &out, State &state, const V &data, const T *&act);
|
||||
QVariant getValue(QString list, QString property, const State &state);
|
||||
QString translate(QString s, State &state);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue