Skip to content

S-bnd — one boundary G-code→Program reader; simulator & plotter go IR-native #282

Closed

Description

@CameronBrooks11

Slice S-bnd of #136 — consolidate the two G-code re-parsers into ONE boundary adapter so the simulator and plotter become IR-native.

Problem

The simulator (simulate_program, line.split()) and plotter (_collect_segments, 'G0' text + ast.literal_eval of the ; Parameters header) each independently parse G-code text and re-derive motion — the duplication the epic targets. Each also carries its own _detect_dialect/_extract_metadata.

Approach — output-preserving

Introduce fiberpath/gcode/reader.py::read_program(lines, *, dialect=None) -> Program: the single inverse of serialize. It parses the ; Parameters header → ProgramMeta, detects the dialect once, and lowers each line to a Move (G0 F…→SET_FEED, G0 …→RAPID, G92 …→SET_POSITION, comments→COMMENT).

The CLI/API boundary parses text→Program once; the simulator and plotter consume the IR. This slice deliberately changes no numbers: both consumers reproduce today's output exactly (the simulator stays G92-blind, marked minimal: for S3; the plotter unchanged). So the gate is a 100%-green sim_plot_snapshot.json with no regen, proving the reader faithful in isolation — the #274 analog. G92-awareness / O1 unification land as the isolated, reviewable regens in S3 (sim) and S4 (plot).

Acceptance

  • read_program is the sole G-code text parser; simulator & plotter take a Program (verifiable by grep — no .split() G-code parsing outside the reader).
  • NEW tests/gcode/test_reader_roundtrip.py: serialize(read_program(g), dialect) reproduces each of the 7 frozen goldens byte-for-byte, + unit tests (header, comment, G92, feed, mixed feed+motion).
  • tests/test_example_goldens.py byte-equal (untouched).
  • tests/test_sim_plot_snapshot.py green without FIBERPATH_UPDATE_GOLDENS (output-preserving proof).
  • CLI simulate/plot <file.gcode> and the /simulate+/plot routes parse via the boundary reader; external-.gcode use case preserved; GUI {gcode}→/plot unaffected; no OpenAPI drift.
  • ruff + mypy clean.

Part of #136. Followed by S3 (simulator shares nominal_metrics), S4 (plotter IR geometry), S5 (delete dead parsers + CI guard).

Activity

  1. added
    python
    on Jun 28, 2026
  2. added a commit that references this issue on Jun 28, 2026
    8964637
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    python

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions