Skip to content
Snippets Groups Projects
Verified Commit 677370d3 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Add some more comments about the mechanism that substitutes dates inside the .mod file

parent f1beaa39
Branches
Tags
No related merge requests found
...@@ -258,6 +258,9 @@ DATE -?[0-9]+([ya]|m([1-9]|1[0-2])|q[1-4]) ...@@ -258,6 +258,9 @@ DATE -?[0-9]+([ya]|m([1-9]|1[0-2])|q[1-4])
/* Inside of a Dynare statement */ /* Inside of a Dynare statement */
<DYNARE_STATEMENT>{DATE} { <DYNARE_STATEMENT>{DATE} {
/* If a date is found within a statement, substitute it with a call to
the dates() constructor in the input character stream. Then it will
be handled by the rule that follows the present one. */
char* yycopy = strdup(yytext); char* yycopy = strdup(yytext);
char* uput = yycopy + yyleng; char* uput = yycopy + yyleng;
unput(')'); unput(')');
......
...@@ -50,6 +50,11 @@ NativeStatement::writeOutput(ostream& output, [[maybe_unused]] const string& bas ...@@ -50,6 +50,11 @@ NativeStatement::writeOutput(ostream& output, [[maybe_unused]] const string& bas
boost::xpressive does not look for the longest match in an alternation, but stops at the first boost::xpressive does not look for the longest match in an alternation, but stops at the first
match from left to right. */ match from left to right. */
string date_regex = R"((-?\d+([YyAa]|[Mm](1[0-2]|[1-9])|[Qq][1-4]|[SsHh][1-2])))"; string date_regex = R"((-?\d+([YyAa]|[Mm](1[0-2]|[1-9])|[Qq][1-4]|[SsHh][1-2])))";
/* NB: the following dance around the dollar sign (exclude it from lookbehind, then use it in a
temporary string after the first replace, then remove it in the second replace) has a purpose:
it allows the user to disable the substitution mechanism. For example, if the user writes
“$2024Q4” in a native statement, it will be transformed into “2024Q4” and not
“$dates('2024Q4')”. */
sregex regex_lookbehind = sregex::compile(R"((?<!\$|\d|[a-zA-Z_]|-|'))" + date_regex); sregex regex_lookbehind = sregex::compile(R"((?<!\$|\d|[a-zA-Z_]|-|'))" + date_regex);
sregex regex_dollar = sregex::compile(R"((\$))" + date_regex); sregex regex_dollar = sregex::compile(R"((\$))" + date_regex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment