Skip to content

Commit

Permalink
Update nom from 7.1.3 to 8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jan 27, 2025
1 parent 2e86b63 commit 3304459
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
13 changes: 3 additions & 10 deletions 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 @@ -16,7 +16,7 @@ coveralls = { repository = "Ortham/esplugin" }
[dependencies]
encoding_rs = "0.8.35"
memchr = "2.7.4"
nom = "7.0.0"
nom = "8.0.0"
flate2 = { version = "1.0.35", optional = true }
unicase = "2.8.1"

Expand Down
8 changes: 4 additions & 4 deletions src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use nom::bytes::complete::{tag, take};
use nom::combinator::{all_consuming, map};
use nom::number::complete::le_u32;
use nom::sequence::delimited;
use nom::IResult;
use nom::{IResult, Parser};

use crate::error::Error;
use crate::game_id::GameId;
Expand All @@ -48,7 +48,7 @@ impl Group {
reader.read_exact(header_bytes)?;

let (_, size_of_records) =
all_consuming(parse_header(group_header_length, skip_length))(header_bytes)?;
all_consuming(parse_header(group_header_length, skip_length)).parse(header_bytes)?;

read_records(reader, game_id, form_ids, header_buffer, size_of_records)
}
Expand All @@ -74,7 +74,7 @@ fn parse_header(group_header_length: u8, skip_length: u8) -> impl Fn(&[u8]) -> I
map(
delimited(tag(GROUP_TYPE), le_u32, take(skip_length)),
move |group_size| group_size - u32::from(group_header_length),
)(input)
).parse(input)
}
}

Expand All @@ -98,7 +98,7 @@ fn read_records<R: BufRead + Seek>(
bytes_read += u32::from(group_header_length);

if &header_bytes[..GROUP_TYPE.len()] == GROUP_TYPE {
let (_, size_of_records) = all_consuming(&parse_header)(header_bytes)?;
let (_, size_of_records) = all_consuming(&parse_header).parse(header_bytes)?;

read_records(reader, game_id, form_ids, header_buffer, size_of_records)?;
bytes_read += size_of_records;
Expand Down
13 changes: 6 additions & 7 deletions src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ use std::num::NonZeroU32;
use nom::bytes::complete::take;
use nom::combinator::{cond, map};
use nom::number::complete::le_u32;
use nom::sequence::tuple;
use nom::IResult;
use nom::{IResult, Parser};

use crate::error::{Error, ParsingErrorKind};
use crate::game_id::GameId;
Expand Down Expand Up @@ -164,7 +163,7 @@ fn parse_morrowind_record_id<'a>(

fn all_consuming<I, T, E>(result: IResult<I, T, E>) -> Result<T, nom::Err<E>>
where
I: nom::InputLength,
I: nom::Input,
E: nom::error::ParseError<I>,
{
let (remaining_input, value) = result?;
Expand Down Expand Up @@ -275,12 +274,12 @@ fn record_type(input: &[u8]) -> IResult<&[u8], RecordType> {
map(take(RECORD_TYPE_LENGTH), |s: &[u8]| {
s.try_into()
.expect("record type slice should be the required length")
})(input)
}).parse(input)
}

fn record_header(input: &[u8], game_id: GameId) -> IResult<&[u8], RecordHeader> {
map(
tuple((
(
record_type,
le_u32,
cond(game_id == GameId::Morrowind, take(4usize)),
Expand All @@ -291,14 +290,14 @@ fn record_header(input: &[u8], game_id: GameId) -> IResult<&[u8], RecordHeader>
game_id != GameId::Morrowind && game_id != GameId::Oblivion,
take(4usize),
),
)),
),
|(record_type, size_of_subrecords, _, flags, form_id, _, _)| RecordHeader {
record_type,
flags,
form_id: form_id.and_then(NonZeroU32::new),
size_of_subrecords,
},
)(input)
).parse(input)
}

fn parse_subrecords(
Expand Down
14 changes: 7 additions & 7 deletions src/subrecord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use nom::bytes::complete::take;
use nom::combinator::map;
use nom::multi::length_data;
use nom::number::complete::{le_u16, le_u32};
use nom::sequence::{pair, preceded, separated_pair, tuple};
use nom::IResult;
use nom::sequence::{pair, preceded, separated_pair};
use nom::{IResult, Parser};

use crate::game_id::GameId;

Expand Down Expand Up @@ -143,23 +143,23 @@ fn subrecord_type(input: &[u8]) -> IResult<&[u8], SubrecordType> {
map(take(SUBRECORD_TYPE_LENGTH), |s: &[u8]| {
s.try_into()
.expect("subrecord type slice should be the required length")
})(input)
}).parse(input)
}

fn morrowind_subrecord(input: &[u8]) -> IResult<&[u8], (SubrecordType, &[u8])> {
tuple((subrecord_type, length_data(le_u32)))(input)
(subrecord_type, length_data(le_u32)).parse(input)
}

fn simple_subrecord(input: &[u8]) -> IResult<&[u8], (SubrecordType, &[u8])> {
tuple((subrecord_type, length_data(le_u16)))(input)
(subrecord_type, length_data(le_u16)).parse(input)
}

fn presized_subrecord(input: &[u8], data_length: u32) -> IResult<&[u8], (SubrecordType, &[u8])> {
separated_pair(subrecord_type, le_u16, take(data_length))(input)
separated_pair(subrecord_type, le_u16, take(data_length)).parse(input)
}

pub fn parse_subrecord_data_as_u32(input: &[u8]) -> IResult<&[u8], u32> {
preceded(pair(subrecord_type, le_u16), le_u32)(input)
preceded(pair(subrecord_type, le_u16), le_u32).parse(input)
}

#[cfg(test)]
Expand Down

0 comments on commit 3304459

Please sign in to comment.