Skip to content

Commit 85a382d

Browse files
author
Nico Lube
committed
Support deprecated G54 aperture-select prefix.
Accepts standalone `G54*` and the combined `G54Dnn*` form still emitted by gerbv on save. See gerber spec 8.1.1. Fixes: #16
1 parent 6ca41d3 commit 85a382d

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

src/parser.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,30 @@ fn parse_line<T: Read>(
263263
_ => Err(ContentError::UnknownCommand {}),
264264
},
265265
]),
266+
'5' => {
267+
// G54 is the deprecated aperture-select prefix (gerber spec 8.1.1).
268+
// The combined `G54Dnn*` form is still emitted by gerbv on save.
269+
match linechars.next().ok_or(ContentError::UnknownCommand {})? {
270+
'4' => {
271+
let select = Ok(FunctionCode::GCode(GCode::SelectAperture).into());
272+
match linechars.next() {
273+
None | Some('*') => Ok(vec![select]),
274+
Some('D') => {
275+
linechars.next_back();
276+
Ok(vec![
277+
select,
278+
parse_aperture_selection_or_command(
279+
line,
280+
linechars.clone(),
281+
),
282+
])
283+
}
284+
Some(_) => Ok(vec![Err(ContentError::UnknownCommand {})]),
285+
}
286+
}
287+
_ => Ok(vec![Err(ContentError::UnknownCommand {})]),
288+
}
289+
}
266290
_ => Ok(vec![Err(ContentError::UnknownCommand {})]),
267291
}
268292
}

tests/component_tests.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,65 @@ fn aperture_selection() {
319319
)
320320
}
321321

322+
/// Test deprecated `G54` aperture selection (gerber spec 8.1.1).
323+
/// Accepts both `G54*` (standalone) and the combined `G54Dnn*` form (emitted by gerbv on save).
324+
#[test]
325+
fn deprecated_g54_aperture_selection() {
326+
// given
327+
logging_init();
328+
329+
let reader = gerber_to_reader(
330+
"
331+
%FSLAX23Y23*%
332+
%MOMM*%
333+
334+
%ADD10C, 0.01*%
335+
%ADD11R, 0.01X0.15*%
336+
337+
G04 Deprecated combined G54Dnn form*
338+
G54D10*
339+
G04 Deprecated standalone G54 form*
340+
G54*
341+
G04 Deprecated combined G54Dnn form again*
342+
G54D11*
343+
344+
M02*
345+
",
346+
);
347+
348+
// when
349+
parse_and_filter!(reader, commands, filtered_commands, |cmd| matches!(
350+
cmd,
351+
Ok(Command::FunctionCode(FunctionCode::DCode(
352+
DCode::SelectAperture(_)
353+
))) | Ok(Command::FunctionCode(FunctionCode::GCode(
354+
GCode::SelectAperture
355+
)))
356+
));
357+
358+
// then
359+
assert_eq!(
360+
filtered_commands,
361+
vec![
362+
Ok(Command::FunctionCode(FunctionCode::GCode(
363+
GCode::SelectAperture
364+
))),
365+
Ok(Command::FunctionCode(FunctionCode::DCode(
366+
DCode::SelectAperture(10)
367+
))),
368+
Ok(Command::FunctionCode(FunctionCode::GCode(
369+
GCode::SelectAperture
370+
))),
371+
Ok(Command::FunctionCode(FunctionCode::GCode(
372+
GCode::SelectAperture
373+
))),
374+
Ok(Command::FunctionCode(FunctionCode::DCode(
375+
DCode::SelectAperture(11)
376+
))),
377+
]
378+
)
379+
}
380+
322381
/// Test the D01* statements (linear)
323382
#[test]
324383
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)