Table of Contents

Class ParameterizedFlagSyntax

Namespace
Hi.NcParsers.ParsingSyntaxs
Assembly
HiMech.dll

Syntax for flags with attached parameters (e.g., G54.1P1, G10L2P1). This is essentially a combination of main flag matching (like NumberedFlagSyntax) plus scoped TagValueSyntax for the parameters after the main flag. Note that the ParameterizedFlagSyntax often should be applied before NumberedFlagSyntax since NumberedFlagSyntax may eat the text that ParameterizedFlagSyntax should handle.

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

Examples

The cases below run the Fanuc-family G54p1Syntax instance (CodePrefixes = [“G54.1”], IntParamPrefixes = [“P”], ParamGatedAliases = {“G54” → “G54.1”}, TerminateWords = [“G”, “M”]). The consumed span is cut out of the text as-is, so the residue keeps the spaces that surrounded the code and its P word — the spaced and the glued spellings differ only there.

Canonical spelling with a space (G54.1 P48) — captured as an integer P under Parsing.G54.1, the rest of the block left for the later syntaxes:

#BeforeBuild:
{ "UnparsedText": "G0 G90 G54.1 P48 X0. Y0." }
#AfterBuild:
{ "UnparsedText": "G0 G90   X0. Y0.", "Parsing": { "G54.1": { "P": 48 } } }
Canonical spelling glued (G54.1P48, glued axis words too): #BeforeBuild:
{ "UnparsedText": "G00 G90 G54.1P48 X0.Y0." }
#AfterBuild:
{ "UnparsedText": "G00 G90  X0.Y0.", "Parsing": { "G54.1": { "P": 48 } } }
The alias spelling with a space — a customer post's block, verbatim — lands under the canonical key exactly like the first case: #BeforeBuild:
{ "UnparsedText": "G0 G90 G54 P48 X0. Y0." }
#AfterBuild:
{ "UnparsedText": "G0 G90   X0. Y0.", "Parsing": { "G54.1": { "P": 48 } } }
The alias spelling glued (G54P48), the same post's other habit, in the same file: #BeforeBuild:
{ "UnparsedText": "G00 G90 G54P48 X0.Y0." }
#AfterBuild:
{ "UnparsedText": "G00 G90  X0.Y0.", "Parsing": { "G54.1": { "P": 48 } } }
A bare G54 (no P word anywhere in its scope) is not this flag: the alias grabs nothing, consumes nothing, and the block is left for NumberedFlagSyntax to read the plain G54 flag — no Parsing object is created: #BeforeBuild:
{ "UnparsedText": "G00 G90 G54 X-24.048 Y-52.446" }
#AfterBuild:
{ "UnparsedText": "G00 G90 G54 X-24.048 Y-52.446" }
A lower-case program: the key is the configured spelling ("G54.1") and the parameter tag is upper-cased, while the untouched residue keeps its case: #BeforeBuild:
{ "UnparsedText": "g0 g90 g54 p4 x0. y0." }
#AfterBuild:
{ "UnparsedText": "g0 g90   x0. y0.", "Parsing": { "G54.1": { "P": 4 } } }

Remarks

Parameters can be stored as typed values via FloatParamPrefixes and IntParamPrefixes (set via property initializer):

Examples:
  • G54.1P1 → {"G54.1": {"P": "1"}} (text)
  • G68.2 X0 I180 → {"G68.2": {"X": 0.0, "I": 180.0}} (float via property initializer)
  • G54.1P#1 → {"G54.1": {"P": "#1"}} (Fanuc variable, kept as string)
  • G54.1PQ1 → {"G54.1": {"P": "Q1"}} (Heidenhain variable)

The stored key is the code's configured spelling (the CodePrefixes entry that matched, or the canonical code an alias maps to), not the text as written: the match is case-insensitive, so a lower-case program (g54.1 p4) still lands under "G54.1" where the logic syntaxes look it up.

