flow control keywords are now highlighted purple
This commit is contained in:
@@ -32,13 +32,13 @@ pub fn flowctl(node: Node, kind: ShErrKind) -> ShResult<()> {
|
|||||||
code = status;
|
code = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
let kind = match kind {
|
let (kind,message) = match kind {
|
||||||
LoopContinue(_) => LoopContinue(code),
|
LoopContinue(_) => (LoopContinue(code), "'continue' found outside of loop"),
|
||||||
LoopBreak(_) => LoopBreak(code),
|
LoopBreak(_) => (LoopBreak(code), "'break' found outside of loop"),
|
||||||
FuncReturn(_) => FuncReturn(code),
|
FuncReturn(_) => (FuncReturn(code), "'return' found outside of function"),
|
||||||
CleanExit(_) => CleanExit(code),
|
CleanExit(_) => (CleanExit(code), ""),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Err(ShErr::simple(kind, ""))
|
Err(ShErr::simple(kind, message))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -432,9 +432,9 @@ impl Display for ShErrKind {
|
|||||||
Self::FileNotFound(file) => &format!("File not found: {file}"),
|
Self::FileNotFound(file) => &format!("File not found: {file}"),
|
||||||
Self::CmdNotFound(cmd) => &format!("Command not found: {cmd}"),
|
Self::CmdNotFound(cmd) => &format!("Command not found: {cmd}"),
|
||||||
Self::CleanExit(_) => "",
|
Self::CleanExit(_) => "",
|
||||||
Self::FuncReturn(_) => "",
|
Self::FuncReturn(_) => "Syntax Error",
|
||||||
Self::LoopContinue(_) => "",
|
Self::LoopContinue(_) => "Syntax Error",
|
||||||
Self::LoopBreak(_) => "",
|
Self::LoopBreak(_) => "Syntax Error",
|
||||||
Self::ReadlineIntr(_) => "",
|
Self::ReadlineIntr(_) => "",
|
||||||
Self::ReadlineErr => "Readline Error",
|
Self::ReadlineErr => "Readline Error",
|
||||||
Self::ClearReadline => "",
|
Self::ClearReadline => "",
|
||||||
|
|||||||
@@ -89,7 +89,23 @@ impl Highlighter {
|
|||||||
markers::STRING_DQ | markers::STRING_SQ | markers::KEYWORD => {
|
markers::STRING_DQ | markers::STRING_SQ | markers::KEYWORD => {
|
||||||
self.push_style(Style::Yellow)
|
self.push_style(Style::Yellow)
|
||||||
}
|
}
|
||||||
markers::BUILTIN => self.push_style(Style::Green),
|
markers::BUILTIN => {
|
||||||
|
let mut cmd_name = String::new();
|
||||||
|
let mut chars_clone = input_chars.clone();
|
||||||
|
while let Some(ch) = chars_clone.next() {
|
||||||
|
if ch == markers::RESET {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if !is_marker(ch) {
|
||||||
|
cmd_name.push(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match cmd_name.as_str() {
|
||||||
|
"continue" | "return" | "break" => self.push_style(Style::Magenta),
|
||||||
|
_ => self.push_style(Style::Green),
|
||||||
|
}
|
||||||
|
}
|
||||||
markers::CASE_PAT => self.push_style(Style::Blue),
|
markers::CASE_PAT => self.push_style(Style::Blue),
|
||||||
|
|
||||||
markers::COMMENT => self.push_style(Style::BrightBlack),
|
markers::COMMENT => self.push_style(Style::BrightBlack),
|
||||||
@@ -157,7 +173,10 @@ impl Highlighter {
|
|||||||
}
|
}
|
||||||
cmd_name.push(ch);
|
cmd_name.push(ch);
|
||||||
}
|
}
|
||||||
let style = if Self::is_valid(&Self::strip_markers(&cmd_name)) {
|
log::debug!("Command name: '{}'", Self::strip_markers(&cmd_name));
|
||||||
|
let style = if matches!(Self::strip_markers(&cmd_name).as_str(), "break" | "continue" | "return") {
|
||||||
|
Style::Magenta.into()
|
||||||
|
} else if Self::is_valid(&Self::strip_markers(&cmd_name)) {
|
||||||
Style::Green.into()
|
Style::Green.into()
|
||||||
} else {
|
} else {
|
||||||
Style::Red | Style::Bold
|
Style::Red | Style::Bold
|
||||||
|
|||||||
Reference in New Issue
Block a user