mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 10:43:47 +08:00
Remove additional dead code from old parser
This commit is contained in:
parent
e5ef45e4c0
commit
4deb46290d
|
@ -3743,7 +3743,7 @@ int builtin_run(parser_t &parser, const wchar_t * const *argv, const io_chain_t
|
|||
|
||||
if (argv[1] != 0 && !internal_help(argv[0]))
|
||||
{
|
||||
if (argv[2] == 0 && (parser.is_help(argv[1], 0)))
|
||||
if (argv[2] == 0 && (parse_util_argument_is_help(argv[1], 0)))
|
||||
{
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return STATUS_BUILTIN_OK;
|
||||
|
|
|
@ -986,6 +986,18 @@ static int parser_is_pipe_forbidden(const wcstring &word)
|
|||
L"continue");
|
||||
}
|
||||
|
||||
bool parse_util_argument_is_help(const wchar_t *s, int min_match)
|
||||
{
|
||||
CHECK(s, 0);
|
||||
|
||||
size_t len = wcslen(s);
|
||||
|
||||
min_match = maxi(min_match, 3);
|
||||
|
||||
return (wcscmp(L"-h", s) == 0) ||
|
||||
(len >= (size_t)min_match && (wcsncmp(L"--help", s, len) == 0));
|
||||
}
|
||||
|
||||
// Check if the first argument under the given node is --help
|
||||
static bool first_argument_is_help(const parse_node_tree_t &node_tree, const parse_node_t &node, const wcstring &src)
|
||||
{
|
||||
|
@ -996,7 +1008,7 @@ static bool first_argument_is_help(const parse_node_tree_t &node_tree, const par
|
|||
// Check the first argument only
|
||||
const parse_node_t &arg = *arg_nodes.at(0);
|
||||
const wcstring first_arg_src = arg.get_source(src);
|
||||
is_help = parser_t::is_help(first_arg_src.c_str(), 3);
|
||||
is_help = parse_util_argument_is_help(first_arg_src.c_str(), 3);
|
||||
}
|
||||
return is_help;
|
||||
}
|
||||
|
|
|
@ -150,6 +150,15 @@ void parse_util_set_argv(const wchar_t * const *argv, const wcstring_list_t &nam
|
|||
*/
|
||||
wchar_t *parse_util_unescape_wildcards(const wchar_t *in);
|
||||
|
||||
/**
|
||||
Checks if the specified string is a help option.
|
||||
|
||||
\param s the string to test
|
||||
\param min_match is the minimum number of characters that must match in a long style option, i.e. the longest common prefix between --help and any other option. If less than 3, 3 will be assumed.
|
||||
*/
|
||||
bool parse_util_argument_is_help(const wchar_t *s, int min_match);
|
||||
|
||||
|
||||
/**
|
||||
Calculates information on the parameter at the specified index.
|
||||
|
||||
|
|
61
parser.cpp
61
parser.cpp
|
@ -381,10 +381,6 @@ void parser_t::forbid_function(const wcstring &function)
|
|||
|
||||
void parser_t::allow_function()
|
||||
{
|
||||
/*
|
||||
if( al_peek( &forbidden_function) )
|
||||
debug( 2, L"Allow %ls\n", al_peek( &forbidden_function) );
|
||||
*/
|
||||
forbidden_function.pop_back();
|
||||
}
|
||||
|
||||
|
@ -846,25 +842,6 @@ wcstring parser_t::current_line()
|
|||
return line_info;
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *parser_t::get_buffer() const
|
||||
{
|
||||
return tok_string(current_tokenizer);
|
||||
}
|
||||
|
||||
|
||||
int parser_t::is_help(const wchar_t *s, int min_match)
|
||||
{
|
||||
CHECK(s, 0);
|
||||
|
||||
size_t len = wcslen(s);
|
||||
|
||||
min_match = maxi(min_match, 3);
|
||||
|
||||
return (wcscmp(L"-h", s) == 0) ||
|
||||
(len >= (size_t)min_match && (wcsncmp(L"--help", s, len) == 0));
|
||||
}
|
||||
|
||||
void parser_t::job_add(job_t *job)
|
||||
{
|
||||
assert(job != NULL);
|
||||
|
@ -948,7 +925,7 @@ profile_item_t *parser_t::create_profile_item()
|
|||
}
|
||||
|
||||
|
||||
int parser_t::eval_new_parser(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type)
|
||||
int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type)
|
||||
{
|
||||
CHECK_BLOCK(1);
|
||||
|
||||
|
@ -1055,42 +1032,6 @@ int parser_t::eval_block_node(node_offset_t node_idx, const io_chain_t &io, enum
|
|||
|
||||
}
|
||||
|
||||
int parser_t::eval(const wcstring &cmd_str, const io_chain_t &io, enum block_type_t block_type)
|
||||
{
|
||||
return this->eval_new_parser(cmd_str, io, block_type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\return the block type created by the specified builtin, or -1 on error.
|
||||
*/
|
||||
block_type_t parser_get_block_type(const wcstring &cmd)
|
||||
{
|
||||
for (size_t i=0; block_lookup[i].desc; i++)
|
||||
{
|
||||
if (block_lookup[i].name && cmd == block_lookup[i].name)
|
||||
{
|
||||
return block_lookup[i].type;
|
||||
}
|
||||
}
|
||||
return (block_type_t)-1;
|
||||
}
|
||||
|
||||
/**
|
||||
\return the block command that createa the specified block type, or null on error.
|
||||
*/
|
||||
const wchar_t *parser_get_block_command(int type)
|
||||
{
|
||||
for (size_t i=0; block_lookup[i].desc; i++)
|
||||
{
|
||||
if (block_lookup[i].type == type)
|
||||
{
|
||||
return block_lookup[i].name;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
Test if this argument contains any errors. Detected errors include
|
||||
syntax errors in command substitutions, improperly escaped
|
||||
|
|
26
parser.h
26
parser.h
|
@ -278,7 +278,7 @@ private:
|
|||
wcstring block_stack_description() const;
|
||||
|
||||
/** List of profile items, allocated with new */
|
||||
std::vector<profile_item_t*> profile_items;
|
||||
std::vector<profile_item_t *> profile_items;
|
||||
|
||||
/* No copying allowed */
|
||||
parser_t(const parser_t&);
|
||||
|
@ -319,9 +319,6 @@ public:
|
|||
/** Global event blocks */
|
||||
event_blockage_list_t global_event_blocks;
|
||||
|
||||
/** Current block level io redirections */
|
||||
io_chain_t block_io;
|
||||
|
||||
/**
|
||||
Evaluate the expressions contained in cmd.
|
||||
|
||||
|
@ -332,7 +329,6 @@ public:
|
|||
\return 0 on success, 1 otherwise
|
||||
*/
|
||||
int eval(const wcstring &cmd_str, const io_chain_t &io, enum block_type_t block_type);
|
||||
int eval_new_parser(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type);
|
||||
|
||||
/** Evaluates a block node at the given node offset in the topmost execution context */
|
||||
int eval_block_node(node_offset_t node_idx, const io_chain_t &io, enum block_type_t block_type);
|
||||
|
@ -384,9 +380,6 @@ public:
|
|||
return block_stack.size();
|
||||
}
|
||||
|
||||
/** Get the string currently parsed */
|
||||
const wchar_t *get_buffer() const;
|
||||
|
||||
/** Get the list of jobs */
|
||||
job_list_t &job_list()
|
||||
{
|
||||
|
@ -448,29 +441,17 @@ public:
|
|||
of infinite recursion.
|
||||
*/
|
||||
void forbid_function(const wcstring &function);
|
||||
|
||||
/**
|
||||
Undo last call to parser_forbid_function().
|
||||
*/
|
||||
void allow_function();
|
||||
|
||||
/**
|
||||
Initialize static parser data
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
Output profiling data to the given filename
|
||||
*/
|
||||
void emit_profiling(const char *path) const;
|
||||
|
||||
/**
|
||||
This function checks if the specified string is a help option.
|
||||
|
||||
\param s the string to test
|
||||
\param min_match is the minimum number of characters that must match in a long style option, i.e. the longest common prefix between --help and any other option. If less than 3, 3 will be assumed.
|
||||
*/
|
||||
static int is_help(const wchar_t *s, int min_match);
|
||||
|
||||
/**
|
||||
Returns the file currently evaluated by the parser. This can be
|
||||
different than reader_current_filename, e.g. if we are evaulating a
|
||||
|
@ -482,9 +463,6 @@ public:
|
|||
Write a stack trace starting at the specified block to the specified wcstring
|
||||
*/
|
||||
void stack_trace(size_t block_idx, wcstring &buff) const;
|
||||
|
||||
int get_block_type(const wchar_t *cmd) const;
|
||||
const wchar_t *get_block_command(int type) const;
|
||||
};
|
||||
|
||||
/* Temporary */
|
||||
|
|
Loading…
Reference in New Issue
Block a user