refactored into Parser::buildTokenList()

This commit is contained in:
Josh Holtrop 2010-05-17 16:26:42 -04:00
parent 89a414ff93
commit 953796ec23
4 changed files with 22 additions and 11 deletions

View File

@ -47,17 +47,8 @@ bool Parser::write(const string & fname)
writeDefine(header, "I_NAMESPACE", m_namespace);
}
writeDefine(header, "I_CLASSNAME", m_classname);
string tokenlist;
for (int i = 0; i < m_tokens.size(); i++)
{
if (i > 0)
tokenlist += " ";
tokenlist += "{\"" + m_tokens[i]->getName() + "\", \""
+ m_tokens[i]->getCString() + "\"}";
if (i < m_tokens.size() - 1)
tokenlist += ", \\\n";
}
writeDefine(header, "I_TOKENLIST", tokenlist);
refptr<string> tokenlist = buildTokenList();
writeDefine(header, "I_TOKENLIST", *tokenlist);
header << endl;
header.write((const char *) tmpl_parser_h, tmpl_parser_h_len);
@ -71,6 +62,22 @@ bool Parser::write(const string & fname)
return true;
}
refptr<string> Parser::buildTokenList()
{
refptr<string> tokenlist = new string();
for (int i = 0; i < m_tokens.size(); i++)
{
if (i > 0)
*tokenlist += " ";
*tokenlist += "{ \"" + m_tokens[i]->getName() + "\", \""
+ m_tokens[i]->getCString() + "\", "
+ (m_tokens[i]->getIgnored() ? "true" : "false") + " }";
if (i < m_tokens.size() - 1)
*tokenlist += ", \\\n";
}
return tokenlist;
}
bool Parser::parseInputFile(char * buff, int size)
{
typedef pcre * pcre_ptr;

View File

@ -34,6 +34,8 @@ class Parser
std::string getExtension() { return m_extension; }
protected:
refptr<std::string> buildTokenList();
std::vector< refptr< TokenDefinition > > m_tokens;
std::vector< refptr< RuleDefinition > > m_rules;
std::string m_classname;

View File

@ -12,6 +12,7 @@ class TokenDefinition
const std::string & definition, const std::string & flags);
std::string getCString() const;
std::string getName() const { return m_name; }
bool getIgnored() const { return m_ignored; }
protected:
std::string m_name;

View File

@ -38,6 +38,7 @@ bool I_CLASSNAME::parse(istream & i)
struct {
const char * name;
const char * definition;
bool ignored;
pcre * re;
pcre_extra * re_extra;
} tokens[] = {