From bb5e0c9917e424f20941bcc01f44266ca7156993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 16 Feb 2025 19:43:08 +0200 Subject: [PATCH] closedcaption: Update to winnow 0.7 Part-of: --- Cargo.lock | 13 ++---------- video/closedcaption/Cargo.toml | 2 +- video/closedcaption/src/mcc_parse/parser.rs | 22 ++++++++++----------- video/closedcaption/src/parser_utils.rs | 10 +++++----- video/closedcaption/src/scc_parse/parser.rs | 12 +++++------ 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c1608a8a..fad7e5309 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2581,7 +2581,7 @@ dependencies = [ "serde_json", "smallvec", "uuid", - "winnow 0.6.26", + "winnow", ] [[package]] @@ -7834,7 +7834,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.7.2", + "winnow", ] [[package]] @@ -8706,15 +8706,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.6.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e90edd2ac1aa278a5c4599b1d89cf03074b610800f866d4026dc199d7929a28" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.7.2" diff --git a/video/closedcaption/Cargo.toml b/video/closedcaption/Cargo.toml index b0a1eb7ff..9c7d4db15 100644 --- a/video/closedcaption/Cargo.toml +++ b/video/closedcaption/Cargo.toml @@ -25,7 +25,7 @@ cea608-types = "0.1.1" gst = { workspace = true, features = ["v1_20"]} gst-base = { workspace = true, features = ["v1_22"]} gst-video = { workspace = true, features = ["v1_16"]} -winnow = "0.6" +winnow = "0.7" smallvec = "1" bitstream-io = "2.3" itertools = "0.13" diff --git a/video/closedcaption/src/mcc_parse/parser.rs b/video/closedcaption/src/mcc_parse/parser.rs index f5f77ed26..34acd2fa5 100644 --- a/video/closedcaption/src/mcc_parse/parser.rs +++ b/video/closedcaption/src/mcc_parse/parser.rs @@ -9,7 +9,7 @@ use either::Either; use crate::parser_utils::{digits, digits_range, end_of_line, timecode, TimeCode}; -use winnow::{error::StrContext, PResult, Parser}; +use winnow::{error::StrContext, ModalParser, ModalResult, Parser}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum MccLine<'a> { @@ -37,7 +37,7 @@ pub struct MccParser { } /// Parser for the MCC header -fn header<'a>(s: &mut &'a [u8]) -> PResult> { +fn header<'a>(s: &mut &'a [u8]) -> ModalResult> { use winnow::combinator::{alt, opt}; use winnow::token::literal; @@ -54,7 +54,7 @@ fn header<'a>(s: &mut &'a [u8]) -> PResult> { /// Parser for an MCC comment, i.e. a line starting with `//`. We don't return the actual comment /// text as it's irrelevant for us. -fn comment<'a>(s: &mut &'a [u8]) -> PResult> { +fn comment<'a>(s: &mut &'a [u8]) -> ModalResult> { use winnow::token::{literal, rest}; (literal("//"), rest) @@ -64,7 +64,7 @@ fn comment<'a>(s: &mut &'a [u8]) -> PResult> { } /// Parser for the MCC UUID line. -fn uuid<'a>(s: &mut &'a [u8]) -> PResult> { +fn uuid<'a>(s: &mut &'a [u8]) -> ModalResult> { use winnow::token::{literal, take_while}; ( @@ -78,7 +78,7 @@ fn uuid<'a>(s: &mut &'a [u8]) -> PResult> { } /// Parser for the MCC Time Code Rate line. -fn time_code_rate<'a>(s: &mut &'a [u8]) -> PResult> { +fn time_code_rate<'a>(s: &mut &'a [u8]) -> ModalResult> { use winnow::combinator::opt; use winnow::token::literal; @@ -94,7 +94,7 @@ fn time_code_rate<'a>(s: &mut &'a [u8]) -> PResult> { } /// Parser for generic MCC metadata lines in the form `key=value`. -fn metadata<'a>(s: &mut &'a [u8]) -> PResult> { +fn metadata<'a>(s: &mut &'a [u8]) -> ModalResult> { use winnow::token::{one_of, take_while}; ( @@ -109,7 +109,7 @@ fn metadata<'a>(s: &mut &'a [u8]) -> PResult> { } /// Parser that accepts only an empty line -fn empty_line<'a>(s: &mut &'a [u8]) -> PResult> { +fn empty_line<'a>(s: &mut &'a [u8]) -> ModalResult> { end_of_line .map(|_| MccLine::Empty) .context(StrContext::Label("invalid empty line")) @@ -121,7 +121,7 @@ fn empty_line<'a>(s: &mut &'a [u8]) -> PResult> { /// /// It returns an `Either` of the single hex encoded byte or the short-cut byte sequence as a /// static byte slice. -fn mcc_payload_item(s: &mut &[u8]) -> PResult> { +fn mcc_payload_item(s: &mut &[u8]) -> ModalResult> { use winnow::combinator::alt; use winnow::stream::AsChar; use winnow::token::{literal, take_while}; @@ -209,7 +209,7 @@ fn mcc_payload_item(s: &mut &[u8]) -> PResult> { } /// Parser for the whole MCC payload with conversion to the underlying byte values. -fn mcc_payload(s: &mut &[u8]) -> PResult> { +fn mcc_payload(s: &mut &[u8]) -> ModalResult> { use winnow::combinator::repeat; repeat(1.., mcc_payload_item) @@ -227,13 +227,13 @@ fn mcc_payload(s: &mut &[u8]) -> PResult> { /// Parser for a MCC caption line in the form `timecode\tpayload`. fn caption<'a>( parse_payload: bool, -) -> impl Parser<&'a [u8], MccLine<'a>, winnow::error::ContextError> { +) -> impl ModalParser<&'a [u8], MccLine<'a>, winnow::error::ContextError> { use winnow::combinator::opt; use winnow::token::{one_of, take_while}; fn parse<'a>( parse_payload: bool, - ) -> impl Parser<&'a [u8], Option>, winnow::error::ContextError> { + ) -> impl ModalParser<&'a [u8], Option>, winnow::error::ContextError> { move |s: &mut &'a [u8]| { if parse_payload { mcc_payload.map(Some).parse_next(s) diff --git a/video/closedcaption/src/parser_utils.rs b/video/closedcaption/src/parser_utils.rs index 635c1e218..6e51cd7f9 100644 --- a/video/closedcaption/src/parser_utils.rs +++ b/video/closedcaption/src/parser_utils.rs @@ -6,7 +6,7 @@ // // SPDX-License-Identifier: MPL-2.0 -use winnow::{error::StrContext, PResult, Parser}; +use winnow::{error::StrContext, ModalParser, ModalResult, Parser}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct TimeCode { @@ -18,7 +18,7 @@ pub struct TimeCode { } /// Parser for parsing a run of ASCII, decimal digits and converting them into a `u32` -pub fn digits(s: &mut &[u8]) -> PResult { +pub fn digits(s: &mut &[u8]) -> ModalResult { use winnow::stream::AsChar; use winnow::token::take_while; @@ -32,7 +32,7 @@ pub fn digits(s: &mut &[u8]) -> PResult { /// in the allowed range. pub fn digits_range<'a, R: std::ops::RangeBounds>( range: R, -) -> impl Parser<&'a [u8], u32, winnow::error::ContextError> { +) -> impl ModalParser<&'a [u8], u32, winnow::error::ContextError> { move |s: &mut &'a [u8]| { digits .verify(|v| range.contains(v)) @@ -42,7 +42,7 @@ pub fn digits_range<'a, R: std::ops::RangeBounds>( } /// Parser for a timecode in the form `hh:mm:ss:fs` -pub fn timecode(s: &mut &[u8]) -> PResult { +pub fn timecode(s: &mut &[u8]) -> ModalResult { use winnow::token::one_of; ( @@ -66,7 +66,7 @@ pub fn timecode(s: &mut &[u8]) -> PResult { } /// Parser that checks for EOF and optionally `\n` or `\r\n` before EOF -pub fn end_of_line(s: &mut &[u8]) -> PResult<()> { +pub fn end_of_line(s: &mut &[u8]) -> ModalResult<()> { use winnow::combinator::alt; use winnow::combinator::{eof, opt}; use winnow::token::literal; diff --git a/video/closedcaption/src/scc_parse/parser.rs b/video/closedcaption/src/scc_parse/parser.rs index 357a799e0..90bef4b63 100644 --- a/video/closedcaption/src/scc_parse/parser.rs +++ b/video/closedcaption/src/scc_parse/parser.rs @@ -8,7 +8,7 @@ // SPDX-License-Identifier: MPL-2.0 use crate::parser_utils::{end_of_line, timecode, TimeCode}; -use winnow::{error::StrContext, PResult, Parser}; +use winnow::{error::StrContext, ModalResult, Parser}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum SccLine { @@ -30,7 +30,7 @@ pub struct SccParser { } /// Parser for the SCC header -fn header(s: &mut &[u8]) -> PResult { +fn header(s: &mut &[u8]) -> ModalResult { use winnow::combinator::opt; use winnow::token::literal; @@ -45,7 +45,7 @@ fn header(s: &mut &[u8]) -> PResult { } /// Parser that accepts only an empty line -fn empty_line(s: &mut &[u8]) -> PResult { +fn empty_line(s: &mut &[u8]) -> ModalResult { end_of_line .map(|_| SccLine::Empty) .context(StrContext::Label("invalid empty line")) @@ -54,7 +54,7 @@ fn empty_line(s: &mut &[u8]) -> PResult { /// A single SCC payload item. This is ASCII hex encoded bytes. /// It returns an tuple of `(u8, u8)` of the hex encoded bytes. -fn scc_payload_item(s: &mut &[u8]) -> PResult<(u8, u8)> { +fn scc_payload_item(s: &mut &[u8]) -> ModalResult<(u8, u8)> { use winnow::stream::AsChar; use winnow::token::take_while; @@ -77,7 +77,7 @@ fn scc_payload_item(s: &mut &[u8]) -> PResult<(u8, u8)> { } /// Parser for the whole SCC payload with conversion to the underlying byte values. -fn scc_payload(s: &mut &[u8]) -> PResult> { +fn scc_payload(s: &mut &[u8]) -> ModalResult> { use winnow::combinator::{alt, repeat}; use winnow::token::literal; @@ -98,7 +98,7 @@ fn scc_payload(s: &mut &[u8]) -> PResult> { } /// Parser for a SCC caption line in the form `timecode\tpayload`. -fn caption(s: &mut &[u8]) -> PResult { +fn caption(s: &mut &[u8]) -> ModalResult { use winnow::ascii::multispace0; use winnow::token::literal;