Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor record matcher #835

Merged
merged 4 commits into from
Sep 21, 2024
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: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ jobs:
strategy:
matrix:
item:
- { name: pica-format, fuzz-dir: crates/pica-format/fuzz, target: fuzz-format, max-total-time: 300 }
- { name: pica-path, fuzz-dir: crates/pica-path/fuzz, target: fuzz-path, max-total-time: 300 }
- { name: pica-record-matcher, fuzz-dir: crates/pica-matcher/fuzz, target: fuzz-record-matcher, max-total-time: 300 }
- { name: pica-record-ref-v1, fuzz-dir: crates/pica-record-v1/fuzz, target: fuzz-record-ref, max-total-time: 300 }
- { name: pica-select-query, fuzz-dir: crates/pica-select/fuzz, target: fuzz-query, max-total-time: 300 }
- { name: pica-record-ref, fuzz-dir: fuzz, target: fuzz-record-ref, max-total-time: 300 }
- { name: pica-format, fuzz-dir: crates/pica-format/fuzz, target: fuzz-format, max-total-time: 120 }
- { name: pica-path, fuzz-dir: crates/pica-path/fuzz, target: fuzz-path, max-total-time: 120 }
- { name: pica-record-matcher-v1, fuzz-dir: crates/pica-matcher/fuzz, target: fuzz-record-matcher, max-total-time: 120 }
- { name: pica-record-ref-v1, fuzz-dir: crates/pica-record-v1/fuzz, target: fuzz-record-ref, max-total-time: 120 }
- { name: pica-select-query, fuzz-dir: crates/pica-select/fuzz, target: fuzz-query, max-total-time: 120 }
- { name: pica-record-ref, fuzz-dir: fuzz, target: fuzz-record-ref, max-total-time: 400 }
- { name: pica-record-matcher, fuzz-dir: fuzz, target: fuzz-record-matcher, max-total-time: 400 }
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
Expand Down
5 changes: 4 additions & 1 deletion crates/pica-record-v1/src/io/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ pub trait RecordsIterator {
}

impl<R: Read> RecordsIterator for Reader<R> {
type Item<'a> = Result<ByteRecord<'a>, ReadPicaError> where Self: 'a;
type Item<'a>
= Result<ByteRecord<'a>, ReadPicaError>
where
Self: 'a;

fn next(&mut self) -> Option<Self::Item<'_>> {
if self.limit > 0 && self.count >= self.limit {
Expand Down
7 changes: 7 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ path = "fuzz_targets/fuzz_record_ref.rs"
test = false
doc = false
bench = false

[[bin]]
name = "fuzz-record-matcher"
path = "fuzz_targets/fuzz_record_matcher.rs"
test = false
doc = false
bench = false
10 changes: 10 additions & 0 deletions fuzz/fuzz_targets/fuzz_record_matcher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use pica_record::prelude::*;

fuzz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
let _ = RecordMatcher::new(s);
}
});
5 changes: 2 additions & 3 deletions src/matcher/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{
use crate::prelude::SubfieldMatcher;
use crate::primitives::FieldRef;

mod parser;
pub(crate) mod parser;

/// A matcher that checks if a field exists.
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -561,8 +561,7 @@ impl BitAnd for FieldMatcher {
}

impl BitAndAssign for FieldMatcher {
/// The bitwise AND assignment operator `&=` of two
/// [FieldMatcher].
/// The bitwise AND assignment operator `&=` of two [FieldMatcher].
///
/// # Example
///
Expand Down
2 changes: 1 addition & 1 deletion src/matcher/field/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn parse_field_composite_matcher(
}

/// Parse a [FieldMatcher] expression.
pub(super) fn parse_field_matcher(
pub(crate) fn parse_field_matcher(
i: &mut &[u8],
) -> PResult<FieldMatcher> {
ws(alt((
Expand Down
2 changes: 2 additions & 0 deletions src/matcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use occurrence::OccurrenceMatcher;
pub use operator::{BooleanOp, RelationalOp};
pub use options::MatcherOptions;
pub use quantifier::Quantifier;
pub use record::RecordMatcher;
pub use tag::TagMatcher;

mod error;
Expand All @@ -13,5 +14,6 @@ mod occurrence;
mod operator;
mod options;
mod quantifier;
mod record;
pub mod subfield;
mod tag;
Loading