Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
468b38c
Intial impl RecordOf
adithyaselv Nov 7, 2024
fa86309
Fix visitors
adithyaselv Nov 11, 2024
7a12483
Add Flag, tests
adithyaselv Nov 12, 2024
71d67e0
Change logic to use callnode
adithyaselv Nov 14, 2024
c00d011
Merge branch 'main' into adithyase/record-of-syntax
adithyaselv Nov 14, 2024
9b886bc
.
adithyaselv Nov 14, 2024
9a31411
Add a bunch of tests
adithyaselv Nov 15, 2024
835d350
add asserts
adithyaselv Nov 15, 2024
31ee2db
Add specific error for incorrect type helper usage
adithyaselv Nov 18, 2024
32053d3
Merge branch 'main' into adithyase/record-of-syntax
adithyaselv Nov 18, 2024
36bac28
tests
adithyaselv Nov 19, 2024
079cc00
RecordOf UDF test
adithyaselv Nov 19, 2024
3046a16
Restrictive aggregate types in UDF
adithyaselv Nov 22, 2024
9a6f43c
fix test
adithyaselv Nov 22, 2024
2c8dcca
Merge branch 'main' into adithyase/record-of-syntax
adithyaselv Dec 2, 2024
c68111e
UDT in REPL
adithyaselv Dec 3, 2024
f2fa6ad
fix
adithyaselv Dec 4, 2024
a4aa143
Merge branch 'main' into adithyase/udf-restrictive-types
adithyaselv Dec 11, 2024
05c446c
Merge branch 'main' into adithyase/types-repl
adithyaselv Dec 13, 2024
68e86ff
.
adithyaselv Dec 13, 2024
b386621
Merge branch 'main' into adithyase/udf-restrictive-types
adithyaselv Dec 13, 2024
34f6f50
Merge branch 'adithyase/udf-restrictive-types' into adithyase/types-repl
adithyaselv Dec 13, 2024
7f5a525
improve and fix error messages
adithyaselv Dec 13, 2024
d0da3b4
Merge branch 'adithyase/udf-restrictive-types' into adithyase/types-repl
adithyaselv Dec 13, 2024
7cbae1a
Better error reporting in REPL
adithyaselv Dec 14, 2024
2d85c9f
try add types with displaynames
adithyaselv Dec 17, 2024
422a9b9
Add Tests
adithyaselv Jan 7, 2025
da6b7f3
Merge branch 'adithyase/udf-restrictive-types' into adithyase/types-repl
adithyaselv Jan 7, 2025
00c51ac
fix tests
adithyaselv Jan 7, 2025
9bd29bf
pass feature to udf bind
adithyaselv Jan 10, 2025
f638530
Merge branch 'main' into adithyase/udf-restrictive-types
adithyaselv Jun 23, 2025
2a55df4
Address review comments
adithyaselv Jul 2, 2025
944c1a4
Merge branch 'main' into adithyase/udf-restrictive-types
adithyaselv Jul 2, 2025
4eca33d
Merge branch 'adithyase/udf-restrictive-types' into adithyase/types-repl
adithyaselv Jul 2, 2025
cc77e2a
Merge branch 'main' into adithyase/types-repl
adithyaselv Jul 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ internal ParseUserDefinitionResult ApplyParse()

public bool ContainsUDF => _parse.UDFs.Any();

public bool ContainsUDT => _parse.DefinedTypes.Any();

