summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2005-03-30 21:58:44 (UTC)
committer Michael Krelin <hacker@klever.net>2005-03-30 21:58:44 (UTC)
commit5c757590c7561f6d85b3f9011aa0695c4111b379 (patch) (side-by-side diff)
treee0bf20ca58b3e7bd9cc4eda54db5674ba1d71db0
parent3ddbfeafde93d1aab16a710498d86eef4e787406 (diff)
downloadsitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.zip
sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.tar.gz
sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.tar.bz2
1. fixed a bug just introduced, preventing the last skeleton-generated file
from being written. 2. introduced pragma directive and pragma main=class 3. minor changes of no importance
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/sitecing/sitecing_enflesher.h9
-rw-r--r--include/sitecing/sitecing_parser.h8
-rw-r--r--lib/component_factory.cc2
-rw-r--r--lib/sitecing_enflesher.ll8
-rw-r--r--lib/sitecing_parser.ll49
5 files changed, 72 insertions, 4 deletions
diff --git a/include/sitecing/sitecing_enflesher.h b/include/sitecing/sitecing_enflesher.h
index 8bc43a0..db15bc3 100644
--- a/include/sitecing/sitecing_enflesher.h
+++ b/include/sitecing/sitecing_enflesher.h
@@ -69,11 +69,20 @@ class sitecing_enflesher : public sitecing_enflesherFlexLexer {
/**
* Close previously opened output stream, rename to the 'correct'
* destination filename, if needed, and open new file.
* @see outs
* @see outs_filename
+ * @see outs_close
*/
void outs_open(const string& nfile);
+ /**
+ * Close previously opened output stream, and rename to the 'correct'
+ * destination filename, if needed.
+ * @see outs_open
+ * @see outs
+ * @see outs_filename
+ */
+ void outs_close();
};
#endif /* __SITECING_SITECING_ENFLESHER_H */
diff --git a/include/sitecing/sitecing_parser.h b/include/sitecing/sitecing_parser.h
index 22d716f..a8474f3 100644
--- a/include/sitecing/sitecing_parser.h
+++ b/include/sitecing/sitecing_parser.h
@@ -288,12 +288,20 @@ class sitecing_parser : public sitecing_parserFlexLexer {
*/
string impl;
/**
* The reference to the component factory object.
*/
component_factory& factory;
+ /**
+ * Pragma map type.
+ */
+ typedef map<string,string> pragmas_t;
+ /**
+ * Pragma's found in the component.
+ */
+ pragmas_t pragmas;
/**
* @param f the component factory.
*/
sitecing_parser(component_factory& f);
diff --git a/lib/component_factory.cc b/lib/component_factory.cc
index b8f5a16..1253111 100644
--- a/lib/component_factory.cc
+++ b/lib/component_factory.cc
@@ -316,13 +316,13 @@ namespace sitecing {
void component_factory::get_ancestors(const string& component,file_list_t& rv) {
string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".ancestors";
make(cn);
ifstream ifs(cn.c_str());
if(!ifs.good())
- throw konforka::exception(CODEPOINT,"filed to access component .ancestors");
+ throw konforka::exception(CODEPOINT,string("failed to access component '")+component+"' .ancestors");
rv.clear();
while(!ifs.eof()) {
string a;
ifs >> a;
if(!a.empty())
rv.push_back(a);
diff --git a/lib/sitecing_enflesher.ll b/lib/sitecing_enflesher.ll
index 46489c7..bb667be 100644
--- a/lib/sitecing_enflesher.ll
+++ b/lib/sitecing_enflesher.ll
@@ -176,22 +176,23 @@ void sitecing_enflesher::LexerOutput(const char *buf,int size) {
void sitecing_enflesher::enflesh() {
ifstream ifs(parser.skeleton.c_str());
if(!ifs.good())
throw preprocessor_error(CODEPOINT,"failed to open skeleton file");
switch_streams(&ifs,NULL);
yylex();
+ outs_close();
}
void sitecing_enflesher::anchor() {
if(!anchoraged)
return;
outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n";
anchor_time = false;
}
-void sitecing_enflesher::outs_open(const string& nfile) {
+void sitecing_enflesher::outs_close() {
if(!outs_filename.empty()) {
outs.flush();
outs.close();
outs.clear();
/*
* compare source and destination files.
@@ -241,12 +242,17 @@ void sitecing_enflesher::outs_open(const string& nfile) {
if(overwrite) {
cerr << "renaming '" << fn_s << "'" << endl;
if(rename(fn_s.c_str(),fn_d.c_str()))
throw preprocessor_error(CODEPOINT,"failed to rename() generated output");
}
}
+ outs_filename.erase();
+}
+
+void sitecing_enflesher::outs_open(const string& nfile) {
+ outs_close();
outs_filename = nfile;
outs.open((nfile+".new").c_str(),ios::trunc);
if(!outs.good())
throw preprocessor_error(CODEPOINT,"failed to write preprocessor output");
}
/*
diff --git a/lib/sitecing_parser.ll b/lib/sitecing_parser.ll
index 6cb78f3..8ba8673 100644
--- a/lib/sitecing_parser.ll
+++ b/lib/sitecing_parser.ll
@@ -20,12 +20,13 @@ using namespace sitecing;
%x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT
%x IMPORTLINE IMPORTCOMPONENT
%x IMPORTTYPELINE IMPORTTYPECOMPONENT
%x DERIVELINE DERIVECOMPONENT
%x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS
%x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK
+%x PRAGMALINE
%option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno
WHITESPACE [ \t]
ID [A-Za-z_][A-Za-z0-9_]*
NOIDCHAR [^A-Za-z0-9_]
@@ -91,12 +92,16 @@ NOIDCHAR [^A-Za-z0-9_]
}
\<\%method{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
anchor();
BEGIN(METHODLINE);
}
+ ^\%\%pragma{WHITESPACE}+ {
+ modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
+ BEGIN(PRAGMALINE);
+ }
<<EOF>> {
assert(modi.size()==1);
M().modify(modus_operandi::modus_preop);
LexerOutput(";",1);
return 0;
}
@@ -107,12 +112,42 @@ NOIDCHAR [^A-Za-z0-9_]
"<%output>" {
anchor();
yy_push_state(OUTPUTBLOCK);
}
}
+<PRAGMALINE>{
+ {WHITESPACE}+ {
+ modus_operandi& m = M();
+ if(!m.output.empty()) {
+ string::size_type eq = m.output.find('=');
+ if(eq==string::npos) {
+ pragmas[m.output]=m.output;
+ }else{
+ pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1);
+ }
+ m.output.erase();
+ }
+ }
+ \n {
+ modus_operandi& m = M();
+ if(!m.output.empty()) {
+ string::size_type eq = m.output.find('=');
+ if(eq==string::npos) {
+ pragmas[m.output]=m.output;
+ }else{
+ pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1);
+ }
+ m.output.erase();
+ }
+ modi.pop_front();
+ BEGIN(INITIAL);
+ anchor();
+ }
+}
+
<METHODLINE>{
{WHITESPACE}+ {
modus_operandi& m = modi.front();
if(!m.output.empty()) {
if(!m._lastid.empty()) {
if(!m._type.empty()) m._type += ' ';
@@ -403,13 +438,13 @@ NOIDCHAR [^A-Za-z0-9_]
}
<CLASSLINE>\n {
class_name = modi.front().output;
modi.pop_front();
BEGIN(INITIAL);
}
-<CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK>{
+<CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK,PRAGMALINE>{
"/*" {
yy_push_state(SLASHSTAR_COMMENT);
if(!M().devour_comments()) {
ECHO;
}
}
@@ -543,13 +578,23 @@ void sitecing_parser::preprocess(const string& in) {
throw preprocessor_error(CODEPOINT,"failed to open input file");
input_file = in;
modi.push_front(modus_operandi(0));
switch_streams(&ifs,NULL);
if(yylex())
throw preprocessor_error(CODEPOINT,"unknown error");
- member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output));
+ pragmas_t::const_iterator mp = pragmas.find("main");
+ if(mp==pragmas.end()) {
+ member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output));
+ }else{
+ member_functions.push_back(
+ member_function(
+ "void","main","(int _magic,va_list _args)",
+ mp->second+"::main(_magic,_args);"
+ )
+ );
+ }
if(have_initializers && !have_constructor)
member_functions.push_back(member_function("","","",""));
sitecing_enflesher enflesher(*this);
enflesher.enflesh();
}