bijington/expressive

Escaped variable names

Opened this issue · 3 comments

Describe the bug
Escaped variables not handled correctly.

To Reproduce
The following code evaluates to "b":

var variables = new Dictionary<string, object>()
{
    { @"[a]", "a" },
    { @"\a\", "b" }
};
var expression = new Expression(@"[\[a\]]");
Console.WriteLine(expression.Evaluate(variables));

Expected behavior
The expected result would be "a".

Platform:

  • OS: .NET Core 3.1 on Windows

Thanks for the bug report. I can quite easily reproduce the behaviour that you are seeing here.

Out of interest what is your need to include the escaped [ ] characters in the variable names?

Thank you for your quick response.

This is just something I discovered "by accident" ;)

Haha the best type of testing/bug discovery :).

I mainly asked in case you were wanting to embed an expression inside of another expression which is entirely possible:

var variables = new Dictionary<string, object>()
{
    { @"a", new Expression("[b]") },
    { @"b", "c" }
};
var expression = new Expression(@"[a]");
Console.WriteLine(expression.Evaluate(variables));

Which should evaluate to c.