fn main() {
while let Some(Ok(line)) = std::io::stdin().lines().next() {
let formatted = format_line(line);
println!("{}", formatted);
}
}
fn format_line(line: String) -> String {
let line = line.trim().to_string();
if line.is_empty() {
return line;
}
let mut comment = String::new();
let mut code_part = line;
if let Some(comment_start) = code_part.find(';') {
comment = code_part[comment_start..].trim().to_string();
code_part = code_part[..comment_start].trim_end().to_string();
}
let mut parts = code_part.split_whitespace().collect::<Vec<&str>>();
let mut label = None;
if let Some(first_part) = parts.first() {
if first_part.ends_with(':') {
label = Some(first_part.to_string());
parts.remove(0);
}
}
let mut formatted_line = String::new();
if let Some(lbl) = label {
formatted_line.push_str(&lbl);
}
formatted_line.push('\t');
if !parts.is_empty() {
formatted_line.push_str(parts[0]);
formatted_line.push('\t');
if parts.len() > 1 {
formatted_line.push_str(&parts[1..].join(" "));
}
}
if !comment.is_empty() {
formatted_line.push('\t');
formatted_line.push_str(&comment);
}
formatted_line
}