Doxygen
TemplateParser类 参考

Parser for templates 更多...

+ TemplateParser 的协作图:

Public 成员函数

 TemplateParser (const TemplateEngine *engine, const QCString &templateName, TemplateTokenStream &tokens)
 
void parse (TemplateNode *parent, int line, const StringVector &stopAt, TemplateNodeList &nodes)
 
bool hasNextToken () const
 
TemplateTokenPtr takeNextToken ()
 
void removeNextToken ()
 
void prependToken (TemplateTokenPtr &&token)
 
const TemplateTokencurrentToken () const
 
QCString templateName () const
 
void warn (const QCString &fileName, int line, const char *fmt,...) const
 

Private 属性

const TemplateEnginem_engine = 0
 
QCString m_templateName
 
TemplateTokenStreamm_tokens
 

详细描述

Parser for templates

在文件 template.cpp1985 行定义.

构造及析构函数说明

◆ TemplateParser()

TemplateParser::TemplateParser ( const TemplateEngine engine,
const QCString templateName,
TemplateTokenStream tokens 
)

在文件 template.cpp5050 行定义.

5052  :
5053  m_engine(engine), m_templateName(templateName), m_tokens(tokens)
5054 {
5055 }

成员函数说明

◆ currentToken()

const TemplateToken * TemplateParser::currentToken ( ) const

在文件 template.cpp5148 行定义.

5149 {
5150  return m_tokens.front().get();
5151 }

引用了 m_tokens.

◆ hasNextToken()

bool TemplateParser::hasNextToken ( ) const

在文件 template.cpp5135 行定义.

5136 {
5137  return !m_tokens.empty();
5138 }

引用了 m_tokens.

被这些函数引用 parse().

◆ parse()

void TemplateParser::parse ( TemplateNode parent,
int  line,
const StringVector stopAt,
TemplateNodeList nodes 
)

在文件 template.cpp5057 行定义.

5060 {
5061  TRACE(("{TemplateParser::parse\n"));
5062  // process the tokens. Build node list
5063  while (hasNextToken())
5064  {
5065  auto tok = takeNextToken();
5066  TRACE(("%p:Token type=%d data='%s' line=%d\n",
5067  (void*)parent,tok->type,qPrint(tok->data),tok->line));
5068  switch(tok->type)
5069  {
5070  case TemplateToken::Text:
5071  nodes.push_back(std::make_unique<TemplateNodeText>(this,parent,tok->line,tok->data));
5072  break;
5073  case TemplateToken::Variable: // {{ var }}
5074  nodes.push_back(std::make_unique<TemplateNodeVariable>(this,parent,tok->line,tok->data));
5075  break;
5076  case TemplateToken::Block: // {% tag %}
5077  {
5078  QCString command = tok->data;
5079  int sep = command.find(' ');
5080  if (sep!=-1)
5081  {
5082  command=command.left(sep);
5083  }
5084  TemplateToken *tok_ptr = tok.get();
5085  if (std::find(stopAt.begin(),stopAt.end(),command.str())!=stopAt.end())
5086  {
5087  prependToken(std::move(tok));
5088  TRACE(("}TemplateParser::parse: stop\n"));
5089  return;
5090  }
5091  QCString arg;
5092  if (sep!=-1)
5093  {
5094  arg = tok_ptr->data.mid(sep+1);
5095  }
5097  command,this,parent,tok_ptr->line,arg);
5098  if (node)
5099  {
5100  nodes.push_back(std::move(node));
5101  }
5102  else if (command=="empty" || command=="else" ||
5103  command=="endif" || command=="endfor" ||
5104  command=="endblock" || command=="endwith" ||
5105  command=="endrecursetree" || command=="endspaceless" ||
5106  command=="endmarkers" || command=="endmsg" ||
5107  command=="endrepeat" || command=="elif" ||
5108  command=="endrange" || command=="endtabbing" ||
5109  command=="endencoding")
5110  {
5111  warn(m_templateName,tok_ptr->line,"Found tag '%s' without matching start tag",qPrint(command));
5112  }
5113  else
5114  {
5115  warn(m_templateName,tok_ptr->line,"Unknown tag '%s'",qPrint(command));
5116  }
5117  }
5118  break;
5119  }
5120  }
5121  if (!stopAt.empty())
5122  {
5123  QCString options;
5124  for (const auto &s : stopAt)
5125  {
5126  if (!options.isEmpty()) options+=", ";
5127  options+=s.c_str();
5128  }
5129  warn(m_templateName,line,"Unclosed tag in template, expected one of: %s",
5130  qPrint(options));
5131  }
5132  TRACE(("}TemplateParser::parse: last token\n"));
5133 }

