mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-25 08:03:26 +08:00

`argparse`, `read`, `set`, `status`, `test` and `[` now can't be used as function names anymore. This is because (except for `test` and `[`) there is no way to wrap these properly, so any function called that will be broken anyway. For `test` (and `[`), there is nothing that can be added and there have been confused users who created a function that then broke everything. Fixes #3000.
30 lines
1.3 KiB
C++
30 lines
1.3 KiB
C++
// Functions having to do with parser keywords, like testing if a function is a block command.
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
#include <string>
|
|
|
|
#include "common.h"
|
|
#include "fallback.h" // IWYU pragma: keep
|
|
#include "parser_keywords.h"
|
|
|
|
bool parser_keywords_skip_arguments(const wcstring &cmd) {
|
|
return cmd == L"else" || cmd == L"begin";
|
|
}
|
|
|
|
static const wcstring_list_t subcommand_keywords({L"command", L"builtin", L"while", L"exec", L"if",
|
|
L"and", L"or", L"not"});
|
|
bool parser_keywords_is_subcommand(const wcstring &cmd) {
|
|
return parser_keywords_skip_arguments(cmd) || contains(subcommand_keywords, cmd);
|
|
}
|
|
|
|
static const wcstring_list_t block_keywords({L"for", L"while", L"if", L"function", L"switch",
|
|
L"begin"});
|
|
bool parser_keywords_is_block(const wcstring &word) { return contains(block_keywords, word); }
|
|
|
|
static const wcstring_list_t 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"["});
|
|
bool parser_keywords_is_reserved(const wcstring &word) {
|
|
return parser_keywords_is_block(word) || parser_keywords_is_subcommand(word) ||
|
|
contains(reserved_keywords, word);
|
|
}
|