Giter Site home page Giter Site logo

Comments (4)

oodavid avatar oodavid commented on August 19, 2024 2

@MatteoAntolini take a peek at the example on pub.dev

You'll see that the expression contains functions cos and sin, which are made available to the evaluator through context. The code below shows how you might implement contains:

var expression = Expression.parse('contains(a,b)');
var context = {
  'a': 'Hello World',
  'b': 'Hello',
  'contains': (String a, String b) {
    return a.contains(b);
  }
};
final evaluator = const ExpressionEvaluator();
print(evaluator.eval(expression, context));

If we change the context for different values of a and b, we'll see false instead of true:

var expression = Expression.parse('contains(a,b)');
var context = {
  'a': 'Hello World',
  'b': 'Hi',
  'contains': (String a, String b) {
    return a.contains(b);
  }
};
final evaluator = const ExpressionEvaluator();
print(evaluator.eval(expression, context));

I hope this helps

from expressions.

rbellens avatar rbellens commented on August 19, 2024

If you want to be able to call a member method of some objects, you need to implement a custom evaluator. See the example directory for an example of this.

from expressions.

MatteoAntolini avatar MatteoAntolini commented on August 19, 2024

Ok, but I have it in the expression.

+a empty or +a contains "b"

How can I do it?

from expressions.

rbellens avatar rbellens commented on August 19, 2024

For this the parser should be changed. This is currently not supported. You can however copy the code of the default parser to your own code and alter it as you wish. If you find a solution that is generic enough, you can also do a pull request.

from expressions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.