Table of Contents

Class MacroFileResolver

Namespace
Hi.NcParsers.EvaluationSyntaxs
Assembly
HiMech.dll

Shared subprogram-/macro-file resolver for Fanuc-style O<n> lookups consumed by SubProgramCallSyntax (M98 / M198) and FanucMacroCallSyntax (G65). Single helper so the three path forms — file name, project-relative path, absolute path — are produced together at one site and each caller gets exactly the form it should consume:

  • FileName — bare O####.NC form the resolver matched. Stored in JSON sections (FanucMacroCall, SubProgramCall) as the structural NC-language identifier; independent of which folder the dependency happened to be pointing at, so the JSON stays portable across environments.
  • RelPath — relative path against the project base directory (e.g. "NC/O1234.NC"). Used as the IndexedFileLine label so diagnostics on inlined blocks align with the relative form already used for the main file label.
  • AbsPath — absolute path. Used only at the ReadLines(int, string, string) call site for actual disk I/O; never persisted, never returned to JSON. Lives inside the resolver's stack frame and the segmenter's enumeration.

Filename lookup order (first match wins) mirrors real Fanuc fallback: O{P:D4}.NC, O{P}.NC, O{P:D4}, O{P}, {P:D4}.NC, {P}.NC. Case-insensitive match is delegated to the host filesystem (Windows is, Linux is not).

public static class MacroFileResolver
Inheritance
MacroFileResolver
Inherited Members

Fields

FilenamePatterns

Filename-resolution fallback chain. Patterns are formatted with the P parameter as the only positional arg.

public static readonly string[] FilenamePatterns

Field Value

string[]

Methods

ReadLines(int, string, string)

Streams IndexedFileLine entries from absPath but stamps each entry's FilePath with the project-relative labelPath. Mirrors the manual loop in GetIndexedFileLines(string, IEnumerable<string>, int, NcDiagnosticProgress, CancellationToken) for the main file so inlined macros stay consistent with the rest of the pipeline (diagnostics anchored to a relative label, not the resolver's transient absolute path).

public static IEnumerable<IndexedFileLine> ReadLines(int fileIndex, string absPath, string labelPath)

Parameters

fileIndex int
absPath string
labelPath string

Returns

IEnumerable<IndexedFileLine>

Resolve(string, int, string)

Resolves an O<p> file against the given folder, returning all three path forms. Returns null when the folder cannot be anchored (relative folder but no baseDirectory), the resolved folder does not exist, or no filename pattern matched.

folder may be absolute (used as-is) or relative (combined with baseDirectory). Empty / null folder means "look directly in baseDirectory". When the folder is absolute, RelPath falls back to absolute too — there's no natural relative form when the user explicitly configured an out-of-project folder.

public static MacroFileResolver.ResolvedFile? Resolve(string folder, int p, string baseDirectory)

Parameters

folder string
p int
baseDirectory string

Returns

MacroFileResolver.ResolvedFile?