Modify parser to accept 'begin' without ';'

Examples that work as expected (even completions don't get confused):

$ begin true; end;
$ begin if true; end; end
$ begin if true; echo hi; end

The last example correctly expects another 'end' to match 'begin'.

Fixes #1248.
This commit is contained in:
Sanne Wouda 2015-03-11 23:53:24 +01:00 committed by David Adam
parent d1a56139e1
commit fd731fb74f
3 changed files with 23 additions and 13 deletions

View File

@ -413,7 +413,7 @@ parse_execution_result_t parse_execution_context_t::run_block_statement(const pa
const parse_node_t &block_header = *get_child(statement, 0, symbol_block_header); //block header
const parse_node_t &header = *get_child(block_header, 0); //specific header type (e.g. for loop)
const parse_node_t &contents = *get_child(statement, 2, symbol_job_list); //block contents
const parse_node_t &contents = *get_child(statement, 1, symbol_job_list); //block contents
parse_execution_result_t ret = parse_execution_success;
switch (header.type)
@ -428,7 +428,7 @@ parse_execution_result_t parse_execution_context_t::run_block_statement(const pa
case symbol_function_header:
{
const parse_node_t &function_end = *get_child(statement, 3, symbol_end_command); //the 'end' associated with the block
const parse_node_t &function_end = *get_child(statement, 2, symbol_end_command); //the 'end' associated with the block
ret = run_function_statement(header, function_end);
break;
}

View File

@ -298,7 +298,7 @@ RESOLVE(freestanding_argument_list)
PRODUCTIONS(block_statement) =
{
{symbol_block_header, parse_token_type_end, symbol_job_list, symbol_end_command, symbol_arguments_or_redirections_list}
{symbol_block_header, symbol_job_list, symbol_end_command, symbol_arguments_or_redirections_list}
};
RESOLVE_ONLY(block_statement)
@ -328,25 +328,35 @@ RESOLVE(block_header)
PRODUCTIONS(for_header) =
{
{KEYWORD(parse_keyword_for), parse_token_type_string, KEYWORD(parse_keyword_in), symbol_argument_list}
{KEYWORD(parse_keyword_for), parse_token_type_string, KEYWORD
(parse_keyword_in), symbol_argument_list, parse_token_type_end}
};
RESOLVE_ONLY(for_header)
PRODUCTIONS(while_header) =
{
{KEYWORD(parse_keyword_while), symbol_job}
{KEYWORD(parse_keyword_while), symbol_job, parse_token_type_end}
};
RESOLVE_ONLY(while_header)
PRODUCTIONS(begin_header) =
{
{KEYWORD(parse_keyword_begin), parse_token_type_end},
{KEYWORD(parse_keyword_begin)}
};
RESOLVE_ONLY(begin_header)
RESOLVE(begin_header)
{
switch (token2.type) {
case parse_token_type_end:
return 0;
default:
return 1;
}
}
PRODUCTIONS(function_header) =
{
{KEYWORD(parse_keyword_function), symbol_argument, symbol_argument_list}
{KEYWORD(parse_keyword_function), symbol_argument, symbol_argument_list, parse_token_type_end}
};
RESOLVE_ONLY(function_header)

View File

@ -249,14 +249,14 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t flags, parse
case_item = CASE argument_list <TOK_END> job_list
block_statement = block_header <TOK_END> job_list end_command arguments_or_redirections_list
block_header = for_header | while_header | function_header | begin_header
for_header = FOR var_name IN argument_list
while_header = WHILE job
begin_header = BEGIN
block_statement = block_header job_list end_command arguments_or_redirections_list
block_header = for_header | while_header | function_header | begin_header
for_header = FOR var_name IN argument_list <TOK_END>
while_header = WHILE job <TOK_END>
begin_header = BEGIN | BEGIN <TOK_END>
# Functions take arguments, and require at least one (the name). No redirections allowed.
function_header = FUNCTION argument argument_list
function_header = FUNCTION argument argument_list <TOK_END>
# A boolean statement is AND or OR or NOT