patchGNU Octave - Patches: patch #9023, Tell user about misaligned if/end...

 
 

patch #9023: Tell user about misaligned if/end pairs when an end-related error occurs

Submitter:  Lachlan Andrew <lachlan>
Submitted:  Fri 10 Jun 2016 09:18:19 AM UTC
   
 
Category:  Core : new feature Priority:  5 - Normal
Status:  None Privacy:  Public
Assigned to:  lachlan Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 13 Jun 2016 09:52:43 AM UTC, comment #1: 

Note: The patch accidentally has tabs in it.  I'll remove them in the next version, but will wait for feedback first.

Lachlan Andrew <lachlan>
Fri 10 Jun 2016 09:18:19 AM UTC, original submission:  

This patch gives users a hint about where a missing or spurious "end" (or "endif" or "endfor" etc.) might be.

It uses the heuristic that the "end" should start at the same level of indentation as the "if" or whatever, or perhaps be on the same line as the "if".  It records if/end pairs for which that doesn't occur.  If an error occurs that is likely to be due to mismatched ends, it augments the error message with a note telling the user the innermost pair that start in different columns.

This is most useful for those of us who have to write Matlab-compatible code, since the dedicated forms of endXYZ provide some help with this, but in deeply nested "if" or "for" statements, it still reduces the ambiguity.

If users have a coding style in which the "end" is supposed to have a different indent, this will not create excess diagnostics, since it only prints anything when an error occurs.  Also, the output is only of the form


Note: The if on line W column X matches the end on line Y column Z.


which doesn't say that that is the cause of the error.

Lachlan Andrew <lachlan>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by lachlan (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-07-07 lachlan CategoryNone Core : new feature
    2016-06-10 lachlan Attached File- Added patch_warn_misaligned_ends.cset, #37445

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code