Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and

## [Unreleased]

## [0.11.3] - 2026-11-03

### Changed

- A `SkippedRecord` diagnostic now reports the record's instance id through
`Diagnostic::instance()` when its `#id` token was read, as written (leading
zeros kept). A record skipped before any `#id` was read still reports
`None`. Sequential and parallel parses agree (#17). When one skip covers
several records, only the first id is reported.

## [0.11.2] - 2026-10-28

### Changed
Expand Down Expand Up @@ -459,7 +469,8 @@ slots) and are pinned in `tests/schema_graph.rs`.
- Arbitrary-precision instance IDs, classic user-defined keywords, and legacy alphabet-selection decoding.
- Incremental event parsing with bounded token buffering.

[Unreleased]: https://github.com/openbimrs/step/compare/v0.11.2...HEAD
[Unreleased]: https://github.com/openbimrs/step/compare/v0.11.3...HEAD
[0.11.3]: https://github.com/openbimrs/step/compare/v0.11.2...v0.11.3
[0.11.2]: https://github.com/openbimrs/step/compare/v0.11.1...v0.11.2
[0.11.1]: https://github.com/openbimrs/step/compare/v0.11.0...v0.11.1
[0.11.0]: https://github.com/openbimrs/step/compare/v0.10.0...v0.11.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["openbim-step"]
resolver = "2"

