Sort parser keywords

This commit is contained in:
Johannes Altmanninger 2024-11-17 08:45:39 +01:00
parent 774b7c7b5b
commit ab4606430e
2 changed files with 31 additions and 31 deletions

View File

@ -1255,7 +1255,7 @@ impl CheckParse for JobConjunction {
token.typ == ParseTokenType::string
&& !matches!(
token.keyword,
ParseKeyword::kw_end | ParseKeyword::kw_else | ParseKeyword::kw_case
ParseKeyword::kw_case | ParseKeyword::kw_end | ParseKeyword::kw_else
)
}
}
@ -3337,6 +3337,14 @@ impl<'s> Populator<'s> {
ParseTokenType::string => {
// There are three keywords which end a job list.
match tok.keyword {
ParseKeyword::kw_case => {
parse_error!(
self,
tok,
ParseErrorCode::unbalancing_case,
"'case' builtin not inside of switch block"
);
}
ParseKeyword::kw_end => {
parse_error!(
self,
@ -3353,14 +3361,6 @@ impl<'s> Populator<'s> {
"'else' builtin not inside of if block"
);
}
ParseKeyword::kw_case => {
parse_error!(
self,
tok,
ParseErrorCode::unbalancing_case,
"'case' builtin not inside of switch block"
);
}
_ => {
internal_error!(
self,

View File

@ -4,43 +4,43 @@ use crate::wchar::prelude::*;
const SKIP_KEYWORDS: &[&wstr] = &[L!("else"), L!("begin")];
const SUBCOMMAND_KEYWORDS: &[&wstr] = &[
L!("command"),
L!("and"),
L!("begin"),
L!("builtin"),
L!("while"),
L!("command"),
L!("exec"),
L!("if"),
L!("and"),
L!("or"),
L!("not"),
L!("or"),
L!("time"),
L!("begin"),
L!("while"),
];
const BLOCK_KEYWORDS: &[&wstr] = &[
L!("for"),
L!("while"),
L!("if"),
L!("function"),
L!("switch"),
L!("begin"),
L!("for"),
L!("function"),
L!("if"),
L!("switch"),
L!("while"),
];
// Don't forget to add any new reserved keywords to the documentation
const RESERVED_KEYWORDS: &[&wstr] = &[
L!("end"),
L!("case"),
L!("else"),
L!("return"),
L!("continue"),
L!("break"),
L!("argparse"),
L!("read"),
L!("string"),
L!("set"),
L!("status"),
L!("test"),
L!("["),
L!("_"),
L!("argparse"),
L!("break"),
L!("case"),
L!("continue"),
L!("else"),
L!("end"),
L!("eval"),
L!("read"),
L!("return"),
L!("set"),
L!("status"),
L!("string"),
L!("test"),
];
// The lists above are purposely implemented separately from the logic below, so that future