<commit_before>#[phase(plugin)]
extern crate peg_syntax_ext;

use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};

pub struct PropertyValue {
    params: String,
    value: String,
}

impl PropertyValue {
    pub fn get_raw_value(&self) -> &String { &self.value }
    pub fn get_raw_params(&self) -> &String { &self.params }
}


pub struct Item {
    pub props: HashMap<String, Vec<PropertyValue>>,
    empty_prop_vector: Vec<PropertyValue>
}

impl Item {
    fn new() -> Item {
        Item {
            props: HashMap::new(),
            empty_prop_vector: vec![]
        }
    }

    pub fn single_value(&self, key: &String) -> Option<&String> {
        match self.props.find(key) {
            Some(x) => { if x.len() > 0 { Some(x[0].get_raw_value()) } else { None } },
            None => { None }
        }
    }

    pub fn all_values_mut(&mut self, key: String) -> &mut Vec<PropertyValue> {
        match self.props.entry(key) {
            Occupied(values) => values.into_mut(),
            Vacant(values) => values.set(vec![])
        }
    }

    pub fn all_values(&self, key: &String) -> &Vec<PropertyValue> {
        match self.props.find(key) {
            Some(values) => values,
            None => &self.empty_prop_vector
        }
    }
}


peg! parser(r#"
use super::{Item,PropertyValue};

#[pub]
<commit_msg>Remove stupid default value field<commit_after>#[phase(plugin)]
extern crate peg_syntax_ext;

use std::collections::HashMap;
use std::collections::hashmap::{Occupied, Vacant};

pub struct PropertyValue {
    params: String,
    value: String,
}

impl PropertyValue {
    pub fn get_raw_value(&self) -> &String { &self.value }
    pub fn get_raw_params(&self) -> &String { &self.params }
}


pub struct Item {
    pub props: HashMap<String, Vec<PropertyValue>>
}

impl Item {
    fn new() -> Item {
        Item {
            props: HashMap::new()
        }
    }

    pub fn single_value(&self, key: &String) -> Option<&String> {
        match self.props.find(key) {
            Some(x) => { if x.len() > 0 { Some(x[0].get_raw_value()) } else { None } },
            None => { None }
        }
    }

    pub fn all_values_mut(&mut self, key: String) -> &mut Vec<PropertyValue> {
        match self.props.entry(key) {
            Occupied(values) => values.into_mut(),
            Vacant(values) => values.set(vec![])
        }
    }

    pub fn all_values(&self, key: &String) -> &[PropertyValue] {
        static EMPTY: &'static [PropertyValue] = [];
        match self.props.find(key) {
            Some(values) => values.as_slice(),
            None => EMPTY
        }
    }
}


peg! parser(r#"
use super::{Item,PropertyValue};

#[pub]

{'fraction_non_alphanumeric': 0.15301963690255652, 'fraction_numerical': 0.0014820303816228233, 'mean_word_length': 2.4571062740076823, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 39, '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': '3663130', 'n_tokens_mistral': 896, 'n_tokens_neox': 887, 'n_words': 194}