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 1656 of file template.cpp.

Constructor & Destructor Documentation

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

Definition at line 4661 of file template.cpp.

4663  :
4664  m_engine(engine), m_templateName(templateName), m_tokens(tokens)
4665 {
4666 }
const TemplateEngine * m_engine
Definition: template.cpp:1671
QList< TemplateToken > & m_tokens
Definition: template.cpp:1673
QCString m_templateName
Definition: template.cpp:1672

Member Function Documentation

const TemplateToken * TemplateParser::currentToken ( ) const

Definition at line 4757 of file template.cpp.

4758 {
4759  return m_tokens.getFirst();
4760 };
type * getFirst() const
Definition: qlist.h:95
QList< TemplateToken > & m_tokens
Definition: template.cpp:1673
bool TemplateParser::hasNextToken ( ) const

Definition at line 4747 of file template.cpp.

4748 {
4749  return !m_tokens.isEmpty();
4750 }
bool isEmpty() const
Definition: qlist.h:67
QList< TemplateToken > & m_tokens
Definition: template.cpp:1673
void TemplateParser::parse ( TemplateNode parent,
int  line,
const QStrList stopAt,
QList< TemplateNode > &  nodes 
)

Definition at line 4668 of file template.cpp.

4671 {
4672  TRACE(("{TemplateParser::parse\n"));
4673  // process the tokens. Build node list
4674  while (hasNextToken())
4675  {
4676  TemplateToken *tok = takeNextToken();
4677  //printf("%p:Token type=%d data='%s' line=%d\n",
4678  // parent,tok->type,tok->data.data(),tok->line);
4679  switch(tok->type)
4680  {
4681  case TemplateToken::Text:
4682  nodes.append(new TemplateNodeText(this,parent,tok->line,tok->data));
4683  break;
4684  case TemplateToken::Variable: // {{ var }}
4685  nodes.append(new TemplateNodeVariable(this,parent,tok->line,tok->data));
4686  break;
4687  case TemplateToken::Block: // {% tag %}
4688  {
4689  QCString command = tok->data;
4690  int sep = command.find(' ');
4691  if (sep!=-1)
4692  {
4693  command=command.left(sep);
4694  }
4695  if (stopAt.contains(command))
4696  {
4697  prependToken(tok);
4698  TRACE(("}TemplateParser::parse: stop\n"));
4699  return;
4700  }
4701  QCString arg;
4702  if (sep!=-1)
4703  {
4704  arg = tok->data.mid(sep+1);
4705  }
4707  create(command,this,parent,tok->line,arg);
4708  if (node)
4709  {
4710  nodes.append(node);
4711  }
4712  else if (command=="empty" || command=="else" ||
4713  command=="endif" || command=="endfor" ||
4714  command=="endblock" || command=="endwith" ||
4715  command=="endrecursetree" || command=="endspaceless" ||
4716  command=="endmarkers" || command=="endmsg" ||
4717  command=="endrepeat" || command=="elif" ||
4718  command=="endrange" || command=="endtabbing")
4719  {
4720  warn(m_templateName,tok->line,"Found tag '%s' without matching start tag",command.data());
4721  }
4722  else
4723  {
4724  warn(m_templateName,tok->line,"Unknown tag '%s'",command.data());
4725  }
4726  }
4727  break;
4728  }
4729  delete tok;
4730  }
4731  if (!stopAt.isEmpty())
4732  {
4733  QStrListIterator it(stopAt);
4734  const char *s;
4735  QCString options;
4736  for (it.toFirst();(s=it.current());++it)
4737  {
4738  if (!options.isEmpty()) options+=", ";
4739  options+=s;
4740  }
4741  warn(m_templateName,line,"Unclosed tag in template, expected one of: %s",
4742  options.data());
4743  }
4744  TRACE(("}TemplateParser::parse: last token\n"));
4745 }
bool isEmpty() const
Definition: qcstring.h:189
void append(const type *d)
Definition: qlist.h:73
int command
TemplateToken * takeNextToken()
Definition: template.cpp:4752
QCString left(uint len) const
Definition: qcstring.cpp:213
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
Class representing a lexical token in a template.
Definition: template.cpp:2226
void warn(const char *fileName, int line, const char *fmt,...) const
Definition: template.cpp:4772
Class representing a variable in a template.
Definition: template.cpp:2608
QCString data
Definition: template.cpp:2232
static TemplateNodeFactory * instance()
Definition: template.cpp:4278
uint contains(const type *d) const
Definition: qinternallist.h:78
const char * data() const
Definition: qcstring.h:207
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
void line(double t, double *p, double &x, double &y, double &z)
Class representing a piece of plain text in a template.
Definition: template.cpp:2578
void prependToken(const TemplateToken *token)
Definition: template.cpp:4767
bool isEmpty() const
Definition: qinternallist.h:57
QCString m_templateName
Definition: template.cpp:1672
Base class of all nodes in a template&#39;s AST.
Definition: template.cpp:1639
#define TRACE(x)
Definition: template.cpp:43
static QCString * s
Definition: config.cpp:1042
bool hasNextToken() const
Definition: template.cpp:4747
void TemplateParser::prependToken ( const TemplateToken token)

Definition at line 4767 of file template.cpp.

4768 {
4769  m_tokens.prepend(token);
4770 }
QList< TemplateToken > & m_tokens
Definition: template.cpp:1673
void prepend(const type *d)
Definition: qlist.h:72
void TemplateParser::removeNextToken ( )

Definition at line 4762 of file template.cpp.

4763 {
4765 }
bool removeFirst()
Definition: qlist.h:79
QList< TemplateToken > & m_tokens
Definition: template.cpp:1673
TemplateToken * TemplateParser::takeNextToken ( )

Definition at line 4752 of file template.cpp.

4753 {
4754  return m_tokens.take(0);
4755 }
QList< TemplateToken > & m_tokens
Definition: template.cpp:1673
type * take(uint i)
Definition: qlist.h:81
QCString TemplateParser::templateName ( ) const
inline

Definition at line 1668 of file template.cpp.

1668 { return m_templateName; }
QCString m_templateName
Definition: template.cpp:1672
void TemplateParser::warn ( const char *  fileName,
int  line,
const char *  fmt,
  ... 
) const

Definition at line 4772 of file template.cpp.

4773 {
4774  va_list args;
4775  va_start(args,fmt);
4776  va_warn(fileName,line,fmt,args);
4777  va_end(args);
4779 }
static QCString args
Definition: declinfo.cpp:674
void printIncludeContext(const char *fileName, int line) const
Definition: template.cpp:4991
fileName
Definition: dumpTree.py:9
const TemplateEngine * m_engine
Definition: template.cpp:1671
void line(double t, double *p, double &x, double &y, double &z)
void va_warn(const char *file, int line, const char *fmt, va_list args)
Definition: message.cpp:191

Member Data Documentation

const TemplateEngine* TemplateParser::m_engine
private

Definition at line 1671 of file template.cpp.

QCString TemplateParser::m_templateName
private

Definition at line 1672 of file template.cpp.

QList<TemplateToken>& TemplateParser::m_tokens
private

Definition at line 1673 of file template.cpp.


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