Table of Contents

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

SegmentAndRewindToLine(ISegmenter, List<INcDependency>, string, string, int, int, int, NcDiagnosticProgress)

Re-segments absPath and returns the slice starting at the first piece whose file line index equals beginLineIndex — the loop back-jump primitive (no label predicate, no probes). Extracted from the Fanuc WHILE/END reverse jump so the Siemens loop family shares the same engine; FanucWhileDoSyntax delegates here unchanged. Returns null when the line did not materialise as a segment start.

public static List<SyntaxPiece> SegmentAndRewindToLine(ISegmenter segmenter, List<INcDependency> ncDependencyList, string absPath, string labelPath, int fileIndex, int sentenceIndexBegin, int beginLineIndex, NcDiagnosticProgress diag)

Parameters

segmenter ISegmenter

Segmenter used to slice the file into Sentence blocks.

ncDependencyList List<INcDependency>

NC dependency list forwarded to GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) while re-segmenting the file.

absPath string

Absolute path to read line content from.

labelPath string

Project-relative path to stamp on each line's IndexedFileLine label.

fileIndex int

Fresh file index to stamp on each line, allocated by the caller from FileIndexCounterDependency.

sentenceIndexBegin int

Legacy fallback starting index — ignored when the pipeline carries a SentenceIndexCounterDependency.

beginLineIndex int

0-based file line index of the block to rewind to (the loop-entry line).

diag NcDiagnosticProgress

Diagnostic sink for the re-segmentation.

Returns

List<SyntaxPiece>

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

segmenter ISegmenter

Segmenter used to slice the file into Sentence blocks.

ncDependencyList List<INcDependency>

NC dependency list forwarded to GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) while re-segmenting the scanned file.

absPath string

Absolute path to read line content from.

labelPath string

Project-relative path to stamp on each line's IndexedFileLine label.

fileIndex int

Fresh file index to stamp on each scanned line, allocated by the caller from FileIndexCounterDependency.

sentenceIndexBegin int

Legacy fallback starting index for the produced pieces — ignored when the pipeline carries a SentenceIndexCounterDependency.

probeSyntaxes List<ISituNcSyntax>

Ordered list of helper syntaxes to run on each candidate block before the predicate check. May be null.

match Func<JsonObject, bool>

Per-candidate predicate; true selects the first match.

diag NcDiagnosticProgress

Sink for any diagnostics produced by the probe syntaxes.

Returns

List<SyntaxPiece>

SegmentAndSkipUntilLabel(ISegmenter, List<INcDependency>, string, string, int, int, List<ISituNcSyntax>, Func<JsonObject, bool>, int, LabelScanDirection, NcDiagnosticProgress)

Anchored, direction-aware overload for the Siemens GOTOF/GOTOB family (and any other scan that must not see the whole file). The two legacy overloads above always scan the whole file top-down and take the first match — that cannot express “forward only, from the jump site” (GOTOF) or “nearest label above the jump site” (GOTOB), and it silently mis-targets when the same label text appears both before and after the host line. Semantics here:

  • ForwardFromAnchor — only candidates whose file line index is strictly greater than anchorLineIndex are probed and matched; the first match wins.
  • BackwardNearestToAnchor — only candidates strictly above anchorLineIndex are probed and matched; the last match (largest line index — nearest to the anchor) wins.
Candidates without a resolvable line index are skipped. The returned slice runs from the matched block (inclusive — a label line may carry trailing code) to EOF, exactly like the legacy overloads; a backward jump is still "replace the source with the slice from the target down", the same shape the WHILE reverse jump uses. Returns null when no candidate matches.
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, int anchorLineIndex, LabelScanDirection direction, NcDiagnosticProgress diag)

Parameters

segmenter ISegmenter

Segmenter used to slice the file into Sentence blocks.

ncDependencyList List<INcDependency>

NC dependency list forwarded to GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) while re-segmenting the scanned file.

absPath string

Absolute path to read line content from.

labelPath string

Project-relative path to stamp on each line's IndexedFileLine label.

fileIndex int

Fresh file index to stamp on each scanned line, allocated by the caller from FileIndexCounterDependency.

sentenceIndexBegin int

Legacy fallback starting index for the produced pieces — ignored when the pipeline carries a SentenceIndexCounterDependency.

probeSyntaxes List<ISituNcSyntax>

Ordered list of helper syntaxes to run on each in-region candidate before the predicate check. May be null.

match Func<JsonObject, bool>

Per-candidate predicate on the probed block's JSON.

anchorLineIndex int

0-based file line index of the jump host block; the scan region excludes this line itself.

direction LabelScanDirection

Scan region and match policy relative to the anchor.

diag NcDiagnosticProgress

Sink for any diagnostics produced by the probe syntaxes.

Returns

List<SyntaxPiece>

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), which stamps SentenceIndex from the session's SentenceIndexCounterDependency when present (the whole re-segmented file is numbered eagerly, so the discarded pre-label prefix leaves a gap in the sequence) and falls back to contiguous numbering from sentenceIndexBegin otherwise. 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

segmenter ISegmenter

Segmenter used to slice the file into Sentence blocks.

ncDependencyList List<INcDependency>

NC dependency list forwarded to GetSyntaxPieces(ISegmenter, List<INcDependency>, IEnumerable<IndexedFileLine>, int, NcDiagnosticProgress, CancellationToken) while re-segmenting the scanned file.

absPath string

Absolute path to read line content from.

labelPath string

Project-relative path to stamp on each line's IndexedFileLine label (so diagnostics anchor to a relative form, not the resolver's transient absolute path).

fileIndex int

Fresh file index to stamp on each scanned line, allocated by the caller from FileIndexCounterDependency.

sentenceIndexBegin int

Legacy fallback starting index for the produced pieces — ignored when the pipeline carries a SentenceIndexCounterDependency.

targetN int

Integer label target to match against Number.

probeSyntaxes List<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.

diag NcDiagnosticProgress

Sink for any diagnostics produced by the probe syntaxes (e.g. comment-stripper malformed-comment warnings).

Returns

List<SyntaxPiece>