remove comments that are placed on the same line as native Matlab code in a .mod file

issue#70
Houtan Bastani 2010-06-17 12:47:38 +02:00
parent 8b03f0d2fd
commit 74b0b9c198
3 changed files with 33 additions and 6 deletions

View File

@ -52,6 +52,7 @@ int sigma_e = 0;
%option case-insensitive noyywrap nounput batch debug never-interactive
/* NB: if new start conditions are defined, add them in the line for [\n]+ */
%x COMMENT
%x DYNARE_STATEMENT
%x DYNARE_BLOCK
@ -85,7 +86,7 @@ int sigma_e = 0;
/* spaces, tabs and carriage returns are ignored */
<*>[ \t\r\f]+ { yylloc->step(); }
<*>[\n]+ { yylloc->lines(yyleng); yylloc->step(); }
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3>[\n]+ { yylloc->lines(yyleng); yylloc->step(); }
/* Comments */
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK>["%"].*
@ -567,7 +568,28 @@ int sigma_e = 0;
<INITIAL>. { BEGIN NATIVE; yyless(0); }
/* Add the native statement */
<NATIVE>.* { driver.add_native(yytext); BEGIN INITIAL; }
<NATIVE>{
[^/%*\n]* |
"*" |
"/" { yymore(); }
\n {
driver.add_native_remove_charset(yytext, "\n");
BEGIN INITIAL;
}
"%".* {
driver.add_native_remove_charset(yytext, "%");
BEGIN INITIAL;
}
"//".* {
driver.add_native_remove_charset(yytext, "//");
BEGIN INITIAL;
}
"/*" {
driver.add_native_remove_charset(yytext, "/*");
comment_caller = INITIAL;
BEGIN COMMENT;
}
}
<*><<EOF>> { yyterminate(); }

View File

@ -1840,9 +1840,14 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in
}
void
ParsingDriver::add_native(const char *s)
ParsingDriver::add_native_remove_charset(const char *s, const char *token)
{
mod_file->addStatement(new NativeStatement(s));
string str = string(s);
string tok = string(token);
size_t found = str.find(token);
assert(found != string::npos);
mod_file->addStatement(new NativeStatement(str.substr(0, found)));
}
void

View File

@ -489,8 +489,8 @@ public:
void add_external_function_arg(NodeID arg);
//! Adds an external function call node
NodeID add_model_var_or_external_function(string *function_name, bool in_model_block);
//! Adds a native statement
void add_native(const char *s);
//! Adds a native statement, first removing the set of characters passed in token (and everything after)
void add_native_remove_charset(const char *s, const char *token);
//! Resets data_tree and model_tree pointers to default (i.e. mod_file->expressions_tree)
void reset_data_tree();
//! Begin a steady_state_model block