Power-Fx
Power-Fx copied to clipboard
Enable UDF on REPL
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.
Fixes #2545 #2546
✅ No public API change.
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)
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)
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)
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"
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"
✅ No public API change.
✅ No public API change.
✅ No public API change.
✅ No public API change.
✅ No public API change.