My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
TemplateParser Class Reference

Parser for templates. More...

Public Member Functions

 TemplateParser (const TemplateEngine *engine, const QCString &templateName, QList< TemplateToken > &tokens)
 
void parse (TemplateNode *parent, int line, const QStrList &stopAt, QList< TemplateNode > &nodes)
 
bool hasNextToken () const
 
TemplateTokentakeNextToken ()
 
void removeNextToken ()
 
void prependToken (const TemplateToken *token)
 
const TemplateTokencurrentToken () const
 
QCString templateName () const
 
void warn (const char *fileName, int line, const char *fmt,...) const
 

Private Attributes

const TemplateEnginem_engine
 
QCString m_templateName
 
QList< TemplateToken > & m_tokens
 

Detailed Description

Parser for templates.

Definition at line 1724 of file template.cpp.

Constructor & Destructor Documentation

TemplateParser::TemplateParser ( const TemplateEngine engine,
const QCString &  templateName,
QList< TemplateToken > &  tokens 
)

Definition at line 4882 of file template.cpp.

:
{
}

Member Function Documentation

const TemplateToken * TemplateParser::currentToken ( ) const

Definition at line 4979 of file template.cpp.

References m_tokens.

{
return m_tokens.getFirst();
};
bool TemplateParser::hasNextToken ( ) const

Definition at line 4969 of file template.cpp.

References m_tokens.

Referenced by parse().

{
return !m_tokens.isEmpty();
}
void TemplateParser::parse ( TemplateNode parent,
int  line,
const QStrList &  stopAt,
QList< TemplateNode > &  nodes 
)

Definition at line 4889 of file template.cpp.

References TemplateToken::Block, TemplateToken::data, hasNextToken(), TemplateNodeFactory::instance(), TemplateToken::line, m_templateName, prependToken(), takeNextToken(), TemplateToken::Text, TRACE, TemplateToken::type, TemplateToken::Variable, and warn().

Referenced by TemplateImpl::TemplateImpl(), TemplateNodeBlock::TemplateNodeBlock(), TemplateNodeEncoding::TemplateNodeEncoding(), TemplateNodeExtend::TemplateNodeExtend(), TemplateNodeFor::TemplateNodeFor(), TemplateNodeIf::TemplateNodeIf(), TemplateNodeMarkers::TemplateNodeMarkers(), TemplateNodeMsg::TemplateNodeMsg(), TemplateNodeRange::TemplateNodeRange(), TemplateNodeRepeat::TemplateNodeRepeat(), TemplateNodeSpaceless::TemplateNodeSpaceless(), TemplateNodeTabbing::TemplateNodeTabbing(), TemplateNodeTree::TemplateNodeTree(), and TemplateNodeWith::TemplateNodeWith().

{
TRACE(("{TemplateParser::parse\n"));
// process the tokens. Build node list
while (hasNextToken())
{
//printf("%p:Token type=%d data='%s' line=%d\n",
// parent,tok->type,tok->data.data(),tok->line);
switch(tok->type)
{
nodes.append(new TemplateNodeText(this,parent,tok->line,tok->data));
break;
case TemplateToken::Variable: // {{ var }}
nodes.append(new TemplateNodeVariable(this,parent,tok->line,tok->data));
break;
case TemplateToken::Block: // {% tag %}
{
QCString command = tok->data;
int sep = command.find(' ');
if (sep!=-1)
{
command=command.left(sep);
}
if (stopAt.contains(command))
{
TRACE(("}TemplateParser::parse: stop\n"));
return;
}
QCString arg;
if (sep!=-1)
{
arg = tok->data.mid(sep+1);
}
create(command,this,parent,tok->line,arg);
if (node)
{
nodes.append(node);
}
else if (command=="empty" || command=="else" ||
command=="endif" || command=="endfor" ||
command=="endblock" || command=="endwith" ||
command=="endrecursetree" || command=="endspaceless" ||
command=="endmarkers" || command=="endmsg" ||
command=="endrepeat" || command=="elif" ||
command=="endrange" || command=="endtabbing" ||
command=="endencoding")
{
warn(m_templateName,tok->line,"Found tag '%s' without matching start tag",command.data());
}
else
{
warn(m_templateName,tok->line,"Unknown tag '%s'",command.data());
}
}
break;
}
delete tok;
}
if (!stopAt.isEmpty())
{
QStrListIterator it(stopAt);
const char *s;
QCString options;
for (it.toFirst();(s=it.current());++it)
{
if (!options.isEmpty()) options+=", ";
options+=s;
}
warn(m_templateName,line,"Unclosed tag in template, expected one of: %s",
options.data());
}
TRACE(("}TemplateParser::parse: last token\n"));
}
void TemplateParser::prependToken ( const TemplateToken token)

