Class LabelScanUtil
- Namespace
- Hi.NcParsers.EvaluationSyntaxs
- Assembly
- HiMech.dll
Shared “re-segment a file and skip pieces until a label matches”
scan, used by both
FanucGotoSyntax (unconditional GOTO redirect)
and SubProgramReturnSyntax (M99 P{seq} jump
into the caller file). Reads the file via
ReadLines(int, string, string), segments through the
provided ISegmenter, 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'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).
public static class LabelScanUtil
- Inheritance
-
LabelScanUtil
- Inherited Members
Methods
SegmentAndSkipUntilLabel(ISegmenter, List<INcDependency>, string, string, int, int, List<ISituNcSyntax>, Func<JsonObject, bool>, NcDiagnosticProgress)
Predicate-driven overload. The caller supplies match
as the per-candidate gate (run on the candidate block's
JsonObject after the probe syntaxes have
finished stamping). This unblocks scans whose label representation
differs from IndexNote.Number —
for example END m blocks identified by a custom probe-written
section, where reusing IndexNote would collide with
real N{m} head indices in the same file.
The default targetN overload delegates here with the
IndexNote.Number == targetN predicate baked in; existing
callers (Fanuc unconditional GOTO, M99 P{seq} jump) are unchanged.
public static List<SyntaxPiece> SegmentAndSkipUntilLabel(ISegmenter segmenter, List<INcDependency> ncDependencyList, string absPath, string labelPath, int fileIndex, int sentenceIndexBegin, List<ISituNcSyntax> probeSyntaxes, Func<JsonObject, bool> match, NcDiagnosticProgress diag)
Parameters
segmenterISegmenterSegmenter used to slice the file into Sentence blocks.
ncDependencyListList<INcDependency>NC dependency list forwarded to GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) while re-segmenting the scanned file.
absPathstringAbsolute path to read line content from.
labelPathstringProject-relative path to stamp on each line's IndexedFileLine label.
fileIndexintFresh file index to stamp on each scanned line, allocated by the caller from FileIndexCounterDependency.
sentenceIndexBeginintStarting execution-order index for the produced pieces.
probeSyntaxesList<ISituNcSyntax>Ordered list of helper syntaxes to run on each candidate block before the predicate check. May be null.
matchFunc<JsonObject, bool>Per-candidate predicate;
trueselects the first match.diagNcDiagnosticProgressSink for any diagnostics produced by the probe syntaxes.
Returns
SegmentAndSkipUntilLabel(ISegmenter, List<INcDependency>, string, string, int, int, int, List<ISituNcSyntax>, NcDiagnosticProgress)
Re-segments absPath from offset 0, scans for
a block whose Number equals
targetN (after the
probeSyntaxes have stamped it in-place), and
returns the sub-list of pieces from that block to EOF.
Pieces are produced via
GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) with
SentenceIndex stamped starting at
sentenceIndexBegin. Returns null when
no match is found; the caller emits its own brand-specific
“label not found” diagnostic.
The predicate is fixed at the
IndexNote.Number section
— the section name comes from nameof() 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
IndexNote on candidates is by definition not
participating in this scan.
public static List<SyntaxPiece> SegmentAndSkipUntilLabel(ISegmenter segmenter, List<INcDependency> ncDependencyList, string absPath, string labelPath, int fileIndex, int sentenceIndexBegin, int targetN, List<ISituNcSyntax> probeSyntaxes, NcDiagnosticProgress diag)
Parameters
segmenterISegmenterSegmenter used to slice the file into Sentence blocks.
ncDependencyListList<INcDependency>NC dependency list forwarded to GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) while re-segmenting the scanned file.
absPathstringAbsolute path to read line content from.
labelPathstringProject-relative path to stamp on each line's IndexedFileLine label (so diagnostics anchor to a relative form, not the resolver's transient absolute path).
fileIndexintFresh file index to stamp on each scanned line, allocated by the caller from FileIndexCounterDependency.
sentenceIndexBeginintStarting execution-order index for the produced pieces.
targetNintInteger label target to match against Number.
probeSyntaxesList<ISituNcSyntax>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.
diagNcDiagnosticProgressSink for any diagnostics produced by the probe syntaxes (e.g. comment-stripper malformed-comment warnings).