From ab4606430e55fc2d0bd3f122ecea2bad40c7d215 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 17 Nov 2024 08:45:39 +0100 Subject: [PATCH] Sort parser keywords --- src/ast.rs | 18 ++++++++--------- src/parser_keywords.rs | 44 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 04654f908..37a7324e4 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -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, diff --git a/src/parser_keywords.rs b/src/parser_keywords.rs index 287064eea..df6bfee36 100644 --- a/src/parser_keywords.rs +++ b/src/parser_keywords.rs @@ -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