preprocessor: allow shock group names to contain spaces. closes #1280

time-shift
Houtan Bastani 2016-09-14 14:03:03 +02:00
parent 81079895df
commit 804d31e8af
3 changed files with 29 additions and 11 deletions

View File

@ -6867,7 +6867,8 @@ of the shock groups is written in a block delimited by @code{shock_groups} and
Each line defines a group of shock as a list of exogenous variables:
@example
SHOCK_GROUP_NAME = VARIABLE_1 [[,] VARIABLE_2 [,]@dots{}];
SHOCK_GROUP_NAME = VARIABLE_1 [[,] VARIABLE_2 [,]@dots{}];
`SHOCK GROUP NAME' = VARIABLE_1 [[,] VARIABLE_2 [,]@dots{}];
@end example
@optionshead
@ -6891,7 +6892,7 @@ varexo e_a, e_b, e_c, e_d;
shock_groups(name=group1);
supply = e_a, e_b;
demand = e_c, e_d;
`aggregate demand' = e_c, e_d;
end;
shocks_decomposition(use_shock_groups=group1);

View File

@ -2685,9 +2685,10 @@ shock_group_list : shock_group_list shock_group_element
| shock_group_element
;
shock_group_element : symbol EQUAL shock_name_list ';' {driver.add_shock_group($1);}
shock_group_element : symbol EQUAL shock_name_list ';' { driver.add_shock_group($1); }
| QUOTED_STRING EQUAL shock_name_list ';' { driver.add_shock_group($1); }
;
shock_name_list : shock_name_list COMMA symbol {driver.add_shock_group_element($3);}
| shock_name_list symbol {driver.add_shock_group_element($2);}
| symbol {driver.add_shock_group_element($1);}

View File

@ -463,13 +463,29 @@ ShockGroupsStatement::ShockGroupsStatement(const group_t &shock_groups_arg, cons
void
ShockGroupsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
for (vector<Group>::const_iterator it = shock_groups.begin(); it != shock_groups.end(); it++)
int i = 1;
bool unique_label = true;
for (vector<Group>::const_iterator it = shock_groups.begin(); it != shock_groups.end(); it++, unique_label=true)
{
output << "M_.shock_groups." << name
<< "." << it->name << " = {";
for ( vector<string>::const_iterator it1 = it->list.begin(); it1 != it->list.end(); it1++)
output << " '" << *it1 << "'";
output << "};" << endl;
for (vector<Group>::const_iterator it1 = it+1; it1 != shock_groups.end(); it1++)
if (it->name == it1->name)
{
unique_label = false;
cerr << "Warning: shock group label '" << it->name << "' has been reused. "
<< "Only using the last definition." << endl;
break;
}
if (unique_label)
{
output << "M_.shock_groups." << name
<< ".group" << i << ".label = '" << it->name << "';" << endl
<< "M_.shock_groups." << name
<< ".group" << i << ".shocks = {";
for ( vector<string>::const_iterator it1 = it->list.begin(); it1 != it->list.end(); it1++)
output << " '" << *it1 << "'";
output << "};" << endl;
i++;
}
}
}