pub fn parse_edit_script(script: &str) -> Result<(&str, Edit), Box<dyn Error>> {
        // parse out the line numbers from the original file
        let (r, og_line_start) = parser::read_usize(script)?;
        let r = parser::skip_sequence(r, ",")?;
        let (r, og_line_end) = parser::read_usize(r)?;

        // parse out the edit's operation
        let (r, op) = match r.chars().next().ok_or("No operation")? {
            'r' => Ok((&r[1..], Operation::Replace)),
            'a' => Ok((&r[1..], Operation::Insert)),
            'd' => Ok((&r[1..], Operation::Delete)),
            _ => Err("Invalid Operation"),
        }?;

        // parse out the line number from the modified file
        let (r, mod_line_start) = parser::read_usize(r)?;
        let r = parser::skip_sequence(r, ",")?;
        let (r, mod_line_end) = parser::read_usize(r)?;

        // parse out the content for each half of the edit
        let r = parser::skip_sequence(r, "\n")?;
        let (r, og_content_ref) = parser::read_lines(r, og_line_end - og_line_start + 1)?;
        let r = parser::skip_sequence(r, "---\n")?;
        let (r, mod_content_ref) = parser::read_lines(r, mod_line_end - mod_line_start + 1)?;

        // I couldn't find a better way to make a Vec<&str> -> Vec<String> while also stripping the '> '/'< ',
        // so here we are
        let mut og_content = Vec::with_capacity(og_content_ref.len());
        for line in og_content_ref {
            og_content.push(
                line.strip_prefix("< ")
                    .ok_or("Content formatted incorrectly")?
                    .to_string(),
            );
        }

        let mut mod_content = Vec::with_capacity(mod_content_ref.len());
        for line in mod_content_ref {
            mod_content.push(
                line.strip_prefix("> ")
                    .ok_or("Content formatted incorrectly")?
                    .to_string(),
            );
        }

        let edit = Edit {
            op,
            original: HalfEdit {
                line: og_line_start,
                content: og_content,
            },
            modified: HalfEdit {
                line: mod_line_start,
                content: mod_content,
            },
        };

        Ok((r, edit))
    }
/// Parse an edit script into an Edit
/// Takes an entire edit script as input, and if sucessful returns the remaining portion of
/// the edit script along with the serialized edit
Parse an edit script into an Edit
Takes an entire edit script as input, and if sucessful returns the remaining portion of
the edit script along with the serialized edit
Parse an edit script into an Edit Takes an entire edit script as input and if sucessful returns the remaining portion of the edit script along with the serialized edit
pub fn parse_edit_script(script: &str) -> Result<(&str, Edit), Box<dyn Error>> {
        // parse out the line numbers from the original file
        let (r, og_line_start) = parser::read_usize(script)?;
        let r = parser::skip_sequence(r, ",")?;
        let (r, og_line_end) = parser::read_usize(r)?;
        // parse out the edit's operation
        let (r, op) = match r.chars().next().ok_or("No operation")? {
            'r' => Ok((&r[1..], Operation::Replace)),
            'a' => Ok((&r[1..], Operation::Insert)),
            'd' => Ok((&r[1..], Operation::Delete)),
            _ => Err("Invalid Operation"),
        }?;
        // parse out the line number from the modified file
        let (r, mod_line_start) = parser::read_usize(r)?;
        let r = parser::skip_sequence(r, ",")?;
        let (r, mod_line_end) = parser::read_usize(r)?;
        // parse out the content for each half of the edit
        let r = parser::skip_sequence(r, "\n")?;
        let (r, og_content_ref) = parser::read_lines(r, og_line_end - og_line_start + 1)?;
        let r = parser::skip_sequence(r, "---\n")?;
        let (r, mod_content_ref) = parser::read_lines(r, mod_line_end - mod_line_start + 1)?;
        // I couldn't find a better way to make a Vec<&str> -> Vec<String> while also stripping the '> '/'< ',
        // so here we are
        let mut og_content = Vec::with_capacity(og_content_ref.len());
        for line in og_content_ref {
            og_content.push(
                line.strip_prefix("< ")
                    .ok_or("Content formatted incorrectly")?
                    .to_string(),
            );
        }
        let mut mod_content = Vec::with_capacity(mod_content_ref.len());
        for line in mod_content_ref {
            mod_content.push(
                line.strip_prefix("> ")
                    .ok_or("Content formatted incorrectly")?
                    .to_string(),
            );
        }
        let edit = Edit {
            op,
            original: HalfEdit {
                line: og_line_start,
                content: og_content,
            },
            modified: HalfEdit {
                line: mod_line_start,
                content: mod_content,
            },
        };
        Ok((r, edit))
    }
pub fn parse_edit_script ( script : & str ) -> Result < ( & str , Edit ) , Box < dyn Error > > { // parse out the line numbers from the original file let ( r , og_line_start ) = parser :: read_usize ( script ) ? ; let r = parser :: skip_sequence ( r , " " ) ? ; let ( r , og_line_end ) = parser :: read_usize ( r ) ? ; // parse out the edit's operation let ( r , op ) = match r . chars ( ) . next ( ) . ok_or ( " " ) ? { 'r' => Ok ( ( & r [ 1 .. ] , Operation :: Replace ) ) , 'a' => Ok ( ( & r [ 1 .. ] , Operation :: Insert ) ) , 'd' => Ok ( ( & r [ 1 .. ] , Operation :: Delete ) ) , _ => Err ( " " ) , } ? ; // parse out the line number from the modified file let ( r , mod_line_start ) = parser :: read_usize ( r ) ? ; let r = parser :: skip_sequence ( r , " " ) ? ; let ( r , mod_line_end ) = parser :: read_usize ( r ) ? ; // parse out the content for each half of the edit let r = parser :: skip_sequence ( r , " \n " ) ? ; let ( r , og_content_ref ) = parser :: read_lines ( r , og_line_end - og_line_start + 1 ) ? ; let r = parser :: skip_sequence ( r , " \n " ) ? ; let ( r , mod_content_ref ) = parser :: read_lines ( r , mod_line_end - mod_line_start + 1 ) ? ; // I couldn't find a better way to make a Vec<&str> -> Vec<String> while also stripping the '> '/'< ', // so here we are let mut og_content = Vec :: with_capacity ( og_content_ref . len ( ) ) ; for line in og_content_ref { og_content . push ( line . strip_prefix ( " " ) . ok_or ( " " ) ? . to_string ( ) , ) ; } let mut mod_content = Vec :: with_capacity ( mod_content_ref . len ( ) ) ; for line in mod_content_ref { mod_content . push ( line . strip_prefix ( " " ) . ok_or ( " " ) ? . to_string ( ) , ) ; } let edit = Edit { op , original : HalfEdit { line : og_line_start , content : og_content , } , modified : HalfEdit { line : mod_line_start , content : mod_content , } , } ; Ok ( ( r , edit ) ) }
Parse an edit script into an Edit
Takes an entire edit script as input, and if sucessful returns the remaining portion of
the edit script along with the serialized edit
Parse an edit script into an Edit Takes an entire edit script as input and if sucessful returns the remaining portion of the edit script along with the serialized edit
script
&str
script
&str