askql icon indicating copy to clipboard operation
askql copied to clipboard

Unable to call object properties that are functions

Open mhagmajer opened this issue 3 years ago • 7 comments

The following code produces a parsing error when run on the playground

ask {
  const sum = fun(a, b) {
      a + b
  }
  
  const diff = fun(a, b) {
      a - b
  }
  
  const myMath = { sum, diff }
   
  myMath.sum(2, 2)
}

It works fine, when myMath is destructured first:

const s = myMath.sum
s(2,2)

Used expression (myMath.sum(2, 2)) should be translated into

<call
  args={
    <list>
      {2}
      {2}
    </list>
  }
>
  <call
    name="at"
    args={
      <list>
        <ref name="myMath" />
        {"sum"}
      </list>
    }
  />
</call>

Note that call in AskJSX can accept either the name property in args or function expression in its first child.

mhagmajer avatar May 18 '21 14:05 mhagmajer

yesterday, while digging into the parser I had an idea that maybe we just change how . works: https://github.com/CatchTheTornado/askql/blob/fea7233dd1c6967b7fddd96da6134e3fd92f88f9/src/askscript/parser/askscript.grammar.pegjs#L237 - somehow making it more like the : I mean adding an option for a MethodCallApplied transformation instead of KeyExpressionApplied

That's why it works by deconstruction - bc. when deconstructed it gets into: https://github.com/CatchTheTornado/askql/blob/fea7233dd1c6967b7fddd96da6134e3fd92f88f9/src/askscript/parser/askscript.grammar.pegjs#L234

pkarw avatar May 18 '21 15:05 pkarw

@czerwinskilukasz1 what do you think about this?

mhagmajer avatar May 18 '21 15:05 mhagmajer

@czerwinskilukasz1 we neeed your help! 🙏😁

pkarw avatar May 18 '21 15:05 pkarw

Ack. I will try to reply tomorrow.

lukasz-xfaang avatar May 18 '21 22:05 lukasz-xfaang

@czerwinskilukasz1 friendly ping :)

mhagmajer avatar May 25 '21 18:05 mhagmajer

@czerwinskilukasz1 another friendly ping ;P

pkarw avatar Jun 07 '21 09:06 pkarw

@lukasz-xfaang i've stuck on this :( I really need your help @lukasz-xfaang @czerwinskilukasz1

pkarw avatar Jun 17 '21 11:06 pkarw