Compare commits
2 Commits
a09abf40d8
...
96f5213264
Author | SHA1 | Date | |
---|---|---|---|
96f5213264 | |||
1049f9bcf6 |
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -309,9 +309,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.10"
|
version = "0.5.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1"
|
checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
@ -367,9 +367,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.14.0"
|
version = "1.15.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
|
checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
|
40
src/diff.rs
40
src/diff.rs
@ -1,31 +1,33 @@
|
|||||||
|
use color_print::cformat;
|
||||||
|
|
||||||
pub struct Compare {
|
pub struct Compare {
|
||||||
pub right: String,
|
pub right: String,
|
||||||
pub left: String,
|
pub left: String,
|
||||||
pub eval: String
|
|
||||||
}
|
}
|
||||||
type Compared = Compare;
|
pub struct Compared {
|
||||||
|
pub right: String,
|
||||||
|
pub left: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Comparer {
|
pub struct Comparer {
|
||||||
formatted_right: Vec<String>,
|
formatted_right: String,
|
||||||
formatted_left: Vec<String>,
|
formatted_left: String
|
||||||
formatted_eval: Vec<String>
|
|
||||||
}
|
}
|
||||||
impl Comparer {
|
impl Comparer {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
formatted_right: Vec::new(),
|
formatted_right: String::new(),
|
||||||
formatted_left: Vec::new(),
|
formatted_left: String::new(),
|
||||||
formatted_eval: Vec::new(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_compare(&mut self, left_char: char, right_char: char) {
|
fn format_compare(&mut self, left_char: char, right_char: char) {
|
||||||
if left_char == right_char {
|
if left_char == right_char {
|
||||||
self.formatted_left.push(left_char.to_string());
|
self.formatted_left.push(left_char);
|
||||||
self.formatted_right.push(right_char.to_string());
|
self.formatted_right.push(right_char);
|
||||||
} else {
|
} else {
|
||||||
self.formatted_left.push(color_print::cformat!("<r>{left_char}</>"));
|
self.formatted_left.push_str(&cformat!("<r>{left_char}</>"));
|
||||||
self.formatted_right.push(color_print::cformat!("<r>{right_char}</>"));
|
self.formatted_right.push_str(&cformat!("<r>{right_char}</>"));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,18 +37,12 @@ impl Comparer {
|
|||||||
for (i, left_char) in compare.left.chars().enumerate() {
|
for (i, left_char) in compare.left.chars().enumerate() {
|
||||||
match right_chars.get(i) {
|
match right_chars.get(i) {
|
||||||
Some(right_char) => self.format_compare(left_char, *right_char),
|
Some(right_char) => self.format_compare(left_char, *right_char),
|
||||||
None => {
|
None => break,
|
||||||
compare.eval.chars().for_each(|char| {
|
|
||||||
// self.formatted_eval
|
|
||||||
});
|
|
||||||
break
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Compared {
|
Compared {
|
||||||
right: self.formatted_right.concat(),
|
right: self.formatted_right.clone(),
|
||||||
left: self.formatted_left.concat(),
|
left: self.formatted_left.clone()
|
||||||
eval: self.formatted_eval.concat()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub enum EvalError {
|
pub enum EvalError {
|
||||||
LeftMissing,
|
LeftMissing,
|
||||||
RightMissing,
|
RightMissing,
|
||||||
@ -44,4 +45,4 @@ pub fn eval(expression: Vec<&str>) -> Result<EvalResult, EvalError> {
|
|||||||
"^" | "xor" => Ok(wrap_result(left ^ right)),
|
"^" | "xor" => Ok(wrap_result(left ^ right)),
|
||||||
str => Err(EvalError::InvalidOperator(str.to_owned()))
|
str => Err(EvalError::InvalidOperator(str.to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
src/input.rs
28
src/input.rs
@ -29,26 +29,34 @@ impl Out {
|
|||||||
match eval_error {
|
match eval_error {
|
||||||
EvalError::I64Conversion(parse_int_error) => println!("{parse_int_error}"),
|
EvalError::I64Conversion(parse_int_error) => println!("{parse_int_error}"),
|
||||||
EvalError::InvalidOperator(invalid_op) => println!("The operator {:?} is invalid.", invalid_op),
|
EvalError::InvalidOperator(invalid_op) => println!("The operator {:?} is invalid.", invalid_op),
|
||||||
|
EvalError::LeftMissing => println!("Left side expression missing."),
|
||||||
|
EvalError::RightMissing => println!("Right side expression missing."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn padded(&self, diffed_left: &str, diffed_right: &str, diffed_eval: String) -> String {
|
||||||
|
let diffed_eval_chars = diffed_eval.chars().count();
|
||||||
|
let mut char_counts = [diffed_left.chars().count(), diffed_right.chars().count(), diffed_eval_chars];
|
||||||
|
char_counts.sort();
|
||||||
|
let subtracted_count = char_counts.last().map_or(0, |biggest_len| {
|
||||||
|
*biggest_len-diffed_eval_chars
|
||||||
|
});
|
||||||
|
format!("{}{diffed_eval}", "0".repeat(subtracted_count))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn evaled(&self, eval_out: Result<EvalResult, EvalError>) {
|
pub fn evaled(&self, eval_out: Result<EvalResult, EvalError>) {
|
||||||
eval_out.map_or_else(|e| self.error(e), |result| {
|
eval_out.map_or_else(|e| self.error(e), |result| {
|
||||||
let eval_base2 = base::binary(result.eval);
|
|
||||||
let left = base::binary(result.input.left);
|
|
||||||
let right = base::binary(result.input.right);
|
|
||||||
|
|
||||||
let mut differ = diff::Comparer::new();
|
let mut differ = diff::Comparer::new();
|
||||||
let diffed = differ.compare(Compare {
|
let diffed = differ.compare(Compare {
|
||||||
right: right.clone(),
|
right: base::binary(result.input.right),
|
||||||
left: left.clone(),
|
left: base::binary(result.input.left),
|
||||||
eval: eval_base2.clone(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let padded_eval = self.padded(&diffed.left, &diffed.right, base::binary(result.eval));
|
||||||
println!("{}", diffed.left);
|
println!("{}", diffed.left);
|
||||||
println!("{}", diffed.right);
|
println!("{}", diffed.right);
|
||||||
println!("{}", "-".repeat(eval_base2.chars().count()));
|
println!("{}", "-".repeat(padded_eval.chars().count()));
|
||||||
println!("{}", diffed.eval)
|
println!("{}", padded_eval)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,4 +96,4 @@ impl Bitfyre {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user