updated replacement system
This commit is contained in:
parent
ecfa1730f5
commit
62fd96ad9b
15
Parser.cc
15
Parser.cc
@ -47,13 +47,13 @@ bool Parser::write(const string & fname)
|
|||||||
writeDefine(header, "I_NAMESPACE", m_namespace);
|
writeDefine(header, "I_NAMESPACE", m_namespace);
|
||||||
}
|
}
|
||||||
writeDefine(header, "I_CLASSNAME", m_classname);
|
writeDefine(header, "I_CLASSNAME", m_classname);
|
||||||
refptr<string> tokenlist = buildTokenList();
|
setReplacement("token_list", buildTokenList());
|
||||||
writeDefine(header, "I_TOKENLIST", *tokenlist);
|
|
||||||
header << endl;
|
header << endl;
|
||||||
writeTmpl(header, (char *) tmpl_parser_h, tmpl_parser_h_len);
|
writeTmpl(header, (char *) tmpl_parser_h, tmpl_parser_h_len);
|
||||||
|
|
||||||
/* write the body */
|
/* write the body */
|
||||||
writeDefine(body, "I_HEADER_NAME", string("\"") + header_fname + "\"");
|
setReplacement("header_name",
|
||||||
|
new string(string("\"") + header_fname + "\""));
|
||||||
body << endl;
|
body << endl;
|
||||||
writeTmpl(body, (char *) tmpl_parser_cc, tmpl_parser_cc_len);
|
writeTmpl(body, (char *) tmpl_parser_cc, tmpl_parser_cc_len);
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ bool Parser::writeTmpl(std::ostream & out, char * dat, int len)
|
|||||||
{
|
{
|
||||||
out.write(data, ovector[0]);
|
out.write(data, ovector[0]);
|
||||||
}
|
}
|
||||||
out << getTmplReplacement(string(data, ovector[2],
|
out << *getReplacement(string(data, ovector[2],
|
||||||
ovector[3] - ovector[2]));
|
ovector[3] - ovector[2]));
|
||||||
if (ovector[1] < newline - data)
|
if (ovector[1] < newline - data)
|
||||||
{
|
{
|
||||||
@ -97,8 +97,13 @@ bool Parser::writeTmpl(std::ostream & out, char * dat, int len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Parser::getTmplReplacement(const std::string & name)
|
refptr<std::string> Parser::getReplacement(const std::string & name)
|
||||||
{
|
{
|
||||||
|
if (m_replacements.find(name) != m_replacements.end())
|
||||||
|
{
|
||||||
|
return m_replacements[name];
|
||||||
|
}
|
||||||
|
return new string("");
|
||||||
}
|
}
|
||||||
|
|
||||||
refptr<string> Parser::buildTokenList()
|
refptr<string> Parser::buildTokenList()
|
||||||
|
8
Parser.h
8
Parser.h
@ -5,6 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "refptr.h"
|
#include "refptr.h"
|
||||||
#include "TokenDefinition.h"
|
#include "TokenDefinition.h"
|
||||||
@ -24,7 +25,11 @@ class Parser
|
|||||||
}
|
}
|
||||||
bool write(const std::string & fname);
|
bool write(const std::string & fname);
|
||||||
bool writeTmpl(std::ostream & out, char * dat, int len);
|
bool writeTmpl(std::ostream & out, char * dat, int len);
|
||||||
std::string getTmplReplacement(const std::string & name);
|
refptr<std::string> getReplacement(const std::string & name);
|
||||||
|
void setReplacement(const std::string & name, refptr<std::string> val)
|
||||||
|
{
|
||||||
|
m_replacements[name] = val;
|
||||||
|
}
|
||||||
bool parseInputFile(char * buff, int size);
|
bool parseInputFile(char * buff, int size);
|
||||||
|
|
||||||
void setClassName(const std::string & cn) { m_classname = cn; }
|
void setClassName(const std::string & cn) { m_classname = cn; }
|
||||||
@ -44,6 +49,7 @@ class Parser
|
|||||||
std::string m_classname;
|
std::string m_classname;
|
||||||
std::string m_namespace;
|
std::string m_namespace;
|
||||||
std::string m_extension;
|
std::string m_extension;
|
||||||
|
std::map< std::string, refptr<std::string> > m_replacements;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include I_HEADER_NAME
|
#include {%header_name%}
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ bool I_CLASSNAME::parse(istream & i)
|
|||||||
pcre * re;
|
pcre * re;
|
||||||
pcre_extra * re_extra;
|
pcre_extra * re_extra;
|
||||||
} tokens[] = {
|
} tokens[] = {
|
||||||
I_TOKENLIST
|
{%token_list%}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (sizeof(tokens)/sizeof(tokens[0]) == 0)
|
if (sizeof(tokens)/sizeof(tokens[0]) == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user