refactored into Parser::buildTokenList()
This commit is contained in:
parent
89a414ff93
commit
953796ec23
29
Parser.cc
29
Parser.cc
@ -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;
|
||||
|
2
Parser.h
2
Parser.h
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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[] = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user