Code Cleanup for my preferred format
This commit is contained in:
parent
a8539d0030
commit
bf5f448897
3 changed files with 23 additions and 11 deletions
1
.rustfmt.toml
Normal file
1
.rustfmt.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
disable_all_formatting = true
|
||||
15
src/main.rs
15
src/main.rs
|
|
@ -149,7 +149,8 @@ fn gen_match(
|
|||
let shots = home_score.max(rng.gen_range(4..=18u8));
|
||||
let on_target = home_score.max(rng.gen_range(1..=shots.min(10)));
|
||||
(shots, on_target)
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
let shots = rng.gen_range(4..=18u8);
|
||||
let on_target = rng.gen_range(1..=shots.min(10));
|
||||
(shots, on_target)
|
||||
|
|
@ -159,7 +160,8 @@ fn gen_match(
|
|||
let shots = away_score.max(rng.gen_range(4..=18u8));
|
||||
let on_target = away_score.max(rng.gen_range(1..=shots.min(10)));
|
||||
(shots, on_target)
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
let shots = rng.gen_range(4..=18u8);
|
||||
let on_target = rng.gen_range(1..=shots.min(10));
|
||||
(shots, on_target)
|
||||
|
|
@ -212,7 +214,8 @@ fn print_table(m: &Match) {
|
|||
lines.push("Goals:".to_string());
|
||||
if m.home.scorers.is_empty() && m.away.scorers.is_empty() {
|
||||
lines.push("No goals scored.".to_string());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (name, min) in &m.home.scorers {
|
||||
lines.push(format!("{home}: {name} ({min}')"));
|
||||
}
|
||||
|
|
@ -314,7 +317,8 @@ fn main() {
|
|||
process::exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
args.iter()
|
||||
.skip(1)
|
||||
.find(|a| !a.starts_with("--") && Path::new(a).is_file())
|
||||
|
|
@ -331,7 +335,8 @@ fn main() {
|
|||
|
||||
if json_mode {
|
||||
print_json(&m);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
print_table(&m);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
src/tsrc.rs
18
src/tsrc.rs
|
|
@ -42,16 +42,20 @@ pub fn parse_tsrc(path: &str) -> Result<TsrcScript, String> {
|
|||
|
||||
if let Some(rest) = line.strip_prefix("string ") {
|
||||
parse_string_decl(rest, n, &mut teams, &mut var_lines)?;
|
||||
} else if let Some(rest) = line.strip_prefix("players") {
|
||||
}
|
||||
else if let Some(rest) = line.strip_prefix("players") {
|
||||
parse_player_insert(rest, n, &mut roster, &mut player_entries, &teams)?;
|
||||
} else if let Some(rest) = line.strip_prefix("goal") {
|
||||
}
|
||||
else if let Some(rest) = line.strip_prefix("goal") {
|
||||
let goal = parse_goal(rest, n, &teams, &roster, &mut goal_entries)?;
|
||||
goals.push(goal);
|
||||
} else if let Some(rest) = line.strip_prefix("match") {
|
||||
}
|
||||
else if let Some(rest) = line.strip_prefix("match") {
|
||||
let rest = rest.trim_end_matches(';');
|
||||
(home_var, away_var) = parse_match(rest, n, &teams)?;
|
||||
match_found = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return Err(format!("tsrc error: unrecognized statement on line {}: '{}'", n, line));
|
||||
}
|
||||
}
|
||||
|
|
@ -172,7 +176,8 @@ fn parse_player_insert(
|
|||
|
||||
let team_name = if value_part.starts_with('"') {
|
||||
parse_string_literal(value_part, n)?
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
let var_name = value_part.trim();
|
||||
if !is_valid_ident(var_name) {
|
||||
return Err(format!(
|
||||
|
|
@ -269,7 +274,8 @@ fn parse_goal(
|
|||
let team_part = parts[1].trim();
|
||||
let team_name = if team_part.starts_with('"') {
|
||||
parse_string_literal(team_part, n)?
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if !is_valid_ident(team_part) {
|
||||
return Err(format!(
|
||||
"tsrc error: goal() team must be a string literal or variable on line {}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue