nc-gcode-interpreter 0.3.0__tar.gz → 0.3.2__tar.gz

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.
Files changed (149) hide show
  1. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/CHANGELOG.md +28 -0
  2. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/Cargo.lock +1 -1
  3. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/Cargo.toml +1 -1
  4. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/PKG-INFO +1 -1
  5. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/build_backend/nc_build_backend.py +11 -7
  6. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/ggroups/generate_g_commands.py +14 -0
  7. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/nc_gcode_interpreter/__init__.py +11 -9
  8. nc_gcode_interpreter-0.3.2/python/tests/test_build_backend.py +39 -0
  9. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_g_group_enum.py +40 -15
  10. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/grammar.pest +4 -4
  11. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/interpret_rules.rs +19 -9
  12. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/interpreter.rs +1 -1
  13. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/lib.rs +11 -18
  14. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/line_driver.rs +17 -12
  15. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/modal_groups.rs +14 -0
  16. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/start.rs +2 -2
  17. nc_gcode_interpreter-0.3.2/tests/syntax_compatibility.rs +154 -0
  18. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/.github/workflows/benchmark.yml +0 -0
  19. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/.github/workflows/build-and-release.yml +0 -0
  20. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/.gitignore +0 -0
  21. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/CONTRIBUTING.md +0 -0
  22. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/Development.md +0 -0
  23. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/LICENSE +0 -0
  24. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/README.md +0 -0
  25. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/TODO.md +0 -0
  26. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/benches/extensions.rs +0 -0
  27. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/benches/fixtures.rs +0 -0
  28. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/benches/workloads.rs +0 -0
  29. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/build.rs +0 -0
  30. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/docs/resumable-interpretation-design.md +0 -0
  31. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/docs/sinumerik-execution-model.md +0 -0
  32. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/actual_position.csv +0 -0
  33. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/actual_position.mpf +0 -0
  34. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/arc.csv +0 -0
  35. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/arc.mpf +0 -0
  36. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/arrays.csv +0 -0
  37. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/arrays.mpf +0 -0
  38. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/axis_index_assignment.csv +0 -0
  39. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/axis_index_assignment.mpf +0 -0
  40. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/basic_math.csv +0 -0
  41. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/basic_math.mpf +0 -0
  42. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/case.csv +0 -0
  43. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/case.mpf +0 -0
  44. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/case_insensitive_variables.csv +0 -0
  45. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/case_insensitive_variables.mpf +0 -0
  46. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/custom_vars.csv +0 -0
  47. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/custom_vars.mpf +0 -0
  48. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/def_string.csv +0 -0
  49. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/def_string.mpf +0 -0
  50. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/defaults.csv +0 -0
  51. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/defaults.def +0 -0
  52. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/defaults.mpf +0 -0
  53. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/defaults_start.json +0 -0
  54. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/edge_cases.csv +0 -0
  55. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/edge_cases.mpf +0 -0
  56. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/flattening/flatten_demo.mpf +0 -0
  57. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/flattening/flatten_demo_flattened.csv +0 -0
  58. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/flattening/flatten_demo_raw.csv +0 -0
  59. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/for_loop.csv +0 -0
  60. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/for_loop.mpf +0 -0
  61. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/function_calls.csv +0 -0
  62. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/function_calls.mpf +0 -0
  63. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/goto.csv +0 -0
  64. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/goto.mpf +0 -0
  65. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/if_statement.csv +0 -0
  66. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/if_statement.mpf +0 -0
  67. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/increment.csv +0 -0
  68. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/increment.mpf +0 -0
  69. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/logic_operators.csv +0 -0
  70. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/logic_operators.mpf +0 -0
  71. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/loop.csv +0 -0
  72. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/loop.mpf +0 -0
  73. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/multiple_m_codes.csv +0 -0
  74. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/multiple_m_codes.mpf +0 -0
  75. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/precedence.csv +0 -0
  76. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/precedence.mpf +0 -0
  77. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/r_param.csv +0 -0
  78. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/r_param.mpf +0 -0
  79. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/repeat.csv +0 -0
  80. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/repeat.mpf +0 -0
  81. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/rot.csv +0 -0
  82. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/rot.mpf +0 -0
  83. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/simple.csv +0 -0
  84. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/simple.mpf +0 -0
  85. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/spline.csv +0 -0
  86. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/spline.mpf +0 -0
  87. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/tool.csv +0 -0
  88. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/tool.mpf +0 -0
  89. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans.csv +0 -0
  90. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans.mpf +0 -0
  91. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans2.csv +0 -0
  92. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans2.mpf +0 -0
  93. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans_ic.csv +0 -0
  94. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans_ic.mpf +0 -0
  95. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans_reset.csv +0 -0
  96. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trans_reset.mpf +0 -0
  97. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trig.csv +0 -0
  98. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/trig.mpf +0 -0
  99. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/variables.csv +0 -0
  100. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/examples/variables.mpf +0 -0
  101. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/pyproject.toml +0 -0
  102. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/example/minimal.py +0 -0
  103. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/example/streaming.py +0 -0
  104. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/nc_gcode_interpreter/_internal.pyi +0 -0
  105. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/nc_gcode_interpreter/cli.py +0 -0
  106. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/nc_gcode_interpreter/ggroups.json +0 -0
  107. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/nc_gcode_interpreter/py.typed +0 -0
  108. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/nc_gcode_interpreter/viz.py +0 -0
  109. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/nc_source.py +0 -0
  110. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_arithmetic_functions.py +0 -0
  111. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_batch_variables.py +0 -0
  112. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_batches.py +0 -0
  113. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_compare_benchmarks.py +0 -0
  114. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_diagnostics.py +0 -0
  115. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_expected_output.py +0 -0
  116. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_feed_check.py +0 -0
  117. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_feed_group.py +0 -0
  118. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_field_defects.py +0 -0
  119. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_flags.py +0 -0
  120. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_flatten.py +0 -0
  121. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_frames.py +0 -0
  122. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_g_groups.py +0 -0
  123. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_g_vocabulary.py +0 -0
  124. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_jumps.py +0 -0
  125. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_real_comparisons.py +0 -0
  126. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_stage1.py +0 -0
  127. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_start_inputs.py +0 -0
  128. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_streaming.py +0 -0
  129. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_string_operations.py +0 -0
  130. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_structured_errors.py +0 -0
  131. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_subprograms.py +0 -0
  132. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/python/tests/test_unsupported.py +0 -0
  133. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/rustfmt.toml +0 -0
  134. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/scripts/benchmark.py +0 -0
  135. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/scripts/compare_benchmarks.py +0 -0
  136. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/errors.rs +0 -0
  137. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/flatten.rs +0 -0
  138. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/frame.rs +0 -0
  139. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/line_driver/experiments.rs +0 -0
  140. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/main.rs +0 -0
  141. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/output.rs +0 -0
  142. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/state.rs +0 -0
  143. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/structure_scan.rs +0 -0
  144. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/subprogram.rs +0 -0
  145. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/types.rs +0 -0
  146. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/src/vm.rs +0 -0
  147. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/tests/cli.rs +0 -0
  148. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/tests/performance_contract.rs +0 -0
  149. {nc_gcode_interpreter-0.3.0 → nc_gcode_interpreter-0.3.2}/uv.lock +0 -0
