added TokenDefinition::getIdentifier() and replacement buildToken
This commit is contained in:
parent
c6cc8e57d1
commit
3f3dd81e67
17
Parser.cc
17
Parser.cc
@ -51,7 +51,7 @@ bool Parser::write(const string & fname)
|
||||
{
|
||||
char buff[20];
|
||||
sprintf(buff, "%d", i++);
|
||||
makeDefine(string("TK_") + (*it)->getName(), buff);
|
||||
makeDefine((*it)->getIdentifier(), buff);
|
||||
*token_classes += (*it)->getClassDefinition();
|
||||
*token_classes_code += (*it)->getProcessMethod();
|
||||
}
|
||||
@ -63,6 +63,7 @@ bool Parser::write(const string & fname)
|
||||
|
||||
/* set up replacements */
|
||||
setReplacement("token_list", buildTokenList());
|
||||
setReplacement("buildToken", buildBuildToken());
|
||||
setReplacement("header_name",
|
||||
new string(string("\"") + header_fname + "\""));
|
||||
setReplacement("token_code", m_token_code);
|
||||
@ -148,6 +149,20 @@ refptr<string> Parser::buildTokenList()
|
||||
return tokenlist;
|
||||
}
|
||||
|
||||
refptr<string> Parser::buildBuildToken()
|
||||
{
|
||||
refptr<string> buildToken = new string();
|
||||
for (list<TokenDefinitionRef>::const_iterator t = m_tokens.begin();
|
||||
t != m_tokens.end();
|
||||
t++)
|
||||
{
|
||||
*buildToken += "case " + (*t)->getIdentifier() + ":\n";
|
||||
*buildToken += " token = new " + (*t)->getName() + "();\n";
|
||||
*buildToken += " break;\n";
|
||||
}
|
||||
return buildToken;
|
||||
}
|
||||
|
||||
bool Parser::parseInputFile(char * buff, int size)
|
||||
{
|
||||
typedef pcre * pcre_ptr;
|
||||
|
1
Parser.h
1
Parser.h
@ -37,6 +37,7 @@ class Parser
|
||||
|
||||
protected:
|
||||
refptr<std::string> buildTokenList();
|
||||
refptr<std::string> buildBuildToken();
|
||||
bool writeTmpl(std::ostream & out, char * dat, int len);
|
||||
refptr<std::string> getReplacement(const std::string & name);
|
||||
void setReplacement(const std::string & name, refptr<std::string> val)
|
||||
|
@ -21,6 +21,7 @@ class TokenDefinition
|
||||
std::string getCode() const { return m_code; }
|
||||
std::string getClassDefinition() const;
|
||||
std::string getProcessMethod() const;
|
||||
std::string getIdentifier() { return std::string("TK_") + m_name; }
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user