Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set in context #2

Open
Alekcei opened this issue Jan 13, 2019 · 1 comment
Open

Set in context #2

Alekcei opened this issue Jan 13, 2019 · 1 comment

Comments

@Alekcei
Copy link

Alekcei commented Jan 13, 2019

i need help please
how implement set "=" in Map context

@rbellens
Copy link
Contributor

The = operator is currently not supported.

You could implement it yourself and do a PR. This means adapting the parser class, creating an AssignmentExpression class and adding an evalAssignment method in the ExpressionEvaluator.

Alternatively, you could use a set method instead of the = operator. So, if you would have an expression like x["something"] = 'hello', write it as x.set("something", 'hello') instead. This will be parsed by the default parser. You would only need to create a custom evaluator that extends the default ExpressionEvaluator and overrides the evalMemberExpression. Something like this:

class MyEvaluator extends ExpressionEvaluator {
  const MyEvaluator();

  @override
  evalMemberExpression(MemberExpression expression, Map<String, dynamic> context) {
    var object = eval(expression.object, context).toJson();
    if (object is Map&&expression.property.name=='set') {
      return (key, value) => object[key] = value;
    }
    return super.evalMemberExpression(expression, context);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants