Giter Site home page Giter Site logo

Parse string methods. about expressions HOT 6 CLOSED

appsup-dart avatar appsup-dart commented on August 19, 2024
Parse string methods.

from expressions.

Comments (6)

apgapg avatar apgapg commented on August 19, 2024

For using strings methods you need to override callexpression and provide the funciton manually. For example parseAsString(24)

from expressions.

danielweil avatar danielweil commented on August 19, 2024

Yes, that I am aware. My problem is I want the parser to be able to handle string directly in the expression. I that possible?

Instead of image 1, do it as image 2.

image

image

from expressions.

apgapg avatar apgapg commented on August 19, 2024

@danielweil '2'.days doesnt make any sense. See the expression parsing is failing at 24 char

from expressions.

danielweil avatar danielweil commented on August 19, 2024

It is a method I created. If it was any other in dart language, is there any way that it would work?

For instance,

"2 ".trim()

What about the parseAsString(24) you told me above, can you be a bit more clear? Do I have to implement this in a custom class? Like "x.parseAsString(24)", {'x': CustomClass}?

from expressions.

apgapg avatar apgapg commented on August 19, 2024
class ResponseEvaluator extends ExpressionEvaluator {
  const ResponseEvaluator();

  @override
  dynamic evalCallExpression(
    CallExpression expression,
    Map<String, dynamic> context,
  ) {
    if (expression.callee is Variable &&
        (expression.callee as Variable).identifier.name == "roundOff") {
      final arguments =
          expression.arguments.map((e) => eval(e, context)).toList();
      return Function.apply(roundOff, arguments);
    } else if (expression.callee is Variable &&
        (expression.callee as Variable).identifier.name == "subtractDates") {
      final arguments =
          expression.arguments.map((e) => eval(e, context)).toList();
      return Function.apply(subtractDates, arguments);
    } else if (expression.callee is Variable &&
        (expression.callee as Variable).identifier.name == "toString") {
      final arguments =
          expression.arguments.map((e) => eval(e, context)).toList();
      return Function.apply(convertToString, arguments);
    } else if (expression.callee is Variable &&
        (expression.callee as Variable).identifier.name == "toDouble") {
      final arguments =
          expression.arguments.map((e) => eval(e, context)).toList();
      return Function.apply(convertToDouble, arguments);
    }
    return super.evalCallExpression(expression, context);
  }
}

@danielweil See how i created custom methods for utilising string methods. Note you cant access string methods directly here because. expression wont evaluate.

to use above methods toString(23)

from expressions.

danielweil avatar danielweil commented on August 19, 2024

Thanks! That cleared all my doubts!

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.