引用了 TemplateToken::Block, TemplateNodeFactory::create(), QCString::data(), TemplateToken::data, QCString::find(), hasNextToken(), TemplateNodeFactory::instance(), QCString::isEmpty(), QCString::left(), TemplateToken::line, m_templateName, QCString::mid(), prependToken(), qPrint(), QCString::str(), takeNextToken(), TemplateToken::Text, TRACE, TemplateToken::Variable , 以及 warn().

被这些函数引用 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() , 以及 TemplateNodeWith::TemplateNodeWith().

◆ prependToken()

void TemplateParser::prependToken ( TemplateTokenPtr &&  token)

在文件 template.cpp5158 行定义.

5159 {
5160  m_tokens.push_front(std::move(token));
5161 }

引用了 m_tokens.

被这些函数引用 parse().

◆ removeNextToken()

◆ takeNextToken()

TemplateTokenPtr TemplateParser::takeNextToken ( )

在文件 template.cpp5140 行定义.

5141 {
5142  if (m_tokens.empty()) return TemplateTokenPtr();
5143  auto tok = std::move(m_tokens.front());
5144  m_tokens.pop_front();
5145  return tok;
5146 }

引用了 m_tokens.

被这些函数引用 parse(), TemplateNodeFor::TemplateNodeFor() , 以及 TemplateNodeIf::TemplateNodeIf().

◆ templateName()

◆ warn()

类成员变量说明

◆ m_engine

const TemplateEngine* TemplateParser::m_engine = 0
private

在文件 template.cpp2001 行定义.

被这些函数引用 warn().

◆ m_templateName

QCString TemplateParser::m_templateName
private

在文件 template.cpp2002 行定义.

被这些函数引用 parse() , 以及 templateName().

◆ m_tokens

TemplateTokenStream& TemplateParser::m_tokens
private

在文件 template.cpp2003 行定义.

被这些函数引用 currentToken(), hasNextToken(), prependToken(), removeNextToken() , 以及 takeNextToken().


该类的文档由以下文件生成:
TemplateParser::prependToken
void prependToken(TemplateTokenPtr &&token)
Definition: template.cpp:5158
TemplateParser::m_templateName
QCString m_templateName
Definition: template.cpp:2002
TemplateToken::line
int line
Definition: template.cpp:1959
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
TemplateTokenPtr
std::unique_ptr< TemplateToken > TemplateTokenPtr
Definition: template.cpp:1962
QCString::str
std::string str() const
Definition: qcstring.h:442
TemplateParser::templateName
QCString templateName() const
Definition: template.cpp:1998
QCString::find
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:38
TemplateToken::data
QCString data
Definition: template.cpp:1958
TemplateEngine::printIncludeContext
void printIncludeContext(const QCString &fileName, int line) const
Prints the current template file include stack
Definition: template.cpp:5401
TemplateParser::m_tokens
TemplateTokenStream & m_tokens
Definition: template.cpp:2003
TemplateParser::warn
void warn(const QCString &fileName, int line, const char *fmt,...) const
Definition: template.cpp:5163
QCString::left
QCString left(size_t len) const
Definition: qcstring.h:212
TemplateParser::hasNextToken
bool hasNextToken() const
Definition: template.cpp:5135
TRACE
#define TRACE(x)
Definition: template.cpp:40
va_warn
void va_warn(const QCString &file, int line, const char *fmt, va_list args)
Definition: message.cpp:159
TemplateToken::Text
@ Text
Definition: template.cpp:1955
TemplateToken
Class representing a lexical token in a template
Definition: template.cpp:1952
QCString::mid
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition: qcstring.h:224
TemplateParser::m_engine
const TemplateEngine * m_engine
Definition: template.cpp:2001
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
TemplateToken::Block
@ Block
Definition: template.cpp:1955
TemplateNodeFactory::instance
static TemplateNodeFactory & instance()
Definition: template.cpp:4671
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
TemplateParser::takeNextToken
TemplateTokenPtr takeNextToken()
Definition: template.cpp:5140
TemplateToken::Variable
@ Variable
Definition: template.cpp:1955
TemplateNodeFactory::create
TemplateNodePtr create(const QCString &name, TemplateParser *parser, TemplateNode *parent, int line, const QCString &data)
Definition: template.cpp:4678
TemplateNodePtr
std::unique_ptr< TemplateNode > TemplateNodePtr
Definition: template.cpp:1947
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108