feat(vtag): passthrough fast-path skips Roslyn for mirror scripts (A)

This commit is contained in:
Joseph Doherty
2026-06-07 15:26:20 -04:00
parent 3834400f05
commit 08d7477860
5 changed files with 256 additions and 3 deletions
@@ -0,0 +1,29 @@
namespace ZB.MOM.WW.OtOpcUa.Core.Scripting;
using System.Text.RegularExpressions;
/// <summary>
/// Classifies the trivial "mirror" VirtualTag script shape <c>return ctx.GetTag("X").Value;</c>,
/// which can be evaluated by returning the dependency value directly — no Roslyn compilation.
/// Narrow, exact pattern: any near-miss returns false and falls through to the Roslyn path.
/// </summary>
public static partial class PassthroughScript
{
// ^ \s* return \s+ ctx . GetTag ( "X" ) . Value ; \s* $ (whitespace-tolerant around tokens)
[GeneratedRegex(@"^\s*return\s+ctx\s*\.\s*GetTag\s*\(\s*""([^""]+)""\s*\)\s*\.\s*Value\s*;\s*$")]
private static partial Regex MirrorRegex();
/// <summary>True if <paramref name="source"/> is the mirror passthrough shape; outputs the referenced tag.</summary>
/// <param name="source">The VirtualTag script source to classify.</param>
/// <param name="tagRef">On success, the tag reference captured from the mirror shape; otherwise empty.</param>
/// <returns><see langword="true"/> if the source is the mirror passthrough shape; otherwise <see langword="false"/>.</returns>
public static bool TryMatch(string? source, out string tagRef)
{
tagRef = string.Empty;
if (string.IsNullOrEmpty(source)) return false;
var m = MirrorRegex().Match(source);
if (!m.Success) return false;
tagRef = m.Groups[1].Value;
return true;
}
}