@@ -4,6 +4,34 @@ Notable changes to **nc-gcode-interpreter**. The format loosely follows
4
4
  [Keep a Changelog](https://keepachangelog.com/); versions are git tags,
5
5
  released to PyPI.
6
6
 
7
+ ## [v0.3.2] - 2026-11-13
8
+
9
+ ### Fixed
10
+
11
+ - A local build on Windows no longer fails with "metadata version does not
12
+ match". The build backend restored `Cargo.toml` and `Cargo.lock` with CRLF
13
+ line endings, so the tree looked modified to the next build phase, which
14
+ then stamped a different `.dirty` version. Both files now come back byte
15
+ for byte, and a CRLF `Cargo.toml` is stamped too.
16
+ - Accept Siemens numeric literals with leading-dot decimals (`X.5`,
17
+ `Z-.5`, `X=IC(.375)`) and explicit positive signs (`X+0.5`, `R1=+2`).
18
+ Zero-padded G and M codes (`G01`, `G017`, `M03`, `M030`) now use their
19
+ canonical spelling for interpretation and output, including frame and curve
20
+ handling. `start.g_groups` accepts padded codes too.
21
+
22
+ ## [v0.3.1] - 2026-11-11
23
+
24
+ ### Changed
25
+
26
+ - The G-group columns reach Python as one-byte codes and become `pl.Enum`
27
+ by a gather from each group's categories. Before, Rust sent an Arrow
28
+ dictionary tagged with an undocumented polars metadata key, and polars
29
+ looked up every row's string on import. On polars 1.40 a 7M-row program
30
+ with eleven G-group columns takes 15% less CPU (3.92 s to 3.32 s); on
31
+ polars 2.1 the time is unchanged. The output is identical, and the
32
+ interpreter no longer depends on that key. Polars 2 does not cast
33
+ integers to an Enum, so the gather works on both.
34
+
7
35
  ## [v0.3.0] - 2026-11-11
8
36
 
9
37
  This release changes the API and the output. To upgrade:
@@ -506,7 +506,7 @@ checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
506
506
 
507
507
  [[package]]
508
508
  name = "nc-gcode-interpreter"
509
- version = "0.3.0"
509
+ version = "0.3.2"
510
510
  dependencies = [
511
511
  "arrow-array",
512
512
  "arrow-data",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "nc-gcode-interpreter"
3
- version = "0.3.0"
3
+ version = "0.3.2"
4
4
  edition = "2021"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nc-gcode-interpreter
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -39,7 +39,8 @@ from maturin import (
39
39
  )
40
40
 
41
41
  PLACEHOLDER = "0.0.0-dev"
42
- _VERSION_LINE = re.compile(r'^version = ".*"$', re.MULTILINE)
42
+ # No trailing `$`: under MULTILINE it does not match before the `\r` of a CRLF file.
43
+ _VERSION_LINE = re.compile(rb'^version = "[^"\r\n]*"', re.MULTILINE)
43
44
  # v0.2.6-3-g1234abc[-dirty]
44
45
  _DESCRIBE = re.compile(r"^v(?P<tag>.+)-(?P<distance>\d+)-g(?P<sha>[0-9a-f]+)(?P<dirty>-dirty)?$")
45
46
 
@@ -71,8 +72,10 @@ def _versioned_cargo_toml():
71
72
  root = Path(__file__).resolve().parent.parent
72
73
  cargo_toml = root / "Cargo.toml"
73
74
  cargo_lock = root / "Cargo.lock"
74
- original = cargo_toml.read_text()
75
- if f'version = "{PLACEHOLDER}"' not in original:
75
+ # Bytes throughout: text mode writes CRLF on Windows, which dirties the tree on restore
76
+ # and makes the next build phase stamp a different (.dirty) version.
77
+ original = cargo_toml.read_bytes()
78
+ if f'version = "{PLACEHOLDER}"'.encode() not in original:
76
79
  # CI already stamped the release version; nothing to do.
77
80
  yield
78
81
  return
@@ -80,15 +83,16 @@ def _versioned_cargo_toml():
80
83
  if version is None:
81
84
  yield
82
85
  return
83
- lock_original = cargo_lock.read_text() if cargo_lock.exists() else None
84
- cargo_toml.write_text(_VERSION_LINE.sub(f'version = "{version}"', original, count=1))
86
+ lock_original = cargo_lock.read_bytes() if cargo_lock.exists() else None
87
+ stamp = f'version = "{version}"'.encode()
88
+ cargo_toml.write_bytes(_VERSION_LINE.sub(lambda _: stamp, original, count=1))
85
89
  try:
86
90
  yield
87
91
  finally:
88
- cargo_toml.write_text(original)
92
+ cargo_toml.write_bytes(original)
89
93
  # cargo rewrites the lock to match the patched version during the build.
90
94
  if lock_original is not None:
91
- cargo_lock.write_text(lock_original)
95
+ cargo_lock.write_bytes(lock_original)
92
96
 
93
97
 
94
98
  def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
@@ -22,6 +22,20 @@ lines = [
22
22
  "// Auto-generated by ggroups/generate_g_commands.py from",
23
23
  "// python/nc_gcode_interpreter/ggroups.json - do not edit by hand.",
24
24
  "",
25
+ "/// Canonical spelling of a G word: uppercase, and numbered codes lose",
26
+ "/// their leading zeros (g001 -> G1, manual 3.2.2.1). Keywords only change case.",
27
+ "pub fn normalize_g_command(word: &str) -> String {",
28
+ " let mut code = word.to_ascii_uppercase();",
29
+ " if let Some(digits) = code.strip_prefix('G') {",
30
+ " if !digits.is_empty() && digits.bytes().all(|b| b.is_ascii_digit()) {",
31
+ " let zeros = digits.bytes().take_while(|&b| b == b'0').count();",
32
+ " let remove = zeros.min(digits.len() - 1);",
33
+ " code.drain(1..1 + remove);",
34
+ " }",
35
+ " }",
36
+ " code",
37
+ "}",
38
+ "",
25
39
  "/// Classify an (uppercased) G-command word: the G-group column it",
26
40
  "/// belongs to, and whether that group is modal. `None` means the word",
27
41
  "/// is not a known G command.",
@@ -346,20 +346,22 @@ G_GROUP_DTYPES: dict[str, pl.Enum] = {
346
346
  }
347
347
 
348
348
 
349
+ # Each group's categories as an Enum series; gathering by code builds the column.
350
+ _G_GROUP_CATEGORIES: dict[str, pl.Series] = {
351
+ name: pl.Series(name, dtype.categories, dtype=dtype) for name, dtype in G_GROUP_DTYPES.items()
352
+ }
353
+
354
+
349
355
  def _batch_frame(batch: Any) -> pl.DataFrame:
350
356
  """Wrap one Arrow batch from Rust, with every G-group column as its Enum.
351
357
 
352
- Rust tags the G-group dictionaries so polars imports them as Enum
353
- directly. The cast is a safety net should polars stop reading that tag;
354
- ``test_g_group_columns_arrive_as_enum_without_a_cast`` turns red if it does.
358
+ Rust sends each G-group column as UInt8 indices into the group's commands
359
+ in manual order. Gathering from the Enum's categories turns them into the
360
+ Enum, since polars 2 no longer casts integers to an Enum.
355
361
  """
356
362
  frame = pl.DataFrame(batch)
357
- casts = [
358
- pl.col(name).cast(G_GROUP_DTYPES[name])
359
- for name, dtype in frame.schema.items()
360
- if name in G_GROUP_DTYPES and dtype != G_GROUP_DTYPES[name]
361
- ]
362
- return frame.with_columns(casts) if casts else frame
363
+ columns = [_G_GROUP_CATEGORIES[name].gather(frame[name]) for name in frame.columns if name in _G_GROUP_CATEGORIES]
364
+ return frame.with_columns(columns) if columns else frame
363
365
 
364
366
 
365
367
  def sanitize_dataframe(
@@ -0,0 +1,39 @@
1
+ """The in-tree build backend stamps Cargo.toml and restores both Cargo files byte for byte."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import importlib.util
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ import pytest
10
+
11
+ BACKEND = Path(__file__).resolve().parents[2] / "build_backend" / "nc_build_backend.py"
12
+
13
+
14
+ @pytest.fixture()
15
+ def backend(tmp_path, monkeypatch):
16
+ pytest.importorskip("maturin")
17
+ spec = importlib.util.spec_from_file_location("_test_nc_build_backend", BACKEND)
18
+ module = importlib.util.module_from_spec(spec)
19
+ monkeypatch.setitem(sys.modules, spec.name, module)
20
+ spec.loader.exec_module(module)
21
+ monkeypatch.setattr(module, "_git_version", lambda root: "0.4.0-dev.1+gabc1234")
22
+ # The backend resolves its root from __file__; point it at the scratch tree.
23
+ (tmp_path / "build_backend").mkdir()
24
+ monkeypatch.setattr(module, "__file__", str(tmp_path / "build_backend" / "x.py"))
25
+ return module
26
+
27
+
28
+ @pytest.mark.parametrize("eol", [b"\n", b"\r\n"], ids=["lf", "crlf"])
29
+ def test_stamp_and_byte_exact_restore(backend, tmp_path, eol):
30
+ toml = eol.join([b"[package]", b'name = "x"', b'version = "0.0.0-dev"', b""])
31
+ lock = eol.join([b'name = "x"', b'version = "0.0.0-dev"', b""])
32
+ # Bytes, not text: write_text would emit CRLF on Windows and mask the bug under test.
33
+ (tmp_path / "Cargo.toml").write_bytes(toml)
34
+ (tmp_path / "Cargo.lock").write_bytes(lock)
35
+ with backend._versioned_cargo_toml():
36
+ assert b'version = "0.4.0-dev.1+gabc1234"' + eol in (tmp_path / "Cargo.toml").read_bytes()
37
+ (tmp_path / "Cargo.lock").write_bytes(b"rewritten by cargo")
38
+ assert (tmp_path / "Cargo.toml").read_bytes() == toml
39
+ assert (tmp_path / "Cargo.lock").read_bytes() == lock
@@ -33,19 +33,20 @@ def test_dtypes_cover_every_group_in_manual_order():
33
33
  assert G_GROUP_DTYPES["gg01_motion"].categories.to_list()[:4] == ["G0", "G1", "G2", "G3"]
34
34
 
35
35
 
36
- def test_g_group_columns_arrive_as_enum_without_a_cast():
37
- # Bypasses _batch_frame: red here means polars no longer reads the Enum tag Rust writes.
36
+ def test_g_group_columns_arrive_as_manual_order_codes():
37
+ # Bypasses _batch_frame: Rust hands over UInt8 indices into each group's manual-order list.
38
38
  from nc_gcode_interpreter import _internal
39
39
 
40
- batches = _internal.nc_to_batches(PROGRAM, batch_size=3)
41
- seen = set()
42
- for batch in batches:
43
- frame = pl.DataFrame(batch)
44
- for name, dtype in frame.schema.items():
45
- if name in G_GROUP_DTYPES:
46
- assert dtype == G_GROUP_DTYPES[name], f"{name} arrived as {dtype}"
47
- seen.add(name)
48
- assert {"gg01_motion", "gg02_wait", "gg06_plane_select"} <= seen
40
+ frames = [pl.DataFrame(batch) for batch in _internal.nc_to_batches(PROGRAM, batch_size=3)]
41
+ raw = pl.concat(frames, how="diagonal")
42
+ expected, _ = nc_to_dataframe(PROGRAM)
43
+ seen = [name for name in raw.columns if name in G_GROUP_DTYPES]
44
+ assert {"gg01_motion", "gg02_wait", "gg06_plane_select"} <= set(seen)
45
+ for name in seen:
46
+ assert raw.schema[name] == pl.UInt8, name
47
+ categories = G_GROUP_DTYPES[name].categories.to_list()
48
+ decoded = [None if code is None else categories[code] for code in raw[name].to_list()]
49
+ assert decoded == expected[name].to_list(), name
49
50
 
50
51
 
51
52
  def test_batches_share_one_enum_dtype_and_concat_vertically():
@@ -92,14 +93,38 @@ def test_rows_keep_plain_strings():
92
93
 
93
94
 
94
95
  def test_unknown_g_command_is_a_loud_error():
95
- with pytest.raises(NcError, match="G01") as info:
96
- nc_to_dataframe("G01 X1\n")
96
+ with pytest.raises(NcError, match="G09999") as info:
97
+ nc_to_dataframe("G09999 X1\n")
97
98
  assert info.value.kind == "unknown_g_command"
98
- with pytest.raises(NcError, match="G01") as info:
99
- nc_to_dataframe("X1\n", start={"g_groups": {"gg01_motion": "G01"}})
99
+
100
+
101
+ def test_start_g_groups_accept_padded_codes_as_canonical_values():
102
+ start = {"g_groups": {"gg01_motion": "g01", "gg06_plane_select": "G018"}, "feed": 100.0}
103
+ df, _ = nc_to_dataframe("X1\n", start=start)
104
+ _assert_g_group_dtypes(df)
105
+ assert df["gg01_motion"].to_list() == ["G1"]
106
+ assert df["gg06_plane_select"].to_list() == ["G18"]
107
+ with pytest.raises(NcError, match="G9999") as info:
108
+ nc_to_dataframe("X1\n", start={"g_groups": {"gg01_motion": "G09999"}})
100
109
  assert info.value.kind == "invalid_input"
101
110
 
102
111
 
112
+ @pytest.mark.parametrize("stage1,min_bytes", [("0", "0"), ("1", "0"), ("1", str(2**63))])
113
+ def test_padded_g_codes_reach_python_as_canonical_values(monkeypatch, stage1, min_bytes):
114
+ monkeypatch.setenv("NC_STAGE1", stage1)
115
+ monkeypatch.setenv("NC_STREAM_MIN_BYTES", min_bytes)
116
+ program = "G00 X.5 M03\ng001 F+100 X+.75 m005 M0\n"
117
+ df, _ = nc_to_dataframe(program)
118
+ frames = list(nc_to_batches(program, batch_size=1))
119
+ for frame in [df, *frames]:
120
+ _assert_g_group_dtypes(frame)
121
+ assert df["gg01_motion"].to_list() == ["G0", "G1"]
122
+ assert df["X"].to_list() == [0.5, 0.75]
123
+ assert_frame_equal(pl.concat(frames, how="diagonal").select(df.columns), df)
124
+ assert df["M"].to_list() == [["M3"], ["M5", "M0"]]
125
+ assert [row["gg01_motion"] for _, row in nc_to_rows(program)] == ["G0", "G1"]
126
+
127
+
103
128
  @pytest.mark.parametrize("batch_size", [1, 2, 500_000])
104
129
  def test_g_groups_seeded_from_start_have_the_enum_dtype_of_later_rows(batch_size):
105
130
  start = {"g_groups": {"gg01_motion": "G1", "gg06_plane_select": "G18"}, "feed": 100.0}
@@ -225,9 +225,10 @@ assignment_multi = { variable_array ~ "=" ~ (value_array | value_repeating) }
225
225
  value_array = { "SET" ~ "(" ~ (expression | value_none) ~ ("," ~ (expression | value_none))* ~ ")" }
226
226
  value_repeating = { "REP" ~ "(" ~ expression ~ ("," ~ expression)? ~ ")" }
227
227
  value_none = { "" }
228
- // Atomic: the interpreter only reads the full lexeme (as_str), so the inner
229
- // float/integer pairs would be two dead tokens per coordinate on the queue.
230
- value = @{ float | integer }
228
+ // Atomic: the interpreter only reads the full lexeme (as_str). Siemens
229
+ // accepts X.5, Z-.5 and an explicit positive sign; at least one digit is
230
+ // required, on either side of the decimal point. Keep block numbers separate.
231
+ value = @{ ("+" | "-")? ~ (ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT*)? | "." ~ ASCII_DIGIT+) ~ !ASCII_ALPHA }
231
232
  op = _{
232
233
  op_add | op_sub | op_mul | op_div | op_int_div | op_mod
233
234
  | op_b_and | op_b_xor | op_b_or
@@ -259,7 +260,6 @@ neg = { "-" }
259
260
  not_op = @{ ^"NOT" ~ !(ASCII_ALPHANUMERIC | "_") }
260
261
  // A quoted string is an operand only of == and <> (manual 4.1.3.2).
261
262
  primary = { arith_fun | value | string_value | variable_array | variable | "(" ~ expression ~ ")" }
262
- float = @{ "-"? ~ ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT* ~ !ASCII_ALPHA } // Ensure floats are not followed by letters
263
263
  integer = @{ "-"? ~ ASCII_DIGIT+ ~ !ASCII_ALPHA } // Ensure integers are not followed by letters
264
264
  // Any call-shaped name is accepted here; the interpreter dispatches on the
265
265
  // (case-insensitive) name and rejects unknown functions with line context.
@@ -821,16 +821,15 @@ fn evaluate_unary(pairs: &[Pair<Rule>], pos: &mut usize, state: &mut State) -> R
821
821
  }
822
822
  /// Classify a lexically G-shaped command (`G<digits>` or `GFRAME[<n>]`)
823
823
  /// against the vocabulary table: the column key is the G-group name, the
824
- /// value the command as written. An unknown G number is a hard error, like
824
+ /// value the canonical command. An unknown G number is a hard error, like
825
825
  /// alarm 12470 "undefined G function" on a real control.
826
826
  fn interpret_g_command(g_command: Pair<Rule>, state: &mut State) -> Result<(&'static str, String), ParsingError> {
827
827
  let command_str = g_command.as_str().trim().to_string();
828
- // Store uppercase: the language is case-insensitive (g2 IS G2), and
829
- // source case leaking into the output breaks downstream comparisons -
830
- // worst case the flattener seeing 'g18' would arc in the wrong plane.
831
- match crate::modal_groups::classify_g_command(&command_str.to_uppercase()) {
828
+ // Normalize both case and padding: downstream frame/curve handling
829
+ // compares canonical codes, so g02 and G018 must become G2 and G18.
830
+ let code = crate::modal_groups::normalize_g_command(&command_str);
831
+ match crate::modal_groups::classify_g_command(&code) {
832
832
  Some((group, modal)) => {
833
- let code = command_str.to_uppercase();
834
833
  // The frame model needs the active plane for RPL and the arc check.
835
834
  if group == "gg06_plane_select" {
836
835
  state.set_plane(&code);
@@ -3497,6 +3496,19 @@ fn interpret_control(element: Pair<Rule>, output: &mut Output, state: &mut State
3497
3496
  }
3498
3497
  Ok(BlockFlow::Continue)
3499
3498
  }
3499
+ /// Canonical spelling of an M word: uppercase (m30 IS M30) and without
3500
+ /// leading zeros (M03 IS M3, manual 3.2.2.1), so output values compare equal.
3501
+ pub(crate) fn normalize_m_command(word: &str) -> String {
3502
+ let mut code = word.to_ascii_uppercase();
3503
+ if let Some(digits) = code.strip_prefix('M') {
3504
+ if !digits.is_empty() && digits.bytes().all(|b| b.is_ascii_digit()) {
3505
+ let zeros = digits.bytes().take_while(|&b| b == b'0').count();
3506
+ code.drain(1..1 + zeros.min(digits.len() - 1));
3507
+ }
3508
+ }
3509
+ code
3510
+ }
3511
+
3500
3512
  pub(crate) fn insert_m_key(
3501
3513
  last: &mut crate::output::CellMap,
3502
3514
  value: &str,
@@ -3504,9 +3516,7 @@ pub(crate) fn insert_m_key(
3504
3516
  preview: String,
3505
3517
  ) -> Result<(), ParsingError> {
3506
3518
  let m_key = "M";
3507
- // Uppercase: the language is case-insensitive (m30 IS M30); source case
3508
- // must not leak into the output values.
3509
- let value = value.to_uppercase();
3519
+ let value = normalize_m_command(value);
3510
3520
  for _i in 1..=5 {
3511
3521
  if let Some(existing_value) = last.get_mut(m_key) {
3512
3522
  // If the key already exists and is a list, append the new value
@@ -550,7 +550,7 @@ fn describe_rule(rule: Rule) -> &'static str {
550
550
  Rule::assignment_multi => "an array assignment (SET/REP)",
551
551
  Rule::axis_increment => "an incremental value IC(...)",
552
552
  Rule::expression | Rule::primary => "an expression",
553
- Rule::value | Rule::float | Rule::integer => "a number",
553
+ Rule::value | Rule::integer => "a number",
554
554
  Rule::identifier | Rule::variable => "a name",
555
555
  Rule::variable_array => "an array element",
556
556
  Rule::indices => "array indices",
@@ -319,7 +319,7 @@ mod python_bindings {
319
319
  let mut arrays: Vec<ArrayRef> = Vec::with_capacity(table.columns.len());
320
320
  for (name, column) in table.columns {
321
321
  if let Some(categories) = crate::modal_groups::g_group_values(&name) {
322
- let (field, array) = g_group_enum_array(&name, categories, column)?;
322
+ let (field, array) = g_group_code_array(&name, categories, column)?;
323
323
  fields.push(field);
324
324
  arrays.push(array);
325
325
  continue;
@@ -376,30 +376,23 @@ mod python_bindings {
376
376
  .map_err(|e| PyErr::new::<PyValueError, _>(format!("failed to build RecordBatch: {}", e)))
377
377
  }
378
378
 
379
- /// One G-group column as an Arrow dictionary whose values are the group's
380
- /// full command list in manual order and whose keys index that list, so
381
- /// every batch carries the same categories. The `_PL_ENUM_VALUES2` field
382
- /// metadata is what polars (>= 1.32) reads to import it as `pl.Enum`. A
383
- /// value outside the list is an error, never a null.
384
- fn g_group_enum_array(
379
+ /// One G-group column as UInt8 indices into the group's command list in
380
+ /// manual order, which the Python wrapper casts to that group's `pl.Enum`.
381
+ /// Plain codes, because polars imports an Arrow dictionary by looking up
382
+ /// every row's string, about 15 times slower than the integer cast. A value
383
+ /// outside the list is an error, never a null.
384
+ fn g_group_code_array(
385
385
  name: &str,
386
386
  categories: &'static [&'static str],
387
387
  column: Column,
388
388
  ) -> PyResult<(arrow_schema::Field, arrow_array::ArrayRef)> {
389
- use arrow_array::types::UInt8Type;
390
- use arrow_array::{Array, DictionaryArray, StringArray, UInt8Array};
391
- use arrow_schema::Field;
389
+ use arrow_array::UInt8Array;
390
+ use arrow_schema::{DataType, Field};
392
391
 
393
- let keys: UInt8Array = crate::output::g_group_codes(name, categories, &column)
392
+ let codes: UInt8Array = crate::output::g_group_codes(name, categories, &column)
394
393
  .map_err(PyErr::new::<PyValueError, _>)?
395
394
  .into();
396
- let values: StringArray = categories.iter().map(|c| Some(*c)).collect();
397
- let array = DictionaryArray::<UInt8Type>::try_new(keys, Arc::new(values))
398
- .map_err(|e| PyErr::new::<PyValueError, _>(format!("G-group column '{}': {}", name, e)))?;
399
- let encoded: String = categories.iter().map(|c| format!("{};{}", c.len(), c)).collect();
400
- let metadata = HashMap::from([("_PL_ENUM_VALUES2".to_string(), encoded)]);
401
- let field = Field::new(name, array.data_type().clone(), true).with_metadata(metadata);
402
- Ok((field, Arc::new(array)))
395
+ Ok((Field::new(name, DataType::UInt8, true), Arc::new(codes)))
403
396
  }
404
397
 
405
398
  /// [`table_to_record_batch`] as an [`ArrowBatch`] the Python side receives
@@ -26,7 +26,7 @@ use crate::interpret_rules::{
26
26
  canonical_block_number, insert_m_key, interpret_block, is_end_of_program_m_code, resolve_jump, scan_jump_targets,
27
27
  BlockFlow,
28
28
  };
29
- use crate::modal_groups::classify_g_command;
29
+ use crate::modal_groups::{classify_g_command, normalize_g_command};
30
30
  use crate::state::{ColKind, State};
31
31
  use crate::types::{NCParser, Pair, Rule, Value};
32
32
  use pest::Parser;
@@ -775,8 +775,8 @@ fn execute_decoded(
775
775
  last.insert("non_returning_function_call", Value::Str(value.to_string()));
776
776
  }
777
777
  Word::GCommand(group, as_written) => {
778
- // Uppercase like the grammar path: g2 IS G2.
779
- let code = as_written.to_uppercase();
778
+ // Canonical spelling like the grammar path: g02 IS G2.
779
+ let code = normalize_g_command(as_written);
780
780
  // The plane feeds the frame model, exactly as interpret_g_command does.
781
781
  if *group == "gg06_plane_select" {
782
782
  state.set_plane(&code);
@@ -867,26 +867,31 @@ enum DecodeResult<'a> {
867
867
  }
868
868
 
869
869
  /// Parse a single numeric literal (`value` in the grammar: optional sign,
870
- /// digits, optional fraction) at `*i`, advancing past it. Rejects exponents,
871
- /// a second dot, or letter/underscore tails - those need the real grammar.
870
+ /// digits with an optional decimal point, including .5) at `*i`, advancing
871
+ /// past it. Rejects exponents, a second dot, or letter/underscore tails;
872
+ /// those need the real grammar.
872
873
  fn parse_number(line: &str, i: &mut usize) -> Option<f64> {
873
874
  let bytes = line.as_bytes();
874
875
  let start = *i;
875
- if *i < bytes.len() && bytes[*i] == b'-' {
876
+ if *i < bytes.len() && matches!(bytes[*i], b'+' | b'-') {
876
877
  *i += 1;
877
878
  }
878
879
  let digits_start = *i;
879
880
  while *i < bytes.len() && bytes[*i].is_ascii_digit() {
880
881
  *i += 1;
881
882
  }
882
- if *i == digits_start {
883
- return None;
884
- }
883
+ let integer_digits = *i - digits_start;
884
+ let mut fraction_digits = 0;
885
885
  if *i < bytes.len() && bytes[*i] == b'.' {
886
886
  *i += 1;
887
+ let fraction_start = *i;
887
888
  while *i < bytes.len() && bytes[*i].is_ascii_digit() {
888
889
  *i += 1;
889
890
  }
891
+ fraction_digits = *i - fraction_start;
892
+ }
893
+ if integer_digits + fraction_digits == 0 {
894
+ return None;
890
895
  }
891
896
  // Exponents, a second dot, or letter tails need the real grammar.
892
897
  if *i < bytes.len() && (bytes[*i].is_ascii_alphabetic() || bytes[*i] == b'_' || bytes[*i] == b'.') {
@@ -1172,7 +1177,7 @@ fn decode_line_inner<'a>(
1172
1177
  }
1173
1178
  let word_start = i;
1174
1179
  i += 1;
1175
- let bare_number_follows = i < n_len && (bytes[i].is_ascii_digit() || bytes[i] == b'-' || bytes[i] == b'.');
1180
+ let bare_number_follows = i < n_len && (bytes[i].is_ascii_digit() || matches!(bytes[i], b'+' | b'-' | b'.'));
1176
1181
  // The grammar's bare-word forms are all case-insensitive: M/G
1177
1182
  // addresses and variable_single_char (axis letters) alike.
1178
1183
  if bare_number_follows && bytes[word_start].is_ascii_alphabetic() {
@@ -1192,7 +1197,7 @@ fn decode_line_inner<'a>(
1192
1197
  if letter == b'M' {
1193
1198
  arena.push(Word::MCode(code));
1194
1199
  } else {
1195
- match classify_g_command(&code.to_uppercase()) {
1200
+ match classify_g_command(&normalize_g_command(code)) {
1196
1201
  Some((group, _modal)) => arena.push(Word::GCommand(group, code)),
1197
1202
  // Unknown G code: let the full path produce its error.
1198
1203
  None => return DecodeResult::NeedsGrammar,
@@ -1912,7 +1917,7 @@ M30
1912
1917
  "N10", "N", "10", "X5", "X", "Y1", "=", "5", "-3", "2.5", ".5", "AND", "OR", "XOR", "B_AND", "B_OR",
1913
1918
  "B_XOR", "DIV", "MOD", "NOT", "TRANS", "ROT", "SCALE", "MIRROR", "RPL", "DEF", "IC(2)", "(3*R1)", "(", ")",
1914
1919
  "*", "+", "/", "LBL:", ";c", "G1", "M3", "R1", "_V", "SIN(30)", "E", "F100", "IF", "GOTOF", "X1=", "T",
1915
- "\"s\"", "[", ",", "<", "x5", "n10", "SET", "$P",
1920
+ "\"s\"", "[", ",", "<", "x5", "n10", "SET", "$P", "G01", "g003", "M03", "+.5", "1.", "-.",
1916
1921
  ];
1917
1922
  let mut seed: u64 = 0x9E37_79B9_7F4A_7C15;
1918
1923
  let mut next = |bound: usize| {
@@ -1,6 +1,20 @@
1
1
  // Auto-generated by ggroups/generate_g_commands.py from
2
2
  // python/nc_gcode_interpreter/ggroups.json - do not edit by hand.
3
3
 
4
+ /// Canonical spelling of a G word: uppercase, and numbered codes lose
5
+ /// their leading zeros (g001 -> G1, manual 3.2.2.1). Keywords only change case.
6
+ pub fn normalize_g_command(word: &str) -> String {
7
+ let mut code = word.to_ascii_uppercase();
8
+ if let Some(digits) = code.strip_prefix('G') {
9
+ if !digits.is_empty() && digits.bytes().all(|b| b.is_ascii_digit()) {
10
+ let zeros = digits.bytes().take_while(|&b| b == b'0').count();
11
+ let remove = zeros.min(digits.len() - 1);
12
+ code.drain(1..1 + remove);
13
+ }
14
+ }
15
+ code
16
+ }
17
+
4
18
  /// Classify an (uppercased) G-command word: the G-group column it
5
19
  /// belongs to, and whether that group is modal. `None` means the word
6
20
  /// is not a known G command.
@@ -14,7 +14,7 @@
14
14
 
15
15
  use crate::errors::ParsingError;
16
16
  use crate::frame::{self, Matrix3};
17
- use crate::modal_groups::{classify_g_command, MODAL_G_GROUPS, NON_MODAL_G_GROUPS};
17
+ use crate::modal_groups::{classify_g_command, normalize_g_command, MODAL_G_GROUPS, NON_MODAL_G_GROUPS};
18
18
  use crate::output::OutputRows;
19
19
  use crate::state::{State, VarType};
20
20
  use crate::types::{NCParser, Rule, Value};
@@ -521,7 +521,7 @@ fn modal_group(field: &str, group: &str, code: &str) -> Result<(&'static str, St
521
521
  };
522
522
  return Err(invalid(field, &reason));
523
523
  };
524
- let code = code.trim().to_uppercase();
524
+ let code = normalize_g_command(code.trim());
525
525
  match classify_g_command(&code) {
526
526
  Some((found, _)) if found == column => Ok((column, code)),
527
527
  Some((found, _)) => Err(invalid(field, &format!("{code} belongs to {found}, not to {column}"))),