Class SoftNcUtil
JSON helpers for soft-NC blocks: vectors under Parsing, motion-term queries, flag grab/remove on raw text, and unparsed-line trimming.
public static class SoftNcUtil
- Inheritance
-
SoftNcUtil
- Inherited Members
Properties
RegexFlagPrefix
Regex prefix pattern that matches word boundary, after digit, after whitespace, or at start of string. The whitespace/start-of-string alternatives are needed for non-word-character prefixes (e.g. Fanuc '#', Siemens '$').
public static string RegexFlagPrefix { get; }
Property Value
Methods
GetMachineStateDouble(JsonObject, string)
Reads a numeric tag from a machine-state section (one written by
a LogicSyntax / Semantic with explicit numeric values, not from the
parser stage). Used by backward-walk lookback paths
(ProgramXyzUtil FindPrevious*,
FindPreviousState on Feedrate/SpindleSpeed/IsoLocalCoordinateOffset,
modal arc-/linear-feedrate prev-block reads, etc.) where the data is
supposed to be guaranteed numeric and any non-numeric is a HiAPIs
codegen bug rather than an unevaluated user expression.
- Tag missing → returns
nullsilently (the section may not have been written on a previous block; caller's?? defaultchain handles it). - Tag present and numeric → returns the value.
- Tag present but non-numeric → throws InvalidOperationException immediately. The stack trace anchors the bug at the read site (which is the right place to investigate — the originating block has already passed). Continuing with NaN/0 would silently propagate corrupt coordinates downstream and is more dangerous than crashing the run.
public static double? GetMachineStateDouble(this JsonObject section, string key)
Parameters
sectionJsonObjectkeystring
Returns
GetMachineStateVec3d(JsonObject, string)
Vec3d reader for machine-state sections (written
by upstream LogicSyntaxes / Semantics with explicit numeric values).
Section missing → returns null; individual missing X/Y/Z
components fall through to NaN; a non-numeric
value at any of X/Y/Z throws via
GetMachineStateDouble(JsonObject, string) — non-numeric here is a HiAPIs
codegen bug, not a user-facing unevaluated expression, and silently
degrading to NaN/0 would propagate corrupt coordinates downstream.
public static Vec3d GetMachineStateVec3d(JsonObject json, string sectionKey)
Parameters
jsonJsonObjectsectionKeystring
Returns
GetOccupiedMotionEventForm(JsonObject)
Reads the form on the current block's MotionEvent section, indicating that a motion event has already been authored on this block by an earlier-stage motion syntax. Returns null when no motion event is present on this block. Used by motion syntaxes to enforce mutual exclusion (only one motion event per block).
Reads MotionEvent rather than MotionState because state is modally carried onto every block via ModalCarrySyntax and would always appear "occupied"; only the event section is sparse and meaningfully indicates an authored claim on this block.
public static string GetOccupiedMotionEventForm(this JsonObject json)
Parameters
jsonJsonObject
Returns
GetParsedDouble(JsonObject, string, ISentenceCarrier, NcDiagnosticProgress)
Reads a numeric tag from a JSON object held on a SyntaxPiece (the Parsing tree, a previously-written modal section, or any sub-object thereof), with strict separation between “tag absent” and “tag present but not a number”.
- Tag missing → returns
nullsilently. The caller's existing?? defaultchain handles the "axis not written" / "section absent" case as before. - Tag present and numeric → returns the value.
- Tag present but non-numeric → emits
UnsupportedError(ISentenceCarrier, string, string, object)
(id
VariableExpression--Unevaluated) and returnsnull. Two sources land here:- Parser-stage residue — a Fanuc
"#124", Heidenhain"Q1", Siemens"R5", or bracket expression"[#100+5]"stored as a string by ToFloat(string) / ToInteger(string) when the literal parse failed. Remediation: wire up the variable evaluator. - Codegen residue — a previously-written modal section that somehow ended up with a non-numeric JsonValue. Remediation: file a HiAPIs bug. Severity is intentionally the same; reconfigurable diagnostic routing handles operator-vs-developer triage and a second error id would be cosmetic.
- Parser-stage residue — a Fanuc
section[key]?.GetDouble() at every
call site that consumes a numeric tag held on a SyntaxPiece.
public static double? GetParsedDouble(this JsonObject section, string key, ISentenceCarrier sentenceCarrier, NcDiagnosticProgress diag)
Parameters
sectionJsonObjectkeystringsentenceCarrierISentenceCarrierdiagNcDiagnosticProgress
Returns
GetVec3d(JsonObject, string, Vec3d, ISentenceCarrier, NcDiagnosticProgress)
Reads Vec3d from a sub-object with X/Y/Z keys,
substituting each missing component (or a missing section) with
the matching component of fallback.
When sentenceCarrier is non-null and diag
is supplied, non-numeric X/Y/Z values are reported via
GetParsedDouble(JsonObject, string, ISentenceCarrier, NcDiagnosticProgress); when sentenceCarrier is
null, the diagnostic still fires but without a source-line anchor.
public static Vec3d GetVec3d(JsonObject json, string sectionKey, Vec3d fallback, ISentenceCarrier sentenceCarrier, NcDiagnosticProgress diag)
Parameters
jsonJsonObjectsectionKeystringfallbackVec3dsentenceCarrierISentenceCarrierdiagNcDiagnosticProgress
Returns
GetVec3d(JsonObject, string, ISentenceCarrier, NcDiagnosticProgress)
Read Vec3d from a sub-object with X/Y/Z keys. Returns null if the section or all three keys are missing; individual missing keys are filled with NaN.
When sentenceCarrier is non-null and diag
is supplied, non-numeric X/Y/Z values are reported via
GetParsedDouble(JsonObject, string, ISentenceCarrier, NcDiagnosticProgress) (id VariableExpression--Unevaluated);
when sentenceCarrier is null, the diagnostic still fires
but without a source-line anchor (used by backward-walk / dump-reading
callers that cannot tie the read to the current sentence).
public static Vec3d GetVec3d(JsonObject json, string sectionKey, ISentenceCarrier sentenceCarrier, NcDiagnosticProgress diag)
Parameters
jsonJsonObjectsectionKeystringsentenceCarrierISentenceCarrierdiagNcDiagnosticProgress
Returns
GrabDouble(ref string, string, bool)
Grab double value with decimal point judgement: The text is changed by replacing tag and value to empty string.
If enableIntegerShrink is true and no decimal point, the value should be scale by 0.001.
public static double GrabDouble(ref string text, string tag, bool enableIntegerShrink)
Parameters
textstringtext
tagstringtag
enableIntegerShrinkboolIf true and no decimal point exists, the value will be scaled by 0.001.
Returns
- double
double value
GrabFlag(ref string, string)
Grabs and removes a flag from the NC text.
public static bool GrabFlag(ref string text, string regexTag)
Parameters
Returns
- bool
True if the flag was found and removed; otherwise, false.
GrabFlags(ref string, IEnumerable<string>)
Removes the first occurrence of any flag in tags from text (alternation regex).
public static bool GrabFlags(ref string text, IEnumerable<string> tags)
Parameters
textstringtagsIEnumerable<string>
Returns
- bool
trueif a match was removed.
HasAnyFlag(string, IEnumerable<string>)
True if text contains any flag in flags as whole tokens.
public static bool HasAnyFlag(string text, IEnumerable<string> flags)
Parameters
textstringflagsIEnumerable<string>
Returns
HasAnyFlag(string, string)
True if text contains flag as a whole token (see RegexFlagPrefix).
public static bool HasAnyFlag(string text, string flag)
Parameters
Returns
HasFlagInArray(JsonObject, string)
Checks if a specific flag string exists in the Parsing.Flags JsonArray.
public static bool HasFlagInArray(this JsonObject parsing, string flag)
Parameters
parsingJsonObjectflagstring
Returns
ParseDouble(JsonNode)
Parses a double from a JsonNode that may be a number or a string. Extends GetDouble(JsonNode) with string parsing support (needed for values from ParameterizedFlagSyntax which stores values as strings like “180”). Returns 0 if null or unparseable.
public static double ParseDouble(this JsonNode node)
Parameters
nodeJsonNode
Returns
RemoveFlagFromArray(JsonObject, string)
Removes a specific flag string from the Parsing.Flags JsonArray.
public static void RemoveFlagFromArray(this JsonObject parsing, string flag)
Parameters
parsingJsonObjectflagstring
SetAndTrimUnparsedText(JsonObject, string)
Normalises UnparsedText (trim, drop blank-only lines) and removes the property when empty.
public static void SetAndTrimUnparsedText(this JsonObject root, string unparsedText)
Parameters
rootJsonObjectBlock JSON object.
unparsedTextstringRaw tail text after structured fields were consumed.
SetVec3d(JsonObject, string, Vec3d)
Writes Vec3d to a sub-object under sectionKey,
setting only the X/Y/Z keys. If the section already exists, other
keys (e.g. A/B/C on a shared MachineCoordinate) are
preserved; if it does not exist, a new sub-object is created.
Upsert rather than replace so callers that write XYZ and ABC in separate stages (McXyzSyntax and McAbcSyntax) can cooperate on the same MachineCoordinateState section without clobbering each other.
public static void SetVec3d(JsonObject json, string sectionKey, Vec3d v)
Parameters
jsonJsonObjectsectionKeystringvVec3d