Definition at line 4989 of file template.cpp.

References m_tokens.

Referenced by parse().

{
m_tokens.prepend(token);
}
void TemplateParser::removeNextToken ( )

Definition at line 4984 of file template.cpp.

References m_tokens.

Referenced by TemplateNodeBlock::TemplateNodeBlock(), TemplateNodeEncoding::TemplateNodeEncoding(), TemplateNodeFor::TemplateNodeFor(), TemplateNodeIf::TemplateNodeIf(), TemplateNodeMarkers::TemplateNodeMarkers(), TemplateNodeMsg::TemplateNodeMsg(), TemplateNodeRange::TemplateNodeRange(), TemplateNodeRepeat::TemplateNodeRepeat(), TemplateNodeSpaceless::TemplateNodeSpaceless(), TemplateNodeTabbing::TemplateNodeTabbing(), TemplateNodeTree::TemplateNodeTree(), and TemplateNodeWith::TemplateNodeWith().

{
m_tokens.removeFirst();
}
TemplateToken * TemplateParser::takeNextToken ( )

Definition at line 4974 of file template.cpp.

References m_tokens.

Referenced by parse(), TemplateNodeFor::TemplateNodeFor(), and TemplateNodeIf::TemplateNodeIf().

{
return m_tokens.take(0);
}
QCString TemplateParser::templateName ( ) const
inline

Definition at line 1736 of file template.cpp.

References m_templateName.

Referenced by ExpressionParser::getNextToken(), ExpressionParser::parseNotExpression(), ExpressionParser::parsePrimaryExpression(), TemplateNodeBlock::TemplateNodeBlock(), TemplateNodeCloseSubIndex::TemplateNodeCloseSubIndex(), TemplateNodeCycle::TemplateNodeCycle(), TemplateNodeIndexEntry::TemplateNodeIndexEntry(), TemplateNodeOpenSubIndex::TemplateNodeOpenSubIndex(), and TemplateNodeWith::TemplateNodeWith().

{ return m_templateName; }
void TemplateParser::warn ( const char *  fileName,
int  line,
const char *  fmt,
  ... 
) const

Definition at line 4994 of file template.cpp.

References m_engine, TemplateEngine::printIncludeContext(), and va_warn().

Referenced by parse(), TemplateNodeBlock::TemplateNodeBlock(), TemplateNodeCloseSubIndex::TemplateNodeCloseSubIndex(), TemplateNodeCreate::TemplateNodeCreate(), TemplateNodeCycle::TemplateNodeCycle(), TemplateNodeEncoding::TemplateNodeEncoding(), TemplateNodeExtend::TemplateNodeExtend(), TemplateNodeFor::TemplateNodeFor(), TemplateNodeIf::TemplateNodeIf(), TemplateNodeInclude::TemplateNodeInclude(), TemplateNodeIndexEntry::TemplateNodeIndexEntry(), TemplateNodeMarkers::TemplateNodeMarkers(), TemplateNodeOpenSubIndex::TemplateNodeOpenSubIndex(), TemplateNodeRange::TemplateNodeRange(), TemplateNodeResource::TemplateNodeResource(), TemplateNodeTree::TemplateNodeTree(), TemplateNodeVariable::TemplateNodeVariable(), and TemplateNodeWith::TemplateNodeWith().

{
va_list args;
va_start(args,fmt);
va_warn(fileName,line,fmt,args);
va_end(args);
m_engine->printIncludeContext(fileName,line);
}

Member Data Documentation

const TemplateEngine* TemplateParser::m_engine
private

Definition at line 1739 of file template.cpp.

Referenced by warn().

QCString TemplateParser::m_templateName
private

Definition at line 1740 of file template.cpp.

Referenced by parse(), and templateName().

QList<TemplateToken>& TemplateParser::m_tokens
private

Definition at line 1741 of file template.cpp.

Referenced by currentToken(), hasNextToken(), prependToken(), removeNextToken(), and takeNextToken().


The documentation for this class was generated from the following file: