Add token-aware depth calculator for indentation, improve brace group error handling, and clean up warnings

This commit is contained in:
2026-03-13 20:57:04 -04:00
parent 307386ffc6
commit 09024728f6
7 changed files with 129 additions and 73 deletions

View File

@@ -803,7 +803,7 @@ impl Dispatcher {
self.job_stack.new_job();
if cmds.len() == 1 {
self.fg_job = !is_bg && self.interactive;
let mut cmd = cmds.into_iter().next().unwrap();
let cmd = cmds.into_iter().next().unwrap();
if is_bg && !matches!(cmd.class, NdRule::Command { .. }) {
self.run_fork(
&cmd.get_command().map(|t| t.to_string()).unwrap_or_default(),

View File

@@ -217,6 +217,32 @@ impl Tk {
};
self.span.as_str().trim() == ";;"
}
pub fn is_opener(&self) -> bool {
OPENERS.contains(&self.as_str()) ||
matches!(self.class, TkRule::BraceGrpStart) ||
matches!(self.class, TkRule::CasePattern)
}
pub fn is_closer(&self) -> bool {
matches!(self.as_str(), "fi" | "done" | "esac") ||
self.has_double_semi() ||
matches!(self.class, TkRule::BraceGrpEnd)
}
pub fn is_closer_for(&self, other: &Tk) -> bool {
if (matches!(other.class, TkRule::BraceGrpStart) && matches!(self.class, TkRule::BraceGrpEnd))
|| (matches!(other.class, TkRule::CasePattern) && self.has_double_semi()) {
return true;
}
match other.as_str() {
"for" |
"while" |
"until" => matches!(self.as_str(), "done"),
"if" => matches!(self.as_str(), "fi"),
"case" => matches!(self.as_str(), "esac"),
_ => false
}
}
}
impl Display for Tk {

File diff suppressed because one or more lines are too long