TODO: Port this (XXX: or the other way round, maybe? Import `args.rs` module to here??) to `cli-refactor` branch
Fortune for rematch's current commit: Small curse − 小凶
5 days ago
3 changed files with 195 additions and 49 deletions
/// Run an expression on an named value with a result type `Result<T, U>`.
/// Where `T` and `U` have *the same API surface* for the duration of the provided expression.
///
/// # Example
/// If there is a value `let mut value: Result<T, U>`, where `T: Write` & `U: BufWrite`;
/// the expression `value.flush()` is valid for both `T` and `U`.
/// Therefore, it can be simplified to be called as so: `unwrap_either(mut value => value.flush())`.
///
/// # Reference capture vs. `move` capture.
/// Note that by default, the identified value is **moved** *into* the expression.
/// The type of reference can be controlled by appending `ref`, `mut`, or `ref mut` to the ident.
///
/// Identifier capture table:
/// - **none** ~default~ - Capture by move, value is immutable in expression.
/// - `mut` - Capture by move, value is mutable in expression.
/// - `ref` - Capture by ref, value is immutable (`&value`) in expression.
/// - `ref mut` - Capture by mutable ref, value is mutable (`&mut value`) in expression. (__NOTE__: `value` must be defined as mutable to take a mutable reference of it.)
///
/// Essentially the same rules as any `match` branch pattern.
//TODO: What should be the behaviour of a non-existent group index here? (NOTE: This now corresponds to the previous `g.len() > group` check in caller.) // (NOTE: The original behaviour is to just ignore groups that are out of range entirely (i.e. no printing, no delimit char, no error,) maybe treat non-existent groups as non-matched groups and *just* print the delim char?)
// (NOTE: Moved out of branch, see above ^) // None if !first => write!(to, "\t"),
// XXX: Should this do what it does now...? Or should it `break` to prevent the checking for more groups...? Print a warning maybe...?
None=>{
eprintln!("Warning: Invalid group index {}!",group);
continue;// Do not set `first = false` if it was an invalid index.
//Ok(())
},
}?;
first=false;
}
// If `first == true`, no groups were printed, so we do not print the new-line.
if!first{
to.write_all(b"\n")
}else{
Ok(())
}
}
fnmain()-> eyre::Result<()>
{
initialise().wrap_err("Fatal: Failed to install panic handle")?;
println!("Pass `-' as `<str>' to read lines from stdin");
std::process::exit(1);
println!("");
println!("Enabled Features:");
ifcfg!(feature="perl"){
println!("+perl\t\t\tEnable PCRE2 (extended) regular-expressions.\n\t\t\tNote that PCRE2 regex engine matches on *bytes*, not *characters*; meaning if a match cuts a vlid UTF8 codepoint into an invalid one, the output will replace the invalid characters with U+FFFD REPLACEMENT CHARACTER.");
}else{
println!("-perl\t\tPCRE2 (extended) features are disabled; a faster but less featureful regular expression engine (that matches on UTF8 strings instead of raw bytes) is used instead.");
}
ifcfg!(feature="unstable"){
println!("+unstable\t\tUnstable optimisations evailable & enabled for build.");
}else{
println!("-unstable\t\tUnstable optimisations disabled / not available for build.");
}
std::process::exit(1)
}else{
letre=re::Regex::compile(&args[2])?;
lettext=&args[1];
letgroup: usize=args[3].parse().expect("Invalid group number.");