Skip to content

Commit

Permalink
Fixed strings starting with @ still being parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
wcaarls committed Nov 4, 2024
1 parent 96f937f commit 1318239
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions addons/python/src/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ bool printPyList(PyObject* arr) {
void PythonRewardEnvironment::configure(Configuration &config)
{
reward_function_str_ = config["reward"].str();
if (!reward_function_str_.empty() && reward_function_str_[0] == '@')
reward_function_str_ = reward_function_str_.substr(1);

env_ = (Environment*)config["environment"].ptr();

Py_Initialize();
Expand Down
4 changes: 4 additions & 0 deletions base/include/grl/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ ASTNodePtr parseExpression(const std::string &str);

inline std::string evaluateExpression(const std::string &str)
{
// Expressions starting with @ are not evaluated.
if (!str.empty() && str[0] == '@')
return str;

ASTNodePtr ast = parseExpression(str);
return ast->evaluate();
}
Expand Down
13 changes: 8 additions & 5 deletions base/src/configurable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,12 @@ std::string ParameterConfigurator::localize(const std::string &id, const Configu

std::string ParameterConfigurator::str() const
{
// Expressions starting with @ are not evaluated.
if (!value_.empty() && value_[0] == '@')
return value_;

std::string v = value_, id, expv;

// Expressions starting with @ are not evaluated. For literal
// @ at the beginning of an expression, use @@.
if (!value_.empty() && v[0] == '@')
return value_.substr(1);

// Resolve references
for (size_t ii=0; ii < v.size(); ++ii)
{
Expand Down Expand Up @@ -466,6 +465,10 @@ ParameterConfigurator *ParameterConfigurator::instantiate(Configurator *parent)
if (!parent)
parent = parent_;

// Expressions starting with @ are not evaluated.
if (!value_.empty() && value_[0] == '@')
return new ParameterConfigurator(element_, value_, parent);

std::string v = value_, id, expv;

// Make references local
Expand Down

0 comments on commit 1318239

Please sign in to comment.