macro processor: allow colon-separated arrays as command-line defines
colon-separated command line arguments such as ``` dynare <<.mod file>> -DA=1:5 -DAA=1:2:5 ``` are now translated as: ``` @#define C = [2, 3, 4, 5, 6] @#define CC = [2, 5] ```issue#70
parent
f00d7c4b4c
commit
6d1c2ca82b
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2019 Dynare Team
|
* Copyright © 2019-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Driver.hh"
|
#include "Driver.hh"
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
using namespace macro;
|
using namespace macro;
|
||||||
|
|
||||||
|
@ -39,9 +40,16 @@ Driver::parse(const string &file_arg, const string &basename_arg, istream &modfi
|
||||||
stod(val, &pos);
|
stod(val, &pos);
|
||||||
if (pos == val.size())
|
if (pos == val.size())
|
||||||
command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
|
command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// The following regex matches the range syntax: double:double(:double)?
|
||||||
|
regex colon_separated_doubles(R"(((((\d*\.\d+)|(\d+\.))([ed][-+]?\d+)?)|(\d+([ed][-+]?\d+)?)):((((\d*\.\d+)|(\d+\.))([ed][-+]?\d+)?)|(\d+([ed][-+]?\d+)?))(:((((\d*\.\d+)|(\d+\.))([ed][-+]?\d+)?)|(\d+([ed][-+]?\d+)?)))?)");
|
||||||
|
if (regex_match(val, colon_separated_doubles))
|
||||||
|
command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
|
||||||
else
|
else
|
||||||
command_line_defines_with_endl << "@#define " << var << R"( = ")" << val << R"(")" << endl;
|
command_line_defines_with_endl << "@#define " << var << R"( = ")" << val << R"(")" << endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (const invalid_argument &)
|
catch (const invalid_argument &)
|
||||||
{
|
{
|
||||||
if (!val.empty() && val.at(0) == '[' && val.at(val.length()-1) == ']')
|
if (!val.empty() && val.at(0) == '[' && val.at(val.length()-1) == ']')
|
||||||
|
|
Loading…
Reference in New Issue