Commit 54b3a18c authored by Houtan Bastani's avatar Houtan Bastani
Browse files

allow long_name to be used without specifying a latex name, #478

parent 49a51ed8
......@@ -331,6 +331,12 @@ nonstationary_var_list : nonstationary_var_list symbol
{ driver.declare_nonstationary_var($3); }
| symbol
{ driver.declare_nonstationary_var($1); }
| nonstationary_var_list symbol named_var
{ driver.declare_nonstationary_var($2, NULL, $3); }
| nonstationary_var_list COMMA symbol named_var
{ driver.declare_nonstationary_var($3, NULL, $4); }
| symbol named_var
{ driver.declare_nonstationary_var($1, NULL, $2); }
| nonstationary_var_list symbol TEX_NAME
{ driver.declare_nonstationary_var($2, $3); }
| nonstationary_var_list COMMA symbol TEX_NAME
......@@ -363,6 +369,12 @@ var_list : var_list symbol
{ driver.declare_endogenous($3); }
| symbol
{ driver.declare_endogenous($1); }
| var_list symbol named_var
{ driver.declare_endogenous($2, NULL, $3); }
| var_list COMMA symbol named_var
{ driver.declare_endogenous($3, NULL, $4); }
| symbol named_var
{ driver.declare_endogenous($1, NULL, $2); }
| var_list symbol TEX_NAME
{ driver.declare_endogenous($2, $3); }
| var_list COMMA symbol TEX_NAME
......@@ -383,6 +395,12 @@ varexo_list : varexo_list symbol
{ driver.declare_exogenous($3); }
| symbol
{ driver.declare_exogenous($1); }
| varexo_list symbol named_var
{ driver.declare_exogenous($2, NULL, $3); }
| varexo_list COMMA symbol named_var
{ driver.declare_exogenous($3, NULL, $4); }
| symbol named_var
{ driver.declare_exogenous($1, NULL, $2); }
| varexo_list symbol TEX_NAME
{ driver.declare_exogenous($2, $3); }
| varexo_list COMMA symbol TEX_NAME
......@@ -403,6 +421,12 @@ varexo_det_list : varexo_det_list symbol
{ driver.declare_exogenous_det($3); }
| symbol
{ driver.declare_exogenous_det($1); }
| varexo_det_list symbol named_var
{ driver.declare_exogenous_det($2, NULL, $3); }
| varexo_det_list COMMA symbol named_var
{ driver.declare_exogenous_det($3, NULL, $4); }
| symbol named_var
{ driver.declare_exogenous_det($1, NULL, $2); }
| varexo_det_list symbol TEX_NAME
{ driver.declare_exogenous_det($2, $3); }
| varexo_det_list COMMA symbol TEX_NAME
......@@ -423,6 +447,12 @@ parameter_list : parameter_list symbol
{ driver.declare_parameter($3); }
| symbol
{ driver.declare_parameter($1); }
| parameter_list symbol named_var
{ driver.declare_parameter($2, NULL, $3); }
| parameter_list COMMA symbol named_var
{ driver.declare_parameter($3, NULL, $4); }
| symbol named_var
{ driver.declare_parameter($1, NULL, $2); }
| parameter_list symbol TEX_NAME
{ driver.declare_parameter($2, $3); }
| parameter_list COMMA symbol TEX_NAME
......
......@@ -138,7 +138,9 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string
if (tex_name == NULL && long_name == NULL)
mod_file->symbol_table.addSymbol(*name, type);
else
if (long_name == NULL)
if (tex_name == NULL)
mod_file->symbol_table.createTexNameAndAddSymbolWithLongName(*name, type, *long_name);
else if (long_name == NULL)
mod_file->symbol_table.addSymbol(*name, type, *tex_name);
else
mod_file->symbol_table.addSymbol(*name, type, *tex_name, *long_name);
......@@ -350,13 +352,16 @@ ParsingDriver::add_expression_variable(string *name)
void
ParsingDriver::declare_nonstationary_var(string *name, string *tex_name, string *long_name)
{
if (tex_name != NULL)
if (long_name != NULL)
declare_endogenous(new string(*name), new string(*tex_name), new string(*long_name));
if (tex_name == NULL && long_name == NULL)
declare_endogenous(new string(*name));
else
if (tex_name == NULL)
declare_endogenous(new string(*name), NULL, new string(*long_name));
else if (long_name == NULL)
declare_endogenous(new string(*name), new string(*tex_name));
else
declare_endogenous(new string(*name));
declare_endogenous(new string(*name), new string(*tex_name), new string(*long_name));
declared_nonstationary_vars.push_back(mod_file->symbol_table.getID(*name));
mod_file->nonstationary_variables = true;
delete name;
......
......@@ -71,16 +71,30 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
int
SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException)
{
string tex_name;
return addSymbol(name, type, construct_tex_name(name, tex_name));
}
int
SymbolTable::createTexNameAndAddSymbolWithLongName(const string &name, SymbolType type, const string &long_name) throw (AlreadyDeclaredException, FrozenException)
{
string tex_name;
return addSymbol(name, type, construct_tex_name(name, tex_name), long_name);
}
string &
SymbolTable::construct_tex_name(const string &name, string &tex_name)
{
// Construct "tex_name" by prepending an antislash to all underscores in "name"
string tex_name = name;
tex_name = name;
size_t pos = 0;
while ((pos = tex_name.find('_', pos)) != string::npos)
{
tex_name.insert(pos, "\\");
pos += 2;
}
return addSymbol(name, type, tex_name);
return tex_name;
}
void
......
......@@ -191,6 +191,12 @@ public:
//! Add a symbol without its TeX name (will be equal to its name)
/*! Returns the symbol ID */
int addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException);
//! Tmp addSymbol function that creates a tex_name and declares a symbol
//! when the name and long_name are passed
/*! Returns the symbol ID */
int createTexNameAndAddSymbolWithLongName(const string &name, SymbolType type, const string &long_name) throw (AlreadyDeclaredException, FrozenException);
//! Create a tex_name based on the variable name
string &construct_tex_name(const string &name, string &tex_name);
//! Adds an auxiliary variable for endogenous with lead >= 2
/*!
\param[in] index Used to construct the variable name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment