Skip to content

Commit 04cc241

Browse files
committed
fix: soften canonical parser
1 parent 766f21b commit 04cc241

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/parser/step.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ fn cookware<'i>(bp: &mut BlockParser<'_, 'i>) -> Option<Event<'i>> {
384384
} else {
385385
unit.span()
386386
};
387-
bp.error(
388-
error!(
387+
bp.warn(
388+
warning!(
389389
"Invalid cookware quantity: unit",
390390
label!(span, "remove this"),
391391
)
@@ -443,8 +443,8 @@ fn timer<'i>(bp: &mut BlockParser<'_, 'i>) -> Option<Event<'i>> {
443443
let mut quantity = body.quantity.map(|tokens| {
444444
let q = parse_quantity(bp, tokens);
445445
if q.quantity.unit.is_none() {
446-
bp.error(
447-
error!(
446+
bp.warn(
447+
warning!(
448448
"Invalid timer quantity: missing unit",
449449
label!(
450450
Span::pos(q.quantity.value.span().end()),
@@ -478,7 +478,7 @@ fn timer<'i>(bp: &mut BlockParser<'_, 'i>) -> Option<Event<'i>> {
478478
} else {
479479
Span::pos(name_offset)
480480
};
481-
bp.error(error!(
481+
bp.warn(warning!(
482482
"Invalid timer: neither quantity nor name",
483483
label!(span, "expected duration or name"),
484484
));

tests/general_tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,27 @@ fn text_steps_extension() {
247247
[Content::Text(_)]
248248
));
249249
}
250+
251+
#[test]
252+
fn timer_missing_unit_warning() {
253+
let input = "Cook for ~{30}";
254+
255+
let parser = CooklangParser::canonical();
256+
let result = parser.parse(input);
257+
258+
// Check that we get a warning, not an error
259+
let report = result.report();
260+
261+
// Verify we have exactly one warning
262+
assert_eq!(report.iter().count(), 1);
263+
264+
// Check that it's a warning, not an error
265+
let diag = report.iter().next().unwrap();
266+
assert_eq!(diag.severity, cooklang::error::Severity::Warning);
267+
268+
// Verify the warning message
269+
assert!(diag.message.contains("Invalid timer quantity: missing unit"));
270+
271+
// Should parse successfully (not error)
272+
let _r = result.unwrap_output();
273+
}

0 commit comments

Comments
 (0)