plotter: document lexer provenance and pin framing recovery

This commit is contained in:
Dylan M. Taylor committed 2026-11-16 21:16:34 -05:00
1 parent 551cb98786
commit 9101c4fc22
2 files changed
+44

No files matched your search

+14
View File
@@ -78,3 +78,17 @@ is MIT OR Apache-2.0 like the rest of the repository. Vendor binaries were not d
decompiled or debugged. The line-segment overcut is this crate's own geometric rule, not a
captured vendor stream. When extending the crate, keep to this: public documentation and
observed device behaviour, never GPL driver source.
## HP-GL byte lexer
`hpgl::lex` also exposes a borrowing HP-GL/2 lexer with PCL/PJL framing,
label/comment skipping and encoded polyline values. It does not interpret drawing
commands or replace the existing cutter encoder. The caller supplies numeric
storage and controls document/geometry budgets; scanning time is proportional to
input consumed, not capped by this API. PJL language detection copies at most 256
bytes of a line. Malformed-input recovery retains the original VectorCraft behavior.
This module comes from dotCooCoo's VectorCraft `crates/cad/src/hpgl/lex.rs`,
commit `74ea25cd6c4dffa4cd41f6ee9a76f7afd4225622` (MIT OR Apache-2.0),
with public visibility for reuse. The drawing interpreter and export policies remain
in VectorCraft. Existing plotter encoders and their device limits are unchanged.
+30
View File
@@ -426,3 +426,33 @@ impl<'a> Lexer<'a> {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn framing_labels_and_bounded_numbers() {
let mut lex = Lexer::new(b"\x1b%-12345X@PJL ENTER LANGUAGE=HPGL2\nIN;LBPU999;\x03PA1,2,3,4;SP2;");
assert_eq!(lex.op(true), Some(*b"IN"));
lex.params();
assert_eq!(lex.op(true), Some(*b"LB"));
lex.label(ETX);
assert_eq!(lex.op(true), Some(*b"PA"));
let mut values = [0.0; 2];
assert_eq!(lex.numbers(&mut values), 2);
assert_eq!(values, [1.0, 2.0]);
assert_eq!(lex.op(true), Some(*b"SP"));
assert_eq!(lex.number(), Some(2.0));
}
#[test]
fn encoded_flags_and_truncated_pair_recover_at_semicolon() {
let mut lex = Lexer::new(b"PE<=\xc1\xc3\xc5;PU;");
assert_eq!(lex.op(true), Some(*b"PE"));
let mut state = Pe::default();
assert_eq!(lex.pe(&mut state), Some(PeItem::Point { x: 1.0, y: 2.0, up: true, absolute: true }));
assert_eq!(lex.pe(&mut state), None);
assert_eq!(lex.op(true), Some(*b"PU"));
}
}