internal IReadOnlyDictionary<DName, FormulaType> ApplyResolveTypes()
{
if (_parse == null)
Expand Down Expand Up @@ -178,7 +180,7 @@ internal TexlFunctionSet ApplyCreateUserDefinedFunctions()
foreach (var udf in partialUDFs)
{
var config = new BindingConfig(allowsSideEffects: _parserOptions.AllowsSideEffects, useThisRecordForRuleScope: false, numberIsFloat: false, userDefinitionsMode: true);
var binding = udf.BindBody(composedSymbols, new Glue2DocumentBinderGlue(), config);
var binding = udf.BindBody(composedSymbols, new Glue2DocumentBinderGlue(), config, features: _features);

List<TexlError> bindErrors = new List<TexlError>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,10 @@ internal override void DefaultExpressionValue(StringBuilder sb)

sb.Append("}");
}

public void SetFieldsOptional()
{
_type.AreFieldsOptional = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override DType Visit(TableNode node, INameResolver context)
{
Contracts.AssertValue(node);
Contracts.AssertValue(context);

if (node.ChildNodes.Count != 1)
{
return DType.Invalid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ public void UpdateSupportedFunctions(SymbolTable s)
SupportedFunctions = s;
}

public ReadOnlySymbolTable GetAllSymbols()
{
return SymbolTable.Compose(Config.ComposedConfigSymbols, SupportedFunctions, _symbolTable, PrimitiveTypes);
}

/// <summary>
/// Add a set of user-defined formulas and functions to the engine.
/// </summary>
Expand Down Expand Up @@ -420,7 +425,7 @@ public void AddUserDefinitions(string script, CultureInfo parseCulture = null, A
}

// Compose will handle null symbols
var composedSymbols = SymbolTable.Compose(Config.ComposedConfigSymbols, SupportedFunctions, PrimitiveTypes, _symbolTable);
var composedSymbols = SymbolTable.Compose(Config.ComposedConfigSymbols, SupportedFunctions, _symbolTable, PrimitiveTypes);

if (parseResult.DefinedTypes.Any())
{
Expand Down
24 changes: 20 additions & 4 deletions src/libraries/Microsoft.PowerFx.Repl/Repl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,25 +508,41 @@ await this.Output.WriteLineAsync($"Error: Can't set '{name}' to a Void value.",
definitionsCheckResult.SetText(expression, this.ParserOptions)
.ApplyParseErrors();

if (this.AllowUserDefinedFunctions && definitionsCheckResult.IsSuccess && definitionsCheckResult.ContainsUDF)
if (definitionsCheckResult.IsSuccess)
{
var defCheckResult = this.Engine.AddUserDefinedFunction(expression, this.ParserOptions.Culture, extraSymbolTable);
definitionsCheckResult.SetBindingInfo(this.Engine.GetAllSymbols());

if (!defCheckResult.IsSuccess)
if (definitionsCheckResult.ApplyErrors().Any())
{
foreach (var error in defCheckResult.Errors)
foreach (var error in definitionsCheckResult.Errors)
{
var kind = error.IsWarning ? OutputKind.Warning : OutputKind.Error;
var msg = error.ToString();

await this.Output.WriteLineAsync(lineError + msg, kind, cancel)
.ConfigureAwait(false);
}

return new ReplResult();
}

this.Engine.AddUserDefinitions(expression, this.ParserOptions.Culture);

return new ReplResult();
}

if (check.ApplyParse().Errors.Any() && definitionsCheckResult.Errors.Any())
{
foreach (var error in definitionsCheckResult.Errors)
{
var kind = error.IsWarning ? OutputKind.Warning : OutputKind.Error;
var msg = error.ToString();

await this.Output.WriteLineAsync(lineError + msg, kind, cancel)
.ConfigureAwait(false);
}
}

foreach (var error in check.Errors)
{
var kind = error.IsWarning ? OutputKind.Warning : OutputKind.Error;
Expand Down
10 changes: 10 additions & 0 deletions src/tools/Repl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ private static RecalcEngine ReplRecalcEngine()
config.AddFunction(new Run2Function());
config.AddFunction(new Language1Function());

var testRecordType = RecordType.Empty()
.Add(new NamedFormulaType("name", FormulaType.String, "Name"))
.Add(new NamedFormulaType("age", FormulaType.Number, "Age"));

testRecordType
.SetFieldsOptional();

config.SymbolTable.AddType(new Core.Utils.DName("TestRecord"), testRecordType);
config.SymbolTable.AddType(new Core.Utils.DName("TestTable"), testRecordType.ToTable());

var optionsSet = new OptionSet("Options", DisplayNameUtility.MakeUnique(options));

#if MATCHCOMPARE
Expand Down
Loading