<commit_before>use lazy_static::lazy_static;

use super::{week2, year2, Manufacturer, Matcher, MatcherDef, Year};

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Accelerometer {
    pub chip_type: Option<String>,
    pub manufacturer: Option<Manufacturer>,
    pub year: Option<Year>,
    pub week: Option<u8>,
}

/// ```
/// # use gbhwdb_backend::parser::parse_accelerometer;
/// assert!(parse_accelerometer("2738109451 0028 ADXL202JQC").is_some());
/// ```
fn analog_adxl202jqc() -> MatcherDef<Accelerometer> {
    MatcherDef(
        r#"^[0-9]{10}\ ([0-9]{2})([0-9]{2})\ ADXL202JQC?$"#,
        move |c| {
            Ok(Accelerometer {
                chip_type: Some("ADXL202JQC".to_owned()),
                manufacturer: Some(Manufacturer::Analog),
                year: Some(year2(&c[1])?),
                week: Some(week2(&c[2])?),
            })
        },
    )
}

pub fn parse_accelerometer(text: &str) -> Option<Accelerometer> {
    lazy_static! {
        static ref MATCHER: Matcher<Accelerometer> = analog_adxl202jqc().into();
    }
    MATCHER.apply(text)
}<commit_msg>Make ADXL202JQC parser stricter<commit_after>use lazy_static::lazy_static;

use super::{week2, year2, Manufacturer, Matcher, MatcherDef, Year};

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Accelerometer {
    pub chip_type: Option<String>,
    pub manufacturer: Option<Manufacturer>,
    pub year: Option<Year>,
    pub week: Option<u8>,
}

/// ```
/// # use gbhwdb_backend::parser::parse_accelerometer;
/// assert!(parse_accelerometer("2738109451 0028 ADXL202JQC").is_some());
/// ```
fn analog_adxl202jqc() -> MatcherDef<Accelerometer> {
    MatcherDef(
        r#"^[0-9]{10}\ ([0-9]{2})([0-9]{2})\ ADXL202JQC$"#,
        move |c| {
            Ok(Accelerometer {
                chip_type: Some("ADXL202JQC".to_owned()),
                manufacturer: Some(Manufacturer::Analog),
                year: Some(year2(&c[1])?),
                week: Some(week2(&c[2])?),
            })
        },
    )
}

pub fn parse_accelerometer(text: &str) -> Option<Accelerometer> {
    lazy_static! {
        static ref MATCHER: Matcher<Accelerometer> = analog_adxl202jqc().into();
    }
    MATCHER.apply(text)
}
{'fraction_non_alphanumeric': 0.16902050113895217, 'fraction_numerical': 0.04328018223234624, 'mean_word_length': 3.066666666666667, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4650735', 'n_tokens_mistral': 841, 'n_tokens_neox': 770, 'n_words': 129}