@chestnutlabs/gcode-parser 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ /** Warning codes surfaced to the IR (DD-017 §4.6). */
2
+ export declare const RS274_WARN: {
3
+ readonly uninitializedParam: "rs274-uninitialized-param";
4
+ readonly badExpression: "rs274-bad-expression";
5
+ readonly nonFiniteValue: "rs274-non-finite-value";
6
+ readonly unsupportedSysParam: "rs274-unsupported-sysparam";
7
+ readonly paramLimit: "rs274-param-limit";
8
+ };
9
+ export type WarnFn = (code: string, message: string, srcByte?: number) => void;
10
+ export type PositionProvider = () => {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ };
15
+ /**
16
+ * True when a line's code section (comment already stripped) uses a parametric construct. A cheap
17
+ * character scan — the parser runs this per line so a non-parametric line (every FDM line) takes the
18
+ * untouched fast path and stays byte-identical.
19
+ */
20
+ export declare function lineUsesParametric(codeSection: string): boolean;
21
+ /** Strip RS274NGC `( … )` comments from a code section (they are comments, never expressions). */
22
+ export declare function stripParenComments(s: string): string;
23
+ /** The result of lexing one parametric line. */
24
+ export type ParametricLine = {
25
+ kind: 'empty';
26
+ } | {
27
+ kind: 'plain';
28
+ } | {
29
+ kind: 'assign';
30
+ } | {
31
+ kind: 'cmd';
32
+ codes: string[];
33
+ params: Record<string, number>;
34
+ };
35
+ /**
36
+ * The parameter store + expression evaluator for one program. A scope STACK (DD-017 Phase 3): the base
37
+ * scope is the main program; each subroutine `call` pushes a frame (`#1`–`#30` args + `#<local>` names)
38
+ * and `return`/`endsub` pops it. `#31`+ numbered and `#<_global>` names are shared across frames.
39
+ * Numbered/named params default to `0` on read-before-write (with a one-time disclosure). A read-only
40
+ * allow-list resolves a few system parameters (current position) from live engine state; any other
41
+ * system parameter reads `0` and is disclosed. With no subroutines the base scope reduces to the single
42
+ * flat store of Phases 1–2 (byte-identical).
43
+ */
44
+ export declare class Rs274Context {
45
+ private readonly warn;
46
+ private readonly position;
47
+ private readonly numbered;
48
+ private readonly numberedWritten;
49
+ private readonly globalNamed;
50
+ private readonly scopes;
51
+ private uninitWarned;
52
+ private paramLimitWarned;
53
+ /** True once any parametric construct was executed — drives the `parametricProgram` capability. */
54
+ used: boolean;
55
+ /**
56
+ * True once execution was degraded relative to a clean run: a hit resource limit (iteration cap),
57
+ * an unbalanced/unsupported O-word, or a malformed control expression (DD-017 §4.6). The
58
+ * O-word flow interpreter (Phase 2) sets this; it downgrades `parametricProgram` from `known` to
59
+ * `approximated` (still disclosed via a specific warning — never silently wrong).
60
+ */
61
+ degraded: boolean;
62
+ constructor(warn: WarnFn, position: PositionProvider);
63
+ private warnUninit;
64
+ private get scope();
65
+ /**
66
+ * Push a fresh call-frame scope with `args` bound to `#1`..`#30` (DD-017 Phase 3 `call`). Args beyond
67
+ * 30 are ignored (RS274NGC passes at most 30). Balanced by `popScope` on `return`/`endsub`.
68
+ */
69
+ pushScope(args: readonly number[]): void;
70
+ /** Pop the current call-frame scope (never the base/main scope). */
71
+ popScope(): void;
72
+ private readNumbered;
73
+ private readSystem;
74
+ /** The map a named parameter lives in: underscore-prefixed (`#<_global>`) → global, else scope-local. */
75
+ private namedMap;
76
+ private readNamed;
77
+ private writeNumbered;
78
+ private writeNamed;
79
+ /** `EXISTS[#<name>]` → 1 if the named parameter has been assigned in its scope, else 0. */
80
+ private exists;
81
+ /**
82
+ * Lex one RAW parametric line — either apply a `#… = …` assignment, or resolve every word value into a
83
+ * plain-number `Cmd` for the engine's existing dispatch. Strips `( … )` comments BEFORE the `;` comment
84
+ * (RS274NGC order, so a `;` inside parens doesn't truncate the line). Malformed constructs are dropped +
85
+ * disclosed; the line still parses as far as it can.
86
+ */
87
+ lexLine(rawLine: string, srcByte?: number): ParametricLine;
88
+ /**
89
+ * The `parametricProgram` capability tier (DD-017 §4.6). `unavailable` for a non-parametric file
90
+ * (all FDM); `known` when params/expressions/O-word flow ran deterministically within limits;
91
+ * `approximated` when execution was degraded (a hit iteration cap, an unbalanced/unsupported O-word,
92
+ * or a malformed control expression) — always paired with a specific disclosure, never silently wrong.
93
+ */
94
+ parametricConfidence(): 'known' | 'approximated' | 'unavailable';
95
+ /**
96
+ * Evaluate a standalone expression (an O-word condition `[#1 GT 2]` or a `repeat` count `[5]`) against
97
+ * the shared parameter store, for the Phase 2 flow interpreter. Returns the numeric result, or `null`
98
+ * when the expression is malformed or evaluates to a non-finite value — disclosed either way (the
99
+ * caller treats `null` as false / zero iterations). Accepts a bracketed expression, a bare `#ref`, or a
100
+ * literal; trailing garbage is a malformed expression. No `eval`, depth-guarded like every other path.
101
+ */
102
+ evalExpression(text: string, srcByte?: number): number | null;
103
+ _readParam(kind: 'numbered' | 'named', key: number | string, srcByte?: number): number;
104
+ _writeParam(kind: 'numbered' | 'named', key: number | string, value: number): void;
105
+ _exists(name: string): number;
106
+ }
107
+ //# sourceMappingURL=rs274.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rs274.d.ts","sourceRoot":"","sources":["../src/rs274.ts"],"names":[],"mappings":"AAoBA,sDAAsD;AACtD,eAAO,MAAM,UAAU;;;;;;CAMb,CAAC;AAWX,MAAM,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAC/E,MAAM,MAAM,gBAAgB,GAAG,MAAM;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,kGAAkG;AAClG,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAWpD;AAED,gDAAgD;AAChD,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,OAAO,CA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