Skip to content

Commit

Permalink
Expression matching tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Feb 4, 2024
1 parent 437deb5 commit f308a5a
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 182 deletions.
13 changes: 7 additions & 6 deletions src/Imazen.Routing/Matching/ExpressionParsingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,15 @@ public static bool TryParseCondition(ReadOnlyMemory<char> text,
[NotNullWhen(false)] out string? error)
{
var textSpan = text.Span;
if (!TryReadConditionName(textSpan, out var functionNameEnds, out error))
if (!TryReadConditionName(textSpan, out var functionNameEndsMaybe, out error))
{
functionName = null;
args = null;
return false;
}
int functionNameEnds = functionNameEndsMaybe.Value;

functionName = text[..functionNameEnds.Value];
functionName = text[..functionNameEnds];

if (functionNameEnds == text.Length)
{
Expand All @@ -184,7 +185,7 @@ public static bool TryParseCondition(ReadOnlyMemory<char> text,
return true;
}

if (textSpan[functionNameEnds.Value] != '(')
if (textSpan[functionNameEnds] != '(')
{
throw new InvalidOperationException("Unreachable code");
}
Expand All @@ -198,7 +199,7 @@ public static bool TryParseCondition(ReadOnlyMemory<char> text,
}

// now parse using unescaped commas
var argListSpan = text.Slice(functionNameEnds.Value + 1, text.Length - 1);
var argListSpan = text[(functionNameEnds + 1)..];
if (argListSpan.Length == 0)
{
error = null;
Expand All @@ -215,7 +216,7 @@ public static bool TryParseCondition(ReadOnlyMemory<char> text,
var commaIndex = FindCharNotEscaped(subSpan, ',', '\\');
if (commaIndex == -1)
{
args.Add(argListSpan[start..]);
args.Add(argListSpan[start..^1]); // no need to include the last character, it's a )
break;
}
args.Add(argListSpan.Slice(start, commaIndex));
Expand Down Expand Up @@ -260,7 +261,7 @@ public static ArgType GetArgType(ReadOnlySpan<char> arg)
type &= ~ArgType.DecimalNumeric;
}
if (arg.Length == 1) type |= ArgType.Char;
else type |= ArgType.String;
type |= ArgType.String;
return type;
}

Expand Down
Loading

0 comments on commit f308a5a

Please sign in to comment.