HiNC-2025-win-desktop-Deploy/App/wwwroot/HiAPI-docsite/api/Hi.NcParsers.EvaluationSyntaxs.LabelScanUtil.html

355 lines
20 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Class LabelScanUtil | HiAPI-C# 2025 </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Class LabelScanUtil | HiAPI-C# 2025 ">
<meta name="description" content="Shared &amp;ldquo;re-segment a file and skip pieces until a label matches&amp;rdquo; scan, used by both (unconditional GOTO redirect) and (M99 P{seq} jump into the caller file). Reads the file via , segments through the provided , runs the caller-supplied probe syntaxes on each candidate block to extract IndexNote.Number, and returns the slice from the first matching block to EOF. Returns null when no block matches — the caller&#39;s responsibility to surface the appropriate diagnostic. The probes are idempotent because the downstream Parsing bundle re-runs the same syntaxes on the yielded pieces with no-op effect (the regex patterns no longer match once the N-prefix is consumed and the parenthesised comment stripped).">
<link rel="icon" href="../img/HiAPI.favicon.ico">
<link rel="stylesheet" href="../public/docfx.min.css">
<link rel="stylesheet" href="../public/main.css">
<meta name="docfx:navrel" content="../toc.html">
<meta name="docfx:tocrel" content="toc.html">
<meta name="docfx:rel" content="../">
<meta name="loc:inThisArticle" content="In this article">
<meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<meta name="loc:tocFilter" content="Filter by title">
<meta name="loc:nextArticle" content="Next">
<meta name="loc:prevArticle" content="Previous">
<meta name="loc:themeLight" content="Light">
<meta name="loc:themeDark" content="Dark">
<meta name="loc:themeAuto" content="Auto">
<meta name="loc:changeTheme" content="Change theme">
<meta name="loc:copy" content="Copy">
<meta name="loc:downloadPdf" content="Download PDF">
<script type="module" src="./../public/docfx.min.js"></script>
<script>
const theme = localStorage.getItem('theme') || 'auto'
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
</script>
</head>
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
<header class="bg-body border-bottom">
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
<div class="container-xxl flex-nowrap">
<a class="navbar-brand" href="../index.html">
<img id="logo" class="svg" src="../img/HiAPI.logo.png" alt="">
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
</form>
</div>
</div>
</div>
</nav>
</header>
<main class="container-xxl">
<div class="toc-offcanvas">
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<nav class="toc" id="toc"></nav>
</div>
</div>
</div>
<div class="content">
<div class="actionbar">
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
<i class="bi bi-list"></i>
</button>
<nav id="breadcrumb"></nav>
</div>
<article data-uid="Hi.NcParsers.EvaluationSyntaxs.LabelScanUtil">
<h1 id="Hi_NcParsers_EvaluationSyntaxs_LabelScanUtil" data-uid="Hi.NcParsers.EvaluationSyntaxs.LabelScanUtil" class="text-break">
Class LabelScanUtil
</h1>
<div class="facts text-secondary">
<dl><dt>Namespace</dt><dd><a class="xref" href="Hi.html">Hi</a>.<a class="xref" href="Hi.NcParsers.html">NcParsers</a>.<a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.html">EvaluationSyntaxs</a></dd></dl>
<dl><dt>Assembly</dt><dd>HiMech.dll</dd></dl>
</div>
<div class="markdown summary"><p>Shared &ldquo;re-segment a file and skip pieces until a label matches&rdquo;
scan, used by both
<a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.Fanuc.FanucGotoSyntax.html">FanucGotoSyntax</a> (unconditional GOTO redirect)
and <a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.SubProgramReturnSyntax.html">SubProgramReturnSyntax</a> (<code>M99 P{seq}</code> jump
into the caller file). Reads the file via
<a class="xref" href="Hi.NcParsers.EvaluationSyntaxs.MacroFileResolver.html#Hi_NcParsers_EvaluationSyntaxs_MacroFileResolver_ReadLines_System_Int32_System_String_System_String_">ReadLines(int, string, string)</a>, segments through the
provided <a class="xref" href="Hi.NcParsers.Segmenters.ISegmenter.html">ISegmenter</a>, runs the
caller-supplied probe syntaxes on each candidate block to
extract <code>IndexNote.Number</code>, and returns the slice from the
first matching block to EOF.</p>
<p>
Returns <code>null</code> when no block matches — the caller's
responsibility to surface the appropriate diagnostic. The probes
are idempotent because the downstream Parsing bundle re-runs the
same syntaxes on the yielded pieces with no-op effect (the regex
patterns no longer match once the N-prefix is consumed and the
parenthesised comment stripped).
</p>
</div>
<div class="markdown conceptual"></div>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static class LabelScanUtil</code></pre>
</div>
<dl class="typelist inheritance">
<dt>Inheritance</dt>
<dd>
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
<div><span class="xref">LabelScanUtil</span></div>
</dd>
</dl>
<dl class="typelist inheritedMembers">
<dt>Inherited Members</dt>
<dd>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
</div>
<div>
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
</div>
</dd></dl>
<h2 class="section" id="methods">Methods
</h2>
<a id="Hi_NcParsers_EvaluationSyntaxs_LabelScanUtil_SegmentAndSkipUntilLabel_" data-uid="Hi.NcParsers.EvaluationSyntaxs.LabelScanUtil.SegmentAndSkipUntilLabel*"></a>
<h3 id="Hi_NcParsers_EvaluationSyntaxs_LabelScanUtil_SegmentAndSkipUntilLabel_Hi_NcParsers_Segmenters_ISegmenter_System_Collections_Generic_List_Hi_NcParsers_Dependencys_INcDependency__System_String_System_String_System_Int32_System_Int32_System_Collections_Generic_List_Hi_NcParsers_Syntaxs_ISituNcSyntax__System_Func_System_Text_Json_Nodes_JsonObject_System_Boolean__Hi_NcParsers_NcDiagnosticProgress_" data-uid="Hi.NcParsers.EvaluationSyntaxs.LabelScanUtil.SegmentAndSkipUntilLabel(Hi.NcParsers.Segmenters.ISegmenter,System.Collections.Generic.List{Hi.NcParsers.Dependencys.INcDependency},System.String,System.String,System.Int32,System.Int32,System.Collections.Generic.List{Hi.NcParsers.Syntaxs.ISituNcSyntax},System.Func{System.Text.Json.Nodes.JsonObject,System.Boolean},Hi.NcParsers.NcDiagnosticProgress)">
SegmentAndSkipUntilLabel(ISegmenter, List&lt;INcDependency&gt;, string, string, int, int, List&lt;ISituNcSyntax&gt;, Func&lt;JsonObject, bool&gt;, NcDiagnosticProgress)
</h3>
<div class="markdown level1 summary"><p>Predicate-driven overload. The caller supplies <code class="paramref">match</code>
as the per-candidate gate (run on the candidate block's
<a class="xref" href="Hi.NcParsers.Syntaxs.SyntaxPiece.html#Hi_NcParsers_Syntaxs_SyntaxPiece_JsonObject">JsonObject</a> after the probe syntaxes have
finished stamping). This unblocks scans whose label representation
differs from <a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html">IndexNote</a>.<a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html#Hi_NcParsers_Keywords_IndexNote_Number">Number</a>
for example <code>END m</code> blocks identified by a custom probe-written
section, where reusing <a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html">IndexNote</a> would collide with
real <code>N{m}</code> head indices in the same file.</p>
<p>
The default <code>targetN</code> overload delegates here with the
<code>IndexNote.Number == targetN</code> predicate baked in; existing
callers (Fanuc unconditional GOTO, M99 P{seq} jump) are unchanged.
</p>
</div>
<div class="markdown level1 conceptual"></div>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static List&lt;SyntaxPiece&gt; SegmentAndSkipUntilLabel(ISegmenter segmenter, List&lt;INcDependency&gt; ncDependencyList, string absPath, string labelPath, int fileIndex, int sentenceIndexBegin, List&lt;ISituNcSyntax&gt; probeSyntaxes, Func&lt;JsonObject, bool&gt; match, NcDiagnosticProgress diag)</code></pre>
</div>
<h4 class="section">Parameters</h4>
<dl class="parameters">
<dt><code>segmenter</code> <a class="xref" href="Hi.NcParsers.Segmenters.ISegmenter.html">ISegmenter</a></dt>
<dd><p>Segmenter used to slice the file into <a class="xref" href="Hi.NcParsers.Sentence.html">Sentence</a> blocks.</p>
</dd>
<dt><code>ncDependencyList</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a>&lt;<a class="xref" href="Hi.NcParsers.Dependencys.INcDependency.html">INcDependency</a>&gt;</dt>
<dd><p>NC dependency list forwarded to <a class="xref" href="Hi.NcParsers.Segmenters.ISegmenter.html">GetSyntaxPieces(ISegmenter, List&lt;INcDependency&gt;, IEnumerable&lt;IndexedFileLine&gt;, int, NcDiagnosticProgress, CancellationToken)</a> while re-segmenting the scanned file.</p>
</dd>
<dt><code>absPath</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd><p>Absolute path to read line content from.</p>
</dd>
<dt><code>labelPath</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd><p>Project-relative path to stamp on each line's <a class="xref" href="Hi.Common.FileLines.IndexedFileLine.html">IndexedFileLine</a> label.</p>
</dd>
<dt><code>fileIndex</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
<dd><p>Fresh file index to stamp on each scanned line, allocated by the caller from <a class="xref" href="Hi.NcParsers.Dependencys.SystemWired.FileIndexCounterDependency.html">FileIndexCounterDependency</a>.</p>
</dd>
<dt><code>sentenceIndexBegin</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
<dd><p>Starting execution-order index for the produced pieces.</p>
</dd>
<dt><code>probeSyntaxes</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a>&lt;<a class="xref" href="Hi.NcParsers.Syntaxs.ISituNcSyntax.html">ISituNcSyntax</a>&gt;</dt>
<dd><p>Ordered list of helper syntaxes to run on each candidate block before the predicate check. May be null.</p>
</dd>
<dt><code>match</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.text.json.nodes.jsonobject">JsonObject</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a>&gt;</dt>
<dd><p>Per-candidate predicate; <code>true</code> selects the first match.</p>
</dd>
<dt><code>diag</code> <a class="xref" href="Hi.NcParsers.NcDiagnosticProgress.html">NcDiagnosticProgress</a></dt>
<dd><p>Sink for any diagnostics produced by the probe syntaxes.</p>
</dd>
</dl>
<h4 class="section">Returns</h4>
<dl class="parameters">
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a>&lt;<a class="xref" href="Hi.NcParsers.Syntaxs.SyntaxPiece.html">SyntaxPiece</a>&gt;</dt>
<dd></dd>
</dl>
<a id="Hi_NcParsers_EvaluationSyntaxs_LabelScanUtil_SegmentAndSkipUntilLabel_" data-uid="Hi.NcParsers.EvaluationSyntaxs.LabelScanUtil.SegmentAndSkipUntilLabel*"></a>
<h3 id="Hi_NcParsers_EvaluationSyntaxs_LabelScanUtil_SegmentAndSkipUntilLabel_Hi_NcParsers_Segmenters_ISegmenter_System_Collections_Generic_List_Hi_NcParsers_Dependencys_INcDependency__System_String_System_String_System_Int32_System_Int32_System_Int32_System_Collections_Generic_List_Hi_NcParsers_Syntaxs_ISituNcSyntax__Hi_NcParsers_NcDiagnosticProgress_" data-uid="Hi.NcParsers.EvaluationSyntaxs.LabelScanUtil.SegmentAndSkipUntilLabel(Hi.NcParsers.Segmenters.ISegmenter,System.Collections.Generic.List{Hi.NcParsers.Dependencys.INcDependency},System.String,System.String,System.Int32,System.Int32,System.Int32,System.Collections.Generic.List{Hi.NcParsers.Syntaxs.ISituNcSyntax},Hi.NcParsers.NcDiagnosticProgress)">
SegmentAndSkipUntilLabel(ISegmenter, List&lt;INcDependency&gt;, string, string, int, int, int, List&lt;ISituNcSyntax&gt;, NcDiagnosticProgress)
</h3>
<div class="markdown level1 summary"><p>Re-segments <code class="paramref">absPath</code> from offset 0, scans for
a block whose <a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html#Hi_NcParsers_Keywords_IndexNote_Number">Number</a> equals
<code class="paramref">targetN</code> (after the
<code class="paramref">probeSyntaxes</code> have stamped it in-place), and
returns the sub-list of pieces from that block to EOF.
Pieces are produced via
<a class="xref" href="Hi.NcParsers.Segmenters.ISegmenter.html">GetSyntaxPieces(ISegmenter, List&lt;INcDependency&gt;, IEnumerable&lt;IndexedFileLine&gt;, int, NcDiagnosticProgress, CancellationToken)</a> with
<code>SentenceIndex</code> stamped starting at
<code class="paramref">sentenceIndexBegin</code>. Returns <code>null</code> when
no match is found; the caller emits its own brand-specific
&ldquo;label not found&rdquo; diagnostic.</p>
<p>
The predicate is fixed at the
<a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html">IndexNote</a>.<a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html#Hi_NcParsers_Keywords_IndexNote_Number">Number</a> section
— the section name comes from <code>nameof()</code> so a future rename
propagates without re-edits. Reconfigurability for non-standard
label-output sections is achieved by replacing the probe syntaxes
(the natural extension point) rather than parameterising the
predicate path here: a probe stack that doesn't end up writing
<a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html">IndexNote</a> on candidates is by definition not
participating in this scan.
</p>
</div>
<div class="markdown level1 conceptual"></div>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static List&lt;SyntaxPiece&gt; SegmentAndSkipUntilLabel(ISegmenter segmenter, List&lt;INcDependency&gt; ncDependencyList, string absPath, string labelPath, int fileIndex, int sentenceIndexBegin, int targetN, List&lt;ISituNcSyntax&gt; probeSyntaxes, NcDiagnosticProgress diag)</code></pre>
</div>
<h4 class="section">Parameters</h4>
<dl class="parameters">
<dt><code>segmenter</code> <a class="xref" href="Hi.NcParsers.Segmenters.ISegmenter.html">ISegmenter</a></dt>
<dd><p>Segmenter used to slice the file into <a class="xref" href="Hi.NcParsers.Sentence.html">Sentence</a> blocks.</p>
</dd>
<dt><code>ncDependencyList</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a>&lt;<a class="xref" href="Hi.NcParsers.Dependencys.INcDependency.html">INcDependency</a>&gt;</dt>
<dd><p>NC dependency list forwarded to <a class="xref" href="Hi.NcParsers.Segmenters.ISegmenter.html">GetSyntaxPieces(ISegmenter, List&lt;INcDependency&gt;, IEnumerable&lt;IndexedFileLine&gt;, int, NcDiagnosticProgress, CancellationToken)</a> while re-segmenting the scanned file.</p>
</dd>
<dt><code>absPath</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd><p>Absolute path to read line content from.</p>
</dd>
<dt><code>labelPath</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
<dd><p>Project-relative path to stamp on each line's <a class="xref" href="Hi.Common.FileLines.IndexedFileLine.html">IndexedFileLine</a> label (so diagnostics anchor to a relative form, not the resolver's transient absolute path).</p>
</dd>
<dt><code>fileIndex</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
<dd><p>Fresh file index to stamp on each scanned line, allocated by the caller from <a class="xref" href="Hi.NcParsers.Dependencys.SystemWired.FileIndexCounterDependency.html">FileIndexCounterDependency</a>.</p>
</dd>
<dt><code>sentenceIndexBegin</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
<dd><p>Starting execution-order index for the produced pieces.</p>
</dd>
<dt><code>targetN</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
<dd><p>Integer label target to match against <a class="xref" href="Hi.NcParsers.Keywords.IndexNote.html#Hi_NcParsers_Keywords_IndexNote_Number">Number</a>.</p>
</dd>
<dt><code>probeSyntaxes</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a>&lt;<a class="xref" href="Hi.NcParsers.Syntaxs.ISituNcSyntax.html">ISituNcSyntax</a>&gt;</dt>
<dd><p>Ordered list of helper syntaxes to run on each candidate block before the predicate check (typically comment-stripper(s) followed by a head-index parser). May be null.</p>
</dd>
<dt><code>diag</code> <a class="xref" href="Hi.NcParsers.NcDiagnosticProgress.html">NcDiagnosticProgress</a></dt>
<dd><p>Sink for any diagnostics produced by the probe syntaxes (e.g. comment-stripper malformed-comment warnings).</p>
</dd>
</dl>
<h4 class="section">Returns</h4>
<dl class="parameters">
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a>&lt;<a class="xref" href="Hi.NcParsers.Syntaxs.SyntaxPiece.html">SyntaxPiece</a>&gt;</dt>
<dd></dd>
</dl>
</article>
<div class="contribution d-print-none">
</div>
</div>
<div class="affix">
<nav id="affix"></nav>
</div>
</main>
<div class="container-xxl search-results" id="search-results"></div>
<footer class="border-top text-secondary">
<div class="container-xxl">
<div class="flex-fill">
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
</div>
</div>
</footer>
</body>
</html>