2016-05-03 00:22:44 +00:00
|
|
|
// Functions having to do with parser keywords, like testing if a function is a block command.
|
2016-05-18 22:30:21 +00:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
2017-04-05 04:28:57 +00:00
|
|
|
#include <string>
|
|
|
|
|
2016-05-03 00:22:44 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "fallback.h" // IWYU pragma: keep
|
2016-05-27 21:41:16 +00:00
|
|
|
#include "parser_keywords.h"
|
2007-04-22 09:50:26 +00:00
|
|
|
|
2016-05-03 00:22:44 +00:00
|
|
|
bool parser_keywords_skip_arguments(const wcstring &cmd) {
|
2017-04-05 04:28:57 +00:00
|
|
|
return cmd == L"else" || cmd == L"begin";
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 23:57:05 +00:00
|
|
|
static const wchar_t *const subcommand_keywords[] = {L"command", L"builtin", L"while", L"exec",
|
|
|
|
L"if", L"and", L"or", L"not"};
|
2016-05-03 00:22:44 +00:00
|
|
|
bool parser_keywords_is_subcommand(const wcstring &cmd) {
|
2017-04-05 04:28:57 +00:00
|
|
|
return parser_keywords_skip_arguments(cmd) || contains(subcommand_keywords, cmd);
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 23:57:05 +00:00
|
|
|
static const wchar_t *const block_keywords[] = {L"for", L"while", L"if",
|
|
|
|
L"function", L"switch", L"begin"};
|
2017-04-05 04:28:57 +00:00
|
|
|
bool parser_keywords_is_block(const wcstring &word) { return contains(block_keywords, word); }
|
2007-04-22 09:50:26 +00:00
|
|
|
|
2018-09-30 23:57:05 +00:00
|
|
|
static const wchar_t *const reserved_keywords[] = {L"end", L"case", L"else", L"return",
|
|
|
|
L"continue", L"break", L"argparse", L"read",
|
|
|
|
L"set", L"status", L"test", L"["};
|
2016-05-03 00:22:44 +00:00
|
|
|
bool parser_keywords_is_reserved(const wcstring &word) {
|
|
|
|
return parser_keywords_is_block(word) || parser_keywords_is_subcommand(word) ||
|
2017-04-05 04:28:57 +00:00
|
|
|
contains(reserved_keywords, word);
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|