Skip to content

Parse Gerber command streams without dropping errors - #26

Open
mfiumara wants to merge 2 commits into
MakerPnP:masterfrom
ratemypcb:ratemypcb/gerber-parser-accounting-fix
Open

Parse Gerber command streams without dropping errors#26
mfiumara wants to merge 2 commits into
MakerPnP:masterfrom
ratemypcb:ratemypcb/gerber-parser-accounting-fix

Conversation

@mfiumara

Copy link
Copy Markdown

Summary

  • parse *-terminated Gerber commands even when a file does not put each command on its own line
  • retain outer tokenizer/parser errors instead of silently dropping those command blocks
  • add regression tests for compact same-line commands and retained malformed-command errors

Gerber line endings are formatting only; * terminates commands. The released parser can therefore lose valid commands in compact streams. The first commit is the focused tokenizer change from #25. The follow-up keeps every outer parse_line error in the returned document rather than losing it through iterator flattening.

This intentionally excludes #25's later breaking ErrorContext API change and single-digit G-code expansion.

Verification

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings -A clippy::blocks_in_conditions (the allowed test lint predates this change)
  • cargo test --all-features — 57 passed
  • RateMyPCB compact/error mutation checks — 7 passed
  • Ucamco local corpus — 32 files, 102,909 records, zero unaccounted errors

Nico Lube and others added 2 commits May 21, 2026 10:07
Commands are delimited by `*`, not newlines (spec 4.1). The old line-based tokenizer merged single-line files into one block, causing a spurious CoordinateDataWithoutOperationCode error. Now splits on `*`, treats `%...%` spans (incl. macros) as one block, and ends a block at a newline outside such spans.
@hydra

hydra commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Hi, I downloaded your branch and applied to my local copy, all the tests pass ok.

I then updated the gerber-viewer to use my updated local copy, but it fails to parse many of the elements in the main demo.

here's what it should look like:

image

here's what it looks like with this PR.

image

You can see that many of the elements are missing.

log.txt

I attached the error log for you.

To me this indicates the changes in this PR break the parsing code in an unexpected way, for which we don't have a test for.

Please can you investigate and create a new test which covers the parsing failure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants