Cutelee  6.1.0
Public Member Functions | Protected Member Functions | List of all members
Cutelee::Parser Class Reference

The Parser class processes a string template into a tree of nodes. More...

#include <cutelee/parser.h>

Inheritance diagram for Cutelee::Parser:
Inheritance graph
[legend]

Public Member Functions

 Parser (const QList< Token > &tokenList, QObject *parent)
 
 ~Parser () override
 
std::shared_ptr< FiltergetFilter (const QString &name) const
 
bool hasNextToken () const
 
void invalidBlockTag (const Token &token, const QString &command, const QStringList &stopAt={})
 
NodeList parse (Node *parent, const QString &stopAt)
 
NodeList parse (Node *parent, const QStringList &stopAt={})
 
NodeList parse (TemplateImpl *parent, const QStringList &stopAt={})
 
void removeNextToken ()
 
void skipPast (const QString &tag)
 
Token takeNextToken ()
 

Protected Member Functions

void prependToken (const 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.

Author
Stephen Kelly steve.nosp@m.ire@.nosp@m.gmail.nosp@m..com

Definition at line 48 of file parser.h.

Constructor & Destructor Documentation

◆ Parser()

Parser::Parser ( const QList< Token > &  tokenList,
QObject *  parent 
)

Constructor.

Initialises the Parser with the tokenList.

Definition at line 90 of file parser.cpp.

References Cutelee::Engine::defaultLibraries().

◆ ~Parser()

Parser::~Parser ( )
override

Destructor.

Definition at line 111 of file parser.cpp.

Member Function Documentation

◆ getFilter()

std::shared_ptr< 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.

Definition at line 157 of file parser.cpp.

Referenced by Cutelee::FilterExpression::FilterExpression().

◆ hasNextToken()

bool Parser::hasNextToken ( ) const

Returns whether the parser has another token to process.

Definition at line 285 of file parser.cpp.

Referenced by skipPast().

◆ parse() [1/3]

NodeList Parser::parse ( Node parent,
const QString stopAt 
)

This is an overloaded method.

See also
parse.

Definition at line 168 of file parser.cpp.

◆ parse() [2/3]

NodeList Parser::parse ( 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

Definition at line 180 of file parser.cpp.

Referenced by AutoescapeNodeFactory::getNode(), FilterNodeFactory::getNode(), ForNodeFactory::getNode(), IfNodeFactory::getNode(), IfChangedNodeFactory::getNode(), RangeNodeFactory::getNode(), SpacelessNodeFactory::getNode(), WithNodeFactory::getNode(), WithLocaleNodeFactory::getNode(), BlockNodeFactory::getNode(), and ExtendsNodeFactory::getNode().

◆ parse() [3/3]

NodeList Cutelee::Parser::parse ( TemplateImpl *  parent,
const QStringList &  stopAt = {} 
)

This is an overloaded method.

See also
parse.

◆ prependToken()

void Parser::prependToken ( const Token token)
protected

Puts the token token to the front of the list to be processed by the parser.

Definition at line 322 of file parser.cpp.

◆ removeNextToken()

void Parser::removeNextToken ( )

◆ skipPast()

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.

Definition at line 145 of file parser.cpp.

References Cutelee::BlockToken, hasNextToken(), and takeNextToken().

Referenced by CommentNodeFactory::getNode().

◆ takeNextToken()

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.

Definition at line 291 of file parser.cpp.

Referenced by ForNodeFactory::getNode(), IfNodeFactory::getNode(), IfChangedNodeFactory::getNode(), BlockNodeFactory::getNode(), and skipPast().