[workspace.package]
version = "0.11.2"
version = "0.11.3"
edition = "2021"
rust-version = "1.99"
license = "AGPL-3.0-or-later OR LicenseRef-Commercial"
Expand Down
14 changes: 11 additions & 3 deletions openbim-step/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<'a, S: Text<'a>> Parser<'a, S> {
Err(error) => {
// A lexical defect inside DATA is recoverable: the damaged
// bytes belong to one record, not to the file structure.
self.recover_or_fail(error, None)?;
self.recover_or_fail(error, None, None)?;
continue;
}
};
Expand Down Expand Up @@ -626,15 +626,19 @@ impl<'a, S: Text<'a>> Parser<'a, S> {
}
sink.event(Event::DataRecord(record));
}
Err(error) => self.recover_or_fail(error, Some(start))?,
Err(error) => self.recover_or_fail(
error,
Some(start),
InstanceId::from_ascii_digits(&id),
)?,
}
}
_ => {
let error = StepError::syntax(
token.span,
format!("unexpected token {:?} in {:?}", token.value, self.phase),
);
self.recover_or_fail(error, Some(token.span.start))?;
self.recover_or_fail(error, Some(token.span.start), None)?;
}
}
}
Expand Down Expand Up @@ -716,10 +720,13 @@ impl<'a, S: Text<'a>> Parser<'a, S> {
/// fatal under every policy: they describe the file, not one payload
/// record, and silently continuing past them would produce a model whose
/// provenance is unknown.
///
/// `instance` is the record's id when its `#id` token was read.
fn recover_or_fail(
&mut self,
error: StepError,
record_start: Option<usize>,
instance: Option<InstanceId>,
) -> Result<(), StepError> {
if self.options.on_malformed_record != OnMalformed::Skip || self.phase != Phase::Data {
return Err(error);
Expand All @@ -739,6 +746,7 @@ impl<'a, S: Text<'a>> Parser<'a, S> {
self.diagnostics.push(Diagnostic::skipped_record(
Span::new(start, resume),
format!("skipped malformed data record: {}", error.detail()),
instance,
));
Ok(())
}
Expand Down
18 changes: 15 additions & 3 deletions openbim-step/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,16 @@ pub struct Diagnostic {
}

impl Diagnostic {
pub(crate) fn skipped_record(span: Span, detail: impl Into<String>) -> Self {
pub(crate) fn skipped_record(
span: Span,
detail: impl Into<String>,
instance: Option<InstanceId>,
) -> Self {
Self {
severity: Severity::Warning,
kind: DiagnosticKind::SkippedRecord,
span,
instance: None,
instance,
detail: detail.into(),
}
}
Expand Down Expand Up @@ -216,7 +220,15 @@ impl Diagnostic {
/// The instance id at fault. For a duplicate it is the later record's id
/// as written; for a dangling reference it is the missing id in canonical
/// form (leading zeros removed, since `#07` and `#7` are the same
/// instance). `None` for a skipped record and a real without a point.
/// instance); for a skipped record it is its id as written when the
/// `#id` token was read. `None` for a skipped record whose id was not
/// read, and for a real without a point.
///
/// A skipped record's id is that of the record where the damage started.
/// Its span can cover further records, whose ids are not reported, and
/// the id is the token that was read, not a guarantee that no kept
/// record uses it. Compare it with a dangling reference's id after
/// removing leading zeros.
#[must_use]
pub const fn instance(&self) -> Option<&InstanceId> {
self.instance.as_ref()
Expand Down
7 changes: 7 additions & 0 deletions openbim-step/tests/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ fn skipped_and_duplicate_diagnostics_interleave_in_source_order() {
.collect();
// Guard: the fixture really interleaves skip and duplicate diagnostics.
assert_ne!(kinds[0], kinds[1], "fixture does not interleave: {kinds:?}");
// A skipped record reports its id, which the parallel parse must keep.
assert_eq!(
sequential.diagnostics[0]
.instance()
.map(openbim_step::InstanceId::as_str),
Some("10010")
);
assert_same(out.as_bytes(), "interleaved diagnostics");
}

Expand Down
54 changes: 49 additions & 5 deletions openbim-step/tests/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn a_reference_to_a_skipped_record_is_dangling() {
assert_eq!(
kinds(&outcome.diagnostics),
[
(DiagnosticKind::SkippedRecord, String::new()),
(DiagnosticKind::SkippedRecord, "1".to_owned()),
(DiagnosticKind::DanglingReference, "1".to_owned()),
]
);
Expand Down Expand Up @@ -184,12 +184,56 @@ fn the_event_api_reports_the_same_diagnostics() {
assert_eq!(diagnostics, owned);
}

/// A skipped record whose `#id` was read reports that id as written, so a
/// consumer can name it and keep it from being reused.
#[test]
fn skipped_record_diagnostics_have_their_kind_and_no_instance() {
let input = exchange("#1=A(@);");
fn skipped_record_diagnostics_have_their_kind_and_the_id_as_written() {
for (records, id) in [
("#1=A(@);", "1"),
("#17\n XXSITE('a',$);", "17"),
("#007=A(,);", "007"),
] {
let input = exchange(records);
let outcome = parse_with(input.as_bytes(), ParseOptions::lenient()).unwrap();
assert_eq!(outcome.diagnostics[0].kind(), DiagnosticKind::SkippedRecord);
assert_eq!(
outcome.diagnostics[0].instance().map(InstanceId::as_str),
Some(id),
"{records}"
);
}
}

/// A record skipped before any `#id` was read has no instance: an
/// unexpected token, or a lexical defect at the record's first byte.
#[test]
fn a_skipped_record_without_an_id_has_no_instance() {
for records in ["A(1);\n#2=B();", "@;\n#2=B();"] {
let input = exchange(records);
let outcome = parse_with(input.as_bytes(), ParseOptions::lenient()).unwrap();
assert_eq!(outcome.diagnostics[0].kind(), DiagnosticKind::SkippedRecord);
assert_eq!(
outcome.diagnostics[0].instance(),
None::<&InstanceId>,
"{records}"
);
assert_eq!(outcome.exchange.data.records.len(), 1, "{records}");
}
}

/// A record missing its `;` swallows the next one: one diagnostic, naming
/// only the first id, with a span over both.
#[test]
fn a_skip_over_several_records_names_only_the_first() {
let input = exchange("#1=A(1)\n#2=B();\n#3=C();");
let outcome = parse_with(input.as_bytes(), ParseOptions::lenient()).unwrap();
assert_eq!(outcome.diagnostics[0].kind(), DiagnosticKind::SkippedRecord);
assert_eq!(outcome.diagnostics[0].instance(), None::<&InstanceId>);
assert_eq!(
kinds(&outcome.diagnostics),
[(DiagnosticKind::SkippedRecord, "1".to_owned())]
);
let span = outcome.diagnostics[0].span();
assert!(input[span.start..span.end].contains("#2=B();"));
assert_eq!(outcome.exchange.data.records.len(), 1);
}

/// One aggregation record forward-referencing many ids must stay linear:
Expand Down
Loading