pub fn parse_directive_str(directive_str: &str) -> Result<BonesDirective, String> {
    let directive_json: String;
    // Check if we have the alternative super-simple form (just one command, rare but easy to parse)
    if !directive_str.contains('{') {
        directive_json = "[\"".to_string() + directive_str + "\", {}]"
    } else {
        // We transform the directive string into compliant JSON with a series of substitutions
        // Execute non-regex substitutions
        let stage1 = directive_str.replace("}", "}]");
        // We can unwrap all the RegExps because we know they're valid
        // Please refer to the Bones specification to understand how these work
        let re1 = Regex::new(r"(?m)^(\s*)(.+) => (.+)\b \{").unwrap();
        let sub1 = "$1\"$2\": [\"$3\", {";
        let re2 = Regex::new(r"(?m)^(\s*)(.+) => (.+)\b").unwrap();
        let sub2 = "$1\"$2\": [\"$3\", {}]";
        let re3 = Regex::new(r"^\s*\b(.+) \{").unwrap();
        let sub3 = "[\"$1\", {";
        // Execute each of those substitutions
        let stage2 = re1.replace_all(&stage1, sub1);
        let stage3 = re2.replace_all(&stage2, sub2);
        directive_json = re3.replace_all(&stage3, sub3).to_string();
    }
    // Now we can deserialize that directly using Serde
    let raw_directive = serde_json::from_str::<RawBonesDirective>(&directive_json);
    let raw_directive = match raw_directive {
        Ok(raw_directive) => raw_directive,
        Err(err) => return Err(format!("The following error occurred while parsing a Bones directive: '{}'. Please note that your code is transformed in several ways before this step, so you may need to refer to the documentation on Bones directives.", err))
    };
    // Now we handle the operators
    let directive = raw_directive.convert_to_proper()?;

    Ok(directive)
}
// This parses a directive string into a `BonesDirective` that can be executed
// The logic of parsing and executing is made separate so we can cache the parsed form for large configuration files
// This function basically interprets a miniature programming language
// Right now, this is quite slow due to its extensive use of RegEx, any ideas to speed it up would be greatly appreciated!
This parses a directive string into a `BonesDirective` that can be executed
The logic of parsing and executing is made separate so we can cache the parsed form for large configuration files
This function basically interprets a miniature programming language
Right now, this is quite slow due to its extensive use of RegEx, any ideas to speed it up would be greatly appreciated!
This parses a directive string into a ` BonesDirective ` that can be executed The logic of parsing and executing is made separate so we can cache the parsed form for large configuration files This function basically interprets a miniature programming language Right now this is quite slow due to its extensive use of RegEx any ideas to speed it up would be greatly appreciated!
pub fn parse_directive_str(directive_str: &str) -> Result<BonesDirective, String> {
    let directive_json: String;
    // Check if we have the alternative super-simple form (just one command, rare but easy to parse)
    if !directive_str.contains('{') {
        directive_json = "[\"".to_string() + directive_str + "\", {}]"
    } else {
        // We transform the directive string into compliant JSON with a series of substitutions
        // Execute non-regex substitutions
        let stage1 = directive_str.replace("}", "}]");
        // We can unwrap all the RegExps because we know they're valid
        // Please refer to the Bones specification to understand how these work
        let re1 = Regex::new(r"(?m)^(\s*)(.+) => (.+)\b \{").unwrap();
        let sub1 = "$1\"$2\": [\"$3\", {";
        let re2 = Regex::new(r"(?m)^(\s*)(.+) => (.+)\b").unwrap();
        let sub2 = "$1\"$2\": [\"$3\", {}]";
        let re3 = Regex::new(r"^\s*\b(.+) \{").unwrap();
        let sub3 = "[\"$1\", {";
        // Execute each of those substitutions
        let stage2 = re1.replace_all(&stage1, sub1);
        let stage3 = re2.replace_all(&stage2, sub2);
        directive_json = re3.replace_all(&stage3, sub3).to_string();
    }
    // Now we can deserialize that directly using Serde
    let raw_directive = serde_json::from_str::<RawBonesDirective>(&directive_json);
    let raw_directive = match raw_directive {
        Ok(raw_directive) => raw_directive,
        Err(err) => return Err(format!("The following error occurred while parsing a Bones directive: '{}'. Please note that your code is transformed in several ways before this step, so you may need to refer to the documentation on Bones directives.", err))
    };
    // Now we handle the operators
    let directive = raw_directive.convert_to_proper()?;
    Ok(directive)
}
pub fn parse_directive_str ( directive_str : & str ) -> Result < BonesDirective , String > { let directive_json : String ; // Check if we have the alternative super-simple form (just one command, rare but easy to parse) if ! directive_str . contains ( '{' ) { directive_json = " \" " . to_string ( ) + directive_str + " \" " } else { // We transform the directive string into compliant JSON with a series of substitutions // Execute non-regex substitutions let stage1 = directive_str . replace ( " " , " " ) ; // We can unwrap all the RegExps because we know they're valid // Please refer to the Bones specification to understand how these work let re1 = Regex :: new ( r"(?m)^(\s*)(.+) => (.+)\b \{" ) . unwrap ( ) ; let sub1 = " \" \" \" \" " ; let re2 = Regex :: new ( r"(?m)^(\s*)(.+) => (.+)\b" ) . unwrap ( ) ; let sub2 = " \" \" \" \" " ; let re3 = Regex :: new ( r"^\s*\b(.+) \{" ) . unwrap ( ) ; let sub3 = " \" \" " ; // Execute each of those substitutions let stage2 = re1 . replace_all ( & stage1 , sub1 ) ; let stage3 = re2 . replace_all ( & stage2 , sub2 ) ; directive_json = re3 . replace_all ( & stage3 , sub3 ) . to_string ( ) ; } // Now we can deserialize that directly using Serde let raw_directive = serde_json :: from_str :: < RawBonesDirective > ( & directive_json ) ; let raw_directive = match raw_directive { Ok ( raw_directive ) => raw_directive , Err ( err ) => return Err ( format ! ( " " err ) ) } ; // Now we handle the operators let directive = raw_directive . convert_to_proper ( ) ? ; Ok ( directive ) }
This parses a directive string into a `BonesDirective` that can be executed
The logic of parsing and executing is made separate so we can cache the parsed form for large configuration files
This function basically interprets a miniature programming language
Right now, this is quite slow due to its extensive use of RegEx, any ideas to speed it up would be greatly appreciated!
This parses a directive string into a ` BonesDirective ` that can be executed The logic of parsing and executing is made separate so we can cache the parsed form for large configuration files This function basically interprets a miniature programming language Right now this is quite slow due to its extensive use of RegEx any ideas to speed it up would be greatly appreciated!
directive_str
&str