A spelling that only means this flag when a parameter follows — Fanuc's G54 Pn for the additional work coordinate system, where a bare G54 is the ordinary work-offset flag — is declared in ParamGatedAliases rather than CodePrefixes. An alias hit that grabs no parameter is left in the text untouched for the later syntaxes; an alias hit with a parameter is stored under its canonical code, indistinguishable from the canonical spelling.

A canonical code that grabs no parameter (a bare G43 whose H is omitted, a bare G41 resuming the modal D) is likewise left in the text and lands in Parsing.Flags through the trailing NumberedFlagSyntax. It is never stored as an empty object: CleanupParsing strips empty objects, and VariableEvaluatorSyntax runs one on every block, so an empty {"G43": {}} would vanish before the logic syntax that owns it ran. Consumers therefore look for their code both as a parameter object and as a flag.

Constructors

ParameterizedFlagSyntax(IEnumerable<string>, IEnumerable<string>, IEnumerable<string>, string, IEnumerable<string>)

Creates a new ParameterizedFlagSyntax instance. Use property initializers for FloatParamPrefixes, IntParamPrefixes and ParamGatedAliases.

public ParameterizedFlagSyntax(IEnumerable<string> categoryPath, IEnumerable<string> codePrefixes, IEnumerable<string> paramPrefixes, string varPrefix, IEnumerable<string> terminateWords = null)

Parameters

categoryPath IEnumerable<string>

JSON path for storing matched codes.

codePrefixes IEnumerable<string>

Full code prefixes to match (e.g., [“G54.1”, “G10”]).

paramPrefixes IEnumerable<string>

Parameter prefixes to extract (e.g., [“P”, “L”]).

varPrefix string

Variable prefix (e.g., “#” for Fanuc, “Q” for Heidenhain).

terminateWords IEnumerable<string>

Words that stop parameter extraction.

ParameterizedFlagSyntax(XElement)

Loads all prefix lists, aliases, variable prefix, and terminator words from XML.

public ParameterizedFlagSyntax(XElement src)

Parameters

src XElement

Root element named XName.

Properties

CategoryPath

Category path for storing matched codes in JSON.

public List<string> CategoryPath { get; set; }

Property Value

List<string>

CodePrefixes

Full code prefixes to match (e.g., [“G54.1”, “G10”]).

public List<string> CodePrefixes { get; set; }

Property Value

List<string>

FloatParamPrefixes

Parameter prefixes stored as double when parseable, string otherwise (for variable references). Set via property initializer for typed G-code parameters.

public List<string> FloatParamPrefixes { get; set; }

Property Value

List<string>

IntParamPrefixes

Parameter prefixes stored as int when parseable, string otherwise (for variable references). Set via property initializer for typed G-code parameters.

public List<string> IntParamPrefixes { get; set; }

Property Value

List<string>

Name

Syntax kind name (typically the concrete type name).

public string Name { get; }

Property Value

string

ParamGatedAliases

Alternative spellings that denote one of the CodePrefixes only when at least one parameter follows: key = the spelling as written in NC text, value = the canonical code the capture is stored under. Matched case-insensitively. A hit that grabs no parameter is left in the text for the later syntaxes — the spelling keeps its own meaning there (Fanuc's G54 Pn is the additional work coordinate system, a bare G54 the ordinary work-offset flag). Serialized as <ParamGatedAliases><Entry Key=“G54”>G54.1</Entry>, omitted when empty.

public Dictionary<string, string> ParamGatedAliases { get; set; }

Property Value

Dictionary<string, string>

ParamPrefixes

Parameter prefixes to extract as text string (e.g., [“P”, “L”, “H”]). Multiple parameters can be attached to one code.

public List<string> ParamPrefixes { get; set; }

Property Value

List<string>

TerminateWords

Words that terminate parameter extraction (e.g., [“G”, “M”, “X”, “Y”, “Z”]). Extraction stops when encountering these prefixes followed by a number.

public List<string> TerminateWords { get; set; }

Property Value

List<string>

VarPrefix

Variable prefix for macro variables (e.g., “#” for Fanuc, “Q” for Heidenhain).

public string VarPrefix { get; set; }

Property Value

string

XName

XML element name for Generators registration.

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