Table of Contents

Class MCodeExpansionSyntax

Namespace
Hi.NcParsers.LogicSyntaxs
Assembly
HiMech.dll

Expands machine-declared M-codes (IMCodeDeclarationConfig on the controller parameter table) into the canonical ISO flags the regular consumers already understand: tool change → M06, spindle direction → M03/M04/M05, coolant → M07/M08/M09. Must run ahead of SpindleSpeedSyntax, CoolantSyntax, and ToolChangeSyntax — expanding early is what lets one composite OEM code (e.g. M13 = spindle CW + flood coolant) feed several downstream consumers without any of them fighting over who removes the original flag. Same rewrite-into-shared-vocabulary pattern as HeidenhainRadiusCompSyntax (RL/RR/R0 → G41/G42/G40).

Two deliberate boundaries keep the rewrite faithful. Declarations whose sole content is a spindle direction (IsSpindleDirectionOnly) are NOT expanded — SpindleSpeedSyntax resolves them in place via TryResolveDirection(string, out SpindleDirection), which keeps legacy <SpindleMCode> configs bit-identical and avoids the expansion product being re-translated by that same custom-first map (e.g. a mirrored M03↔M04 remap would otherwise flip direction). Expansion codes are inserted at the declared flag's own position, and a code whose raw twin also appears un-declared elsewhere in the block is not emitted — the block's textual order keeps deciding last-wins conflicts exactly as it did before.

Declared-but-unmodeled behavior stays loud: a declaration carrying an UnmodeledNote emits one DeclaredMCode--UnmodeledEffects informational diagnostic per occurrence — a declaration replaces the raw Parsing--Unconsumed warning with an explanation, never with silence. A declaration with no effects and no note consumes its code silently by explicit intent. Undeclared codes are untouched and keep falling through to UnconsumedCheckSyntax.

public class MCodeExpansionSyntax : ISituNcSyntax, INcSyntax, IMakeXmlSource
Inheritance
MCodeExpansionSyntax
Implements
Inherited Members
Extension Methods

Examples

Composite OEM code (test declares M13 → spindle CW + flood coolant) — the declared flag is replaced in place by its canonical ISO equivalents; other words ride along untouched: #BeforeBuild:

{ "Parsing": { "Flags": ["M13"], "S": 2000 } }

#AfterBuild:

{ "Parsing": { "Flags": ["M03", "M08"], "S": 2000 } }

Custom tool-change trigger (test declares M106 → tool change, the Siemens $MC_TOOL_CHANGE_M_CODE shape) — expands to M06 for ToolChangeSyntax to consume: #BeforeBuild:

{ "Parsing": { "Flags": ["M106"], "T": 5 } }

#AfterBuild:

{ "Parsing": { "Flags": ["M06"], "T": 5 } }

Note-only declaration (test declares M23 with an unmodeled note and no effects) — consumed with an explanatory diagnostic, leaving the block clean: #BeforeBuild:

{ "Parsing": { "Flags": ["M23"] } }

#AfterBuild:

{}

Undeclared code — untouched, still falls through to the unconsumed check: #BeforeBuild:

{ "Parsing": { "Flags": ["M55"] } }

#AfterBuild:

{ "Parsing": { "Flags": ["M55"] } }

Spindle-direction-only declaration (test declares M203 → CW, nothing else) — deliberately NOT expanded; SpindleSpeedSyntax resolves it in place, keeping legacy configs bit-identical: #BeforeBuild:

{ "Parsing": { "Flags": ["M203"], "S": 1670 } }

#AfterBuild:

{ "Parsing": { "Flags": ["M203"], "S": 1670 } }

In-place expansion keeps textual last-wins order — the composite M13 expands at its own position, so a later raw M05 still overrides the spindle half downstream: #BeforeBuild:

{ "Parsing": { "Flags": ["M13", "M05"] } }

#AfterBuild:

{ "Parsing": { "Flags": ["M03", "M08", "M05"] } }

A canonical target that is itself declared (test declares M08 → note-only) must not swallow the composite's effect: the raw M08 is consumed for its own declaration while M13's flood half still emits M08: #BeforeBuild:

{ "Parsing": { "Flags": ["M13", "M08"] } }

#AfterBuild:

{ "Parsing": { "Flags": ["M03", "M08"] } }

Constructors

MCodeExpansionSyntax()

Initializes a new instance with default settings.

public MCodeExpansionSyntax()

MCodeExpansionSyntax(XElement)

Initializes a new instance by deserializing from the given XML element.

public MCodeExpansionSyntax(XElement src)

Parameters

src XElement

Source XML element.

Fields

UnknownCoolantDiagId

Diagnostic id for a declaration whose CoolantMode names no known mode.

public const string UnknownCoolantDiagId = "DeclaredMCode--UnknownCoolantMode"

Field Value

string

UnmodeledDiagId

Diagnostic id for the informational message emitted when a consumed declaration carries an UnmodeledNote.

public const string UnmodeledDiagId = "DeclaredMCode--UnmodeledEffects"

Field Value

string

Properties

Name

Syntax kind name (typically the concrete type name).

public string Name { get; }

Property Value

string

XName

XML element name used to register this syntax with XFactory.

public static string XName { get; }

Property Value

string

Methods

Build(LazyLinkedListNode<SyntaxPiece>, List<INcDependency>, NcDiagnosticProgress)

Build syntax arrangement into the syntaxPieceNode in-place.

public void Build(LazyLinkedListNode<SyntaxPiece> syntaxPieceNode, List<INcDependency> ncDependencyList, NcDiagnosticProgress ncDiagnosticProgress)

Parameters

syntaxPieceNode LazyLinkedListNode<SyntaxPiece>
ncDependencyList List<INcDependency>
ncDiagnosticProgress NcDiagnosticProgress

MakeXmlSource(string, string, bool)

Creates an XML representation of the object. This method may also generate additional resources such as related files.

public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)

Parameters

baseDirectory string

The base directory for resolving relative paths

relFile string

The relative file path for the XML source

exhibitionOnly bool

if true, the extended file creation is suppressed.

Returns

XElement

An XML element representing the object's state

Remarks

For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied. The baseDirectory is typically the folder at the nearest configuration file folder. Since the folder can be moving with the configuration file.

Reg(XFactory)

Registers this type's deserializer with the given XFactory (or Default when factory is null). Idempotent.

public static void Reg(XFactory factory = null)

Parameters

factory XFactory