KTextTemplate

parser.h
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10#ifndef KTEXTTEMPLATE_PARSER_H
11#define KTEXTTEMPLATE_PARSER_H
12
13#include "filter.h"
14#include "node.h"
15#include "token.h"
16
17#include <QStringList>
18
19namespace KTextTemplate
20{
21class TemplateImpl;
22
23class ParserPrivate;
24
25/// @headerfile parser.h <KTextTemplate/Parser>
26
27/**
28 @brief The **%Parser** class processes a string template into a tree of nodes.
29
30 For application developers, this class is internal.
31
32 For template tag authors it may be necessary to advance the parser and process
33 contained tags if the tag works in a tag -- endtag fashion.
34
35 @author Stephen Kelly <steveire@gmail.com>
36*/
37class KTEXTTEMPLATE_EXPORT Parser : public QObject
38{
39 Q_OBJECT
40public:
41 /**
42 Constructor.
43
44 Initialises the **%Parser** with the @p tokenList.
45 */
46 Parser(const QList<Token> &tokenList, QObject *parent);
47
48 /**
49 Destructor.
50 */
51 ~Parser() override;
52
53 /**
54 Advance the parser, using @p parent as the parent of new Nodes. The parser
55 will stop if it encounters a tag which is contained in the list @p stopAt.
56
57 For example, the @gr_tag{if} tag would stopAt both @gr_tag{endif} and
58 @gr_tag{else} tags.
59
60 @see AbstractNodeFactory::getNode
61 */
62 NodeList parse(Node *parent, const QStringList &stopAt = {});
63
64 /**
65 This is an overloaded method.
66 @see parse.
67 */
68 NodeList parse(TemplateImpl *parent, const QStringList &stopAt = {});
69
70 /**
71 This is an overloaded method.
72 @see parse.
73 */
74 NodeList parse(Node *parent, const QString &stopAt);
75
76 /**
77 Returns the filter object called @p name or an invalid object if no filter
78 with that name is loaded.
79 */
80 QSharedPointer<Filter> getFilter(const QString &name) const;
81
82 /**
83 Advances the parser to the tag @p tag. This method is similar to @ref parse,
84 but it does not create nodes for tags encountered.
85 */
86 void skipPast(const QString &tag);
87
88 /**
89 Returns the next token to be processed by the parser. This can be examined
90 in template tag implementations to determine why parsing stopped.
91
92 For example, if the @gr_tag{if} tag, parsing may stop at an @gr_tag{else}
93 tag, in which case parsing should be restarted, or it could stop at an
94 @gr_tag{endif} tag, in which case parsing is finished for that node.
95 */
96 Token takeNextToken();
97
98 /**
99 Returns whether the parser has another token to process.
100 */
101 bool hasNextToken() const;
102
103 /**
104 Deletes the next token available to the parser.
105 */
106 void removeNextToken();
107
108 void invalidBlockTag(const Token &token, const QString &command, const QStringList &stopAt = {});
109
110#ifndef K_DOXYGEN
111 /**
112 @internal
113
114 Used by the @gr_tag{load} tag to load libraries.
115 */
116 void loadLib(const QString &name);
117#endif
118
119protected:
120 /**
121 Puts the token @p token to the front of the list to be processed by the
122 parser.
123 */
124 void prependToken(const Token &token);
125
126private:
127 Q_DECLARE_PRIVATE(Parser)
128 ParserPrivate *const d_ptr;
129};
130}
131
132#endif
A list of Nodes with some convenience API for rendering them.
Definition node.h:141
Base class for all nodes.
Definition node.h:72
The Parser class processes a string template into a tree of nodes.
Definition parser.h:38
NodeList parse(TemplateImpl *parent, const QStringList &stopAt={})
This is an overloaded method.
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
A token in a parse stream for a template.
Definition token.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.