namespace ZB.MOM.WW.OtOpcUa.Core.Scripting; using System.Text.RegularExpressions; /// /// Classifies the trivial "mirror" VirtualTag script shape return ctx.GetTag("X").Value;, /// 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. /// /// /// Physically defined in the Core.Scripting.Abstractions assembly (Roslyn-free, so ControlPlane /// can reference it); the namespace is Core.Scripting to keep consumer using-directives unchanged. /// public static partial class PassthroughScript { // ^ \s* return \s+ ctx . GetTag ( "X" ) . Value ; \s* $ (whitespace-tolerant around tokens) // Tag-name class [^"\\] excludes both the closing quote and backslash: a literal containing a // backslash escape (e.g. "a\\b" → runtime name a\b) won't match, so it correctly falls through // to Roslyn, which interprets the escape and resolves the actual dependency key. [GeneratedRegex(@"^\s*return\s+ctx\s*\.\s*GetTag\s*\(\s*""([^""\\]+)""\s*\)\s*\.\s*Value\s*;\s*$")] private static partial Regex MirrorRegex(); /// True if is the mirror passthrough shape; outputs the referenced tag. /// The VirtualTag script source to classify. /// On success, the tag reference captured from the mirror shape; otherwise empty. /// if the source is the mirror passthrough shape; otherwise . 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; } }