<commit_before>use nom::{
  be_u8, be_u16, be_u32,
  IResult,
  ErrorKind,
};

use attribute_info::*;
use attribute_info::types::StackMapFrame::*;

pub fn attribute_parser(input: &[u8]) -> IResult<&[u8], AttributeInfo> {
    do_parse!(input,
        attribute_name_index: be_u16 >>
        attribute_length: be_u32 >>
        info: take!(attribute_length)>>
        (AttributeInfo {
            attribute_name_index: attribute_name_index,
            attribute_length: attribute_length,
            info: info.to_owned(),
        })
    )
}

pub fn exception_entry_parser(input: &[u8]) -> IResult<&[u8], ExceptionEntry> {
    do_parse!(input,
        start_pc: be_u16 >>
        end_pc: be_u16 >>
        handler_pc: be_u16 >>
        catch_type: be_u16>>
        (ExceptionEntry {
            start_pc: start_pc,
            end_pc: end_pc,
            handler_pc: handler_pc,
            catch_type: catch_type,
        })
    )
}

pub fn code_attribute_parser(input: &[u8]) -> IResult<&[u8], CodeAttribute> {
    do_parse!(input,
        max_stack: be_u16 >>
        max_locals: be_u16 >>
        code_length: be_u32 >>
        code: take!(code_length) >>
        exception_table_length: be_u16 >>
        exception_table: count!(exception_entry_parser, exception_table_length as usize) >>
        attributes_count: be_u16 >>
        attributes: count!(attribute_parser, attributes_count as usize) >>
        (CodeAttribute {
            max_stack: max_stack,
            max_locals: max_locals,
            code_length: code_length,
            code: code.to_owned(),
            exception_table_length: exception_table_length,
            exception_table: exception_table,
            attributes_count: attributes_count,
            attributes: attributes,
        })
    )
}

fn same_frame_parser(input: &[u8], frame_type: u8) -> IResult<&[u8], StackMapFrame> {
    value!(input, SameFrame { frame_type })
}

fn verification_type(v: &u8) -> Option<VerificationTypeInfo> {
    use self::VerificationTypeInfo::*;
    match *v {
        0 => Some(Top),
        1 => Some(Integer),
        2 => Some(Float),
        3 => Some(Double),
        4 => Some(Long),
        5 => Some(Null),
        6 => Some(UninitializedThis),
        7 => Some(Object),
        8 => Some(Uninitialized),
        _ => None,
    }
}

fn verification_type_parser(input: &[u8]) -> IResult<&[u8], VerificationTypeInfo> {
    do_parse!(input,
        v: be_u8 >>
        (verification_type(&v).unwrap()) // TODO rewrite .unwrap() call
    )
}<commit_msg>Get rid of .unwrap() call<commit_after>use nom::{
  be_u8, be_u16, be_u32,
  IResult,
  ErrorKind,
};

use attribute_info::*;
use attribute_info::types::StackMapFrame::*;

pub fn attribute_parser(input: &[u8]) -> IResult<&[u8], AttributeInfo> {
    do_parse!(input,
        attribute_name_index: be_u16 >>
        attribute_length: be_u32 >>
        info: take!(attribute_length)>>
        (AttributeInfo {
            attribute_name_index: attribute_name_index,
            attribute_length: attribute_length,
            info: info.to_owned(),
        })
    )
}

pub fn exception_entry_parser(input: &[u8]) -> IResult<&[u8], ExceptionEntry> {
    do_parse!(input,
        start_pc: be_u16 >>
        end_pc: be_u16 >>
        handler_pc: be_u16 >>
        catch_type: be_u16>>
        (ExceptionEntry {
            start_pc: start_pc,
            end_pc: end_pc,
            handler_pc: handler_pc,
            catch_type: catch_type,
        })
    )
}

pub fn code_attribute_parser(input: &[u8]) -> IResult<&[u8], CodeAttribute> {
    do_parse!(input,
        max_stack: be_u16 >>
        max_locals: be_u16 >>
        code_length: be_u32 >>
        code: take!(code_length) >>
        exception_table_length: be_u16 >>
        exception_table: count!(exception_entry_parser, exception_table_length as usize) >>
        attributes_count: be_u16 >>
        attributes: count!(attribute_parser, attributes_count as usize) >>
        (CodeAttribute {
            max_stack: max_stack,
            max_locals: max_locals,
            code_length: code_length,
            code: code.to_owned(),
            exception_table_length: exception_table_length,
            exception_table: exception_table,
            attributes_count: attributes_count,
            attributes: attributes,
        })
    )
}

fn same_frame_parser(input: &[u8], frame_type: u8) -> IResult<&[u8], StackMapFrame> {
    value!(input, SameFrame { frame_type })
}

fn verification_type(v: &u8) -> Option<VerificationTypeInfo> {
    use self::VerificationTypeInfo::*;
    match *v {
        0 => Some(Top),
        1 => Some(Integer),
        2 => Some(Float),
        3 => Some(Double),
        4 => Some(Long),
        5 => Some(Null),
        6 => Some(UninitializedThis),
        7 => Some(Object),
        8 => Some(Uninitialized),
        _ => None,
    }
}

fn verification_type_parser(input: &[u8]) -> IResult<&[u8], VerificationTypeInfo> {
    match verification_type(&input[0]) {
        Some(x) => IResult::Done(&input[1..], x),
        _ => IResult::Error(error_position!(ErrorKind::Alt, input)),
    }
}
{'fraction_non_alphanumeric': 0.12815002930259817, 'fraction_numerical': 0.01933971478804454, 'mean_word_length': 2.514070006863418, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 111, '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': '1049987', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1649, 'n_words': 305}