diff --git a/src/parser.rs b/src/parser.rs index 0281305..314e6d2 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -57,7 +57,7 @@ static RE_INTERPOLATION: Lazy = static RE_MOVE_OR_FLASH: Lazy = lazy_regex!(r"X?(-?[0-9]+)?Y?(-?[0-9]+)?D(0)?[2-3]*"); static RE_IMAGE_NAME: Lazy = lazy_regex!(r"%IN(.*)\*%"); static RE_STEP_REPEAT: Lazy = - lazy_regex!(r"%SRX([0-9]+)Y([0-9]+)I(\d+\.?\d*)J(\d+\.?\d*)\*%"); + lazy_regex!(r"%SRX([0-9]+)Y([0-9]+)I(-?\d+\.?\d*)J(-?\d+\.?\d*)\*%"); static RE_MACRO_UNSIGNED_INTEGER: Lazy = lazy_regex!(r"^(?:(?P[0-9]+)|(?P\$[0-9]+)|(?P.*))$"); static RE_MACRO_BOOLEAN: Lazy = diff --git a/tests/component_tests.rs b/tests/component_tests.rs index e8fe0ac..dd5cff1 100644 --- a/tests/component_tests.rs +++ b/tests/component_tests.rs @@ -780,7 +780,7 @@ fn test_load_scaling_zero() { )); } -/// Test Step and Repeat command (%SR*%) +/// Test Step and Repeat command (%SR*%), including negative I/J offsets. #[test] fn step_and_repeat() { // given @@ -800,7 +800,11 @@ fn step_and_repeat() { X-1000Y-30000D01* %SR*% - M02* + %SRX12Y6I-3.33J-8.120*% + X0Y0D01* + %SR*% + + M02* ", ); @@ -825,6 +829,17 @@ fn step_and_repeat() { Ok(Command::ExtendedCode(ExtendedCode::StepAndRepeat( StepAndRepeat::Close ))), + Ok(Command::ExtendedCode(ExtendedCode::StepAndRepeat( + StepAndRepeat::Open { + repeat_x: 12, + repeat_y: 6, + distance_x: -3.33, + distance_y: -8.12, + } + ))), + Ok(Command::ExtendedCode(ExtendedCode::StepAndRepeat( + StepAndRepeat::Close + ))), ] ) }