diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index be1e86898c15c7772c6041bfa57ff1ba25ea4ccb..83d767120523ec4856cdd21899d5d6f485d27fad 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -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(); } diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 38f08a1e2b193a191e82b2e2e33aa43dff568bbb..846a0989f8d8396271ab5ea79795747995c87a7b 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -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 diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index 43cace79084241ac63bfaa53bb844ff4632a5318..987feb1f87f480eb76d90b17ddec57880a0aef83 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -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