Namespace Hi.NcParsers.ParsingSyntaxs.Fanuc
Classes
- FanucGotoParsingSyntax
Parses Fanuc Custom Macro B GOTO phrases out of the remaining UnparsedText into a
Parsing.FanucGotosub-object. Two forms are recognised:GOTO <n>— unconditional jump.IF [<bool-expr>] GOTO <n>— conditional jump.
IF [...] GOTOis matched as a single phrase, not as anIFsyntax composed with aGOTOsyntax — Fanuc only permits the two fixed forms (the other beingIF [...] THEN <assignment>, out of scope here), so a phrase-level parser is more faithful and avoids parsing-ambiguity rabbit holes.<n>is captured as a raw token (literal like"100", variable like"#1", or bracketed expression like"#[#2+5]"). VariableEvaluatorSyntax substitutes the resolved literal back into the same field downstream; FanucGotoSyntax then parses the final string as an int. Storing as a string at parsing time mirrors how axis tags and canned-cycle params accept#Nreferences and the evaluator rewrites them in place.Pipeline placement: after HeadIndexSyntax (so the leading
N{seq}on a block likeN50 GOTO 100has already been consumed) and after QuoteCommentSyntax (so a parenthesised(GOTO 100)inside a comment never matches). The phrase consumes the entire remaining text on the block — Fanuc allows only the GOTO / IF-GOTO phrase after any preceding head index, no other instructions on the same block.
- FanucIfThenParsingSyntax
Parses the Fanuc Custom Macro B
IF [<bool-expr>] THEN <body>single-block conditional phrase out of UnparsedText into aParsing.FanucIfThensub-object. Sibling to FanucGotoParsingSyntax — Fanuc spec only permits two IF-led control phrases (IF [...] GOTO <n>handled there,IF [...] THEN <stmt>handled here) so each form is matched phrase-level rather than composed from a generic IF combinator.Body shape. The body after
THENis conceptually a single statement that affects the current block only — no jump, no label scan. Almost always a Custom Macro B assignment (#nnn = <expr>); multiple assignments in the same body (#100 = 5. #101 = #100 + 1) are also accepted. The parsing syntax pre-extracts these via GrabTagAssignment(ref string, IEnumerable<string>, string, IEnumerable<string>) intoParsing.FanucIfThen.PendingAssignmentsas{tag: rhs-string}entries — that shape lets VariableEvaluatorSyntax's pass-2 tree walk substitute each RHS to a numeric in place, and lets FanucIfThenSyntax lift the resolved entries intoParsing.Assignmentsonly when the gate condition fires (so unfired bodies leave no trace in the readers).Pipeline placement. This syntax must run before FanucGotoParsingSyntax — the bare IF-GOTO regex over there (
^IF[..]GOTO n$) is anchored, but consuming IF-THEN here first keeps the two phrases textually disjoint and avoids any future regression if either regex is loosened. Also placed before TagAssignmentSyntax so a bareIF [...] THEN #100 = 5.is not first half-eaten as a plain assignment.Raw BodyText is retained verbatim on the parsing section regardless of whether the body parsed as assignments — it carries the round-trip view and lets the evaluation syntax warn (
FanucIfThen--UnsupportedBody) if no PendingAssignments were produced on a truthy condition.
- FanucProgramNumberSyntax
Detects a Fanuc-family program identifier header —
O1234or<O1234>— that follows a TapeBoundary line, and records it under FanucProgramNumber on the block JSON. The wrapping form (bare vs angle-bracketed) is preserved in Wrapper so the block can be emitted back to its original notation.
- FanucWhileDoParsingSyntax
Parses the two Fanuc Custom Macro B WHILE/END phrases out of UnparsedText into a
Parsing.FanucWhileDosub-object:WHILE [<bool-expr>] DO <m>— loop entry, writes{ Term: "WHILE...DO", LoopId, Condition }.END <m>— loop terminator, writes{ Term: "END", LoopId }.
Pipeline placement. This syntax must run before TagAssignmentSyntax in the Parsing bundle — same lesson as FanucIfThenParsingSyntax: although the WHILE / END phrases per Fanuc spec do not coexist with assignments on the same block, the defensive ordering prevents a body fragment from being half-eaten as a stand-alone assignment if a non-spec NC file appears.
LoopIdis captured as an int directly (Fanuc spec restricts themidentifier to small literal integers 1–3 typical, no expression form). TheWHILE's Condition is captured as a string and substituted in place by VariableEvaluatorSyntax's pass-2 tree walk; FanucWhileDoSyntax then reads it via the shared FanucConditionReader.