KTextTemplate::Parser Class
class KTextTemplate::ParserThe Parser class processes a string template into a tree of nodes. More...
Header: | #include <KTextTemplate/Parser> |
CMake: | find_package(KF6 REQUIRED COMPONENTS TextTemplate) target_link_libraries(mytarget PRIVATE KF6::TextTemplate) |
Inherits: | QObject |
Public Functions
Parser(const QList<KTextTemplate::Token> &tokenList, QObject *parent) | |
QSharedPointer<KTextTemplate::Filter> | getFilter(const QString &name) const |
bool | hasNextToken() const |
KTextTemplate::NodeList | parse(KTextTemplate::Node *parent, const QString &stopAt) |
KTextTemplate::NodeList | parse(KTextTemplate::Node *parent, const QStringList &stopAt = {}) |
KTextTemplate::NodeList | parse(KTextTemplate::TemplateImpl *parent, const QStringList &stopAt = {}) |
void | removeNextToken() |
void | skipPast(const QString &tag) |
KTextTemplate::Token | takeNextToken() |
Protected Functions
void | prependToken(const KTextTemplate::Token &token) |
Detailed Description
For application developers, this class is internal.
For template tag authors it may be necessary to advance the parser and process contained tags if the tag works in a tag – endtag fashion.
Member Function Documentation
Parser::Parser(const QList<KTextTemplate::Token> &tokenList, QObject *parent)
Constructor.
Initialises the Parser with the tokenList.
QSharedPointer<KTextTemplate::Filter> Parser::getFilter(const QString &name) const
Returns the filter object called name or an invalid object if no filter with that name is loaded.
bool Parser::hasNextToken() const
Returns whether the parser has another token to process.
KTextTemplate::NodeList Parser::parse(KTextTemplate::Node *parent, const QString &stopAt)
This is an overloaded method.
KTextTemplate::NodeList Parser::parse(KTextTemplate::Node *parent, const QStringList &stopAt = {})
Advance the parser, using parent as the parent of new Nodes. The parser will stop if it encounters a tag which is contained in the list stopAt.
For example, the {% if %}
tag would stopAt both {% endif %}
and {% else %}
tags.
See also AbstractNodeFactory::getNode.
KTextTemplate::NodeList Parser::parse(KTextTemplate::TemplateImpl *parent, const QStringList &stopAt = {})
This is an overloaded method.
[protected]
void Parser::prependToken(const KTextTemplate::Token &token)
Puts the token token to the front of the list to be processed by the parser.
void Parser::removeNextToken()
Deletes the next token available to the parser.
void Parser::skipPast(const QString &tag)
Advances the parser to the tag tag. This method is similar to parse, but it does not create nodes for tags encountered.
KTextTemplate::Token Parser::takeNextToken()
Returns the next token to be processed by the parser. This can be examined in template tag implementations to determine why parsing stopped.
For example, if the {% if %}
tag, parsing may stop at an {% else %}
tag, in which case parsing should be restarted, or it could stop at an {% endif %}
tag, in which case parsing is finished for that node.