Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Manuel Reiter Newsgroups: gnu.bash.bug Subject: Re: error message for missing fi is not helpful Date: Fri, 14 Sep 2018 16:26:14 +0200 Lines: 82 Approved: bug-bash@gnu.org Message-ID: References: <12006574-8df4-d613-0603-51b77b703a3d@dwd.de> <3461cc07-6477-234b-83ea-30a6bc0c8d8c@case.edu> <5B99CB6D.5060108@tlinx.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F73683A027B772DBEC74E544" X-Trace: usenet.stanford.edu 1536935191 10297 208.118.235.17 (14 Sep 2018 14:26:31 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org X-Virus-Scanned: by amavisd-new at csg.dwd.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-Reply-To: <5B99CB6D.5060108@tlinx.org> Content-Language: uk-UA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 141.38.3.245 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14579 This is a multi-part message in MIME format. --------------F73683A027B772DBEC74E544 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 13.09.2018 04:29, L A Walsh wrote: > This isn't *exactly* what you wanted, but this gives the line number > of the last unmatched statement (but doesn't tell you what the statement > was).  The diff was against bash-4.4.23 (4.4 base w/23 patches) Thank you for taking the time to look into this! There seems to be a problem with your code though: if word_top is zero and EOF_Reached is true, you set msg to msg0 without initializing msg0 first. Reviving the code you commented out (your first attempt?) I came to the attached result. I also added if/fi to the compound commands tracked by word_top. There are probably others that I have missed missed. > Anyway, if you store the word in a separate array where the line # > is stored, you _could_ list the matching word, but I suspect just the > line it started on would be enough for most users. I totally agree with that. Thanks and best regards, Manuel --------------F73683A027B772DBEC74E544 Content-Type: text/x-patch; name="parse.y.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="parse.y.diff" diff --git a/parse.y.orig b/parse.y index f415d2e..76974f0 100644 --- a/parse.y.orig +++ b/parse.y @@ -1000,11 +1000,11 @@ coproc: COPROC shell_command ; if_command: IF compound_list THEN compound_list FI - { $$ = make_if_command ($2, $4, (COMMAND *)NULL); } + { $$ = make_if_command ($2, $4, (COMMAND *)NULL); if (word_top > 0) word_top--; } | IF compound_list THEN compound_list ELSE compound_list FI - { $$ = make_if_command ($2, $4, $6); } + { $$ = make_if_command ($2, $4, $6); if (word_top > 0) word_top--; } | IF compound_list THEN compound_list elif_clause FI - { $$ = make_if_command ($2, $4, $5); } + { $$ = make_if_command ($2, $4, $5); if (word_top > 0) word_top--; } ; @@ -5142,6 +5142,7 @@ got_token: case CASE: case SELECT: case FOR: + case IF: if (word_top < MAX_CASE_NEST) word_top++; word_lineno[word_top] = line_number; @@ -6020,9 +6021,13 @@ report_syntax_error (message) print_offending_line (); } else - { - msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error"); - parser_error (line_number, "%s", msg); + { + if (EOF_Reached && word_top>=0) { + parser_error(line_number, _("syntax error: unexpected end of file from line %d."), word_lineno[word_top] ); + } else { + msg = EOF_Reached ? _("syntax error: unexpected end of file") : _("syntax error"); + parser_error (line_number, "%s", msg); + } /* When the shell is interactive, this file uses EOF_Reached only for error reporting. Other mechanisms are used to decide whether or not to exit. */ --------------F73683A027B772DBEC74E544--