Power-Fx icon indicating copy to clipboard operation
Power-Fx copied to clipboard

Enable UDF on REPL

Open adithyaselv opened this issue 1 year ago • 6 comments

Adds ability to define User-defined functions in REPL.

Parsing UDFs requires a different parser from the Texl Expression parser and this is addressed by using the DefinitionsParser as a fallback to check when regular parsing fails. If definitions parsing is successful and we find UDF, we add it to the Engine.

image

Fixes #2545 #2546

adithyaselv avatar Jul 23 '24 21:07 adithyaselv

✅ No public API change.

LucGenetier avatar Jul 23 '24 22:07 LucGenetier

            texlFunctionSet.Add(func);

see above - we should remove this too. Only call texlFunctionSet.Add() once.


Refers to: src/libraries/Microsoft.PowerFx.Core/Functions/UserDefinedFunction.cs:249 in 4169003. [](commit_id = 4169003ab9036c970afcfb4a8e196a1511a272da, deletion_comment = False)

MikeStall avatar Jul 26 '24 23:07 MikeStall

                nameResolver.Functions.WithName(udfName).Any(func => func.IsRestrictedUDFName))

suspicious?

Adding a new TexlFunction.IsRestrictedUDFName = true is a breaking change. Which means we must keep to a fixed list (currently just AsType, Collect), so why not just keep it to _restrictedUDFNames.


Refers to: src/libraries/Microsoft.PowerFx.Core/Functions/UserDefinedFunction.cs:223 in 4169003. [](commit_id = 4169003ab9036c970afcfb4a8e196a1511a272da, deletion_comment = False)

MikeStall avatar Jul 26 '24 23:07 MikeStall

                nameResolver.Functions.WithName(udfName).Any(func => func.IsRestrictedUDFName))

talked more. This is also used in other PA Client functions like IsType,Set,UpdateContext ... basically anything that can implicitly define variables.


In reply to: 2253638869


Refers to: src/libraries/Microsoft.PowerFx.Core/Functions/UserDefinedFunction.cs:223 in 4169003. [](commit_id = 4169003ab9036c970afcfb4a8e196a1511a272da, deletion_comment = False)

MikeStall avatar Jul 26 '24 23:07 MikeStall

Is the parser assuming that the open curly braces is a function body? The "a:" isn't valid as the start of a formula, and the ".a" on the end is a dead giveaway too. We will need this to work (without the ".a" on the end) when we have UDFs that return typed records.

>> rr():Text = {a:"asdf"}.a
Error 4-5: Unexpected characters. Characters are used in the formula in an unexpected way.
Error 0-4: 'rr' is an unknown or unsupported function.

>> rr():Text = Proper( {a:"asdf"}.a )

>> rr()
"Asdf"

gregli-msft avatar Jul 27 '24 00:07 gregli-msft

As discussed in chat, this is very odd, as a Text string should not be returnable from this function. As we discussed, we may want to just block Void for now, both as an input and output type.

>> n(x:Number):Void = "asdf"

>> n(3)
"asdf"

gregli-msft avatar Jul 27 '24 00:07 gregli-msft

✅ No public API change.

LucGenetier avatar Sep 04 '24 00:09 LucGenetier

✅ No public API change.

LucGenetier avatar Sep 06 '24 01:09 LucGenetier

✅ No public API change.

LucGenetier avatar Sep 09 '24 21:09 LucGenetier

✅ No public API change.

LucGenetier avatar Sep 17 '24 23:09 LucGenetier

✅ No public API change.

LucGenetier avatar Sep 19 '24 17:09 LucGenetier