Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gregli-msft committed Mar 7, 2025
1 parent 2b74c5a commit 3fc069c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/regular-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The regular expression must be a constant and not calculated or stored in a vari

Octal codes for characters, such as `\044` or `\o{044}` are disallowed, as they can be ambiguous with numbered back references. Use `\x` or `\u` instead.

`\v` is not supported as it ambiguous across regular expression languages. Use `\x0b` for a vertical tab or `[\x0b\f\r\n\u2028\u2029]` for vertical whitespace.
`\v` is not supported as it ambiguous across regular expression languages. Use `\x0b` for a vertical tab or `[\x0b\f\r\n\x85\u2028\u2029]` for vertical whitespace.

### Assertions

Expand Down
14 changes: 9 additions & 5 deletions src/libraries/Microsoft.PowerFx.Core/Binding/BinderUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.PowerFx.Core.App.Controls;
using Microsoft.PowerFx.Core.App.ErrorContainers;
Expand Down Expand Up @@ -1508,21 +1507,26 @@ public static bool TryGetConstantValue(CheckTypesContext context, TexlNode node,
{
case NodeKind.StrInterp:
var strInterpNode = node.AsStrInterp();
StringBuilder strInterpValue = new StringBuilder();
var segments = new List<string>();
foreach (var segmentNode in strInterpNode.Children)
{
if (TryGetConstantValue(context, segmentNode, out var segmentValue))
{
strInterpValue.Append(segmentValue);
segments.Append(segmentValue);
}
else
{
break;
}
}

nodeValue = strInterpValue.ToString();
return true;
if (segments.Count == strInterpNode.Children.Count)
{
nodeValue = string.Join(string.Empty, segments);
return true;
}

break;
case NodeKind.StrLit:
nodeValue = node.AsStrLit().Value;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,8 @@ Errors: Error 17-31: Regular expression must be a constant value.|Error 0-7: The
>> IsMatch( "asdf", "asdf", If( Int(4) > -1, MatchOptions.IgnoreCase, MatchOptions.Contains ) )
Errors: Error 25-90: MatchOptions must be a constant value.|Error 0-7: The function 'IsMatch' has some invalid arguments.

// String interpolation is supported
// String interpolation is supported for constant regular expression pattern

>> Match( "asdf", $"a{ Char(115) }{ UniChar(100) }f" )
{FullMatch:"asdf",StartMatch:1}

Expand All @@ -1462,6 +1463,12 @@ Errors: Error 25-90: MatchOptions must be a constant value.|Error 0-7: The funct
>> Match( "asdf", "a" & $"{Char(115)}" & $"{UniChar(100)}" & "f" )
{FullMatch:"asdf",StartMatch:1}

>> Match( "asdf", "a" & $"{Char(Len("asdf"&"asdf"))}" & $"{UniChar(100)}" & "f" )
Errors: Error 71-72: Regular expression must be a constant value.|Error 0-5: The function 'Match' has some invalid arguments.

>> Match( "asdf", "a" & $"{Char(114+1)}" & $"{UniChar(100)}" & "f" )
Errors: Error 58-59: Regular expression must be a constant value.|Error 0-5: The function 'Match' has some invalid arguments.

// leading zeros on quant support

>> Match( "aaaaaa", "a{00002,}" )
Expand Down

0 comments on commit 3fc069c

Please sign in to comment.