Bug 314442 - Format source messes up LPG grammar
Summary: Format source messes up LPG grammar
Status: ASSIGNED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: IMP (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Robert M. Fuhrer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-26 07:54 EDT by Zoltan Ujhelyi CLA
Modified: 2014-01-09 15:04 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zoltan Ujhelyi CLA 2010-05-26 07:54:34 EDT
I'm using version 0.1.106.v201004212015 of the LPG IDE, and wanted to use the automatic source code formatter by pressing Cmd+Shift+F (Control+Shift+F I guess on Windows).

But it messed up the grammar badly, as it functionally changed the grammar rules: it removed necessary spaces from the language, and the left hand sides of the rules are added to the right hand side of the rule. E.g. 

TextualModel ::= NamespaceDeclarationOpt ImportDeclarationsOpt ModelElementDefinitions

become

TextualModel::=TextualModel NamespaceDeclarationOpt ImportDeclarationsOpt ModelElementDefinitions

The problems are twofold:
  1) By removing some necessary whitespaces (e.g. before ::= or | characters) special symbols are considered as parts of the terminal/non-terminal symbols's name instead of grammar features.
  2) By adding the left hand terminal to the right hand the grammar becomes unusable, as no sane replacements can be made by the parser.
  
I suggest either removing the autoformat option completely from the LPG grammar, or fixing these errors, as these are a real pain to fix.

Thanks.
Comment 1 Zoltan Ujhelyi CLA 2010-05-26 08:10:47 EDT
And it also removes anything between $-s in the grammar - thus unhiding non-terminals and removing list definitions.
Comment 2 Robert M. Fuhrer CLA 2010-05-26 09:13:08 EDT
Hi there, thanks for the bug report!

The error of repeating the non-terminal on the rule RHS should be trivial to fix.

Can you tell me where necessary spaces got deleted?

[Honestly, it's been ages since I used auto-format on LPG, or for that matter, on pretty much anything, including Java. I never seem to like what it produces enough to keep...]
Comment 3 Zoltan Ujhelyi CLA 2010-05-26 11:36:07 EDT
I could identify two scenarios where this causes errors originally: one was at the '::=' symbol (but that could be related to the left hand side duplication). The other was at '|' symbols on the right hand side of rules, where if it was written after the previous symbol, the parser considered the '|' as a part of the symbol name - but I couldn't reproduce this using the already cleaned up grammar (I manually fixed the previously messed up grammar).
Comment 4 Robert M. Fuhrer CLA 2010-06-04 10:30:42 EDT
I fixed the repeating the LHS non-terminal on the rule RHS. The fix is in head of SVN trunk. I'll look at the problem with $'s next.
Comment 5 Robert M. Fuhrer CLA 2010-09-09 12:06:08 EDT
I've fixed the problem with loss of macros, and a few other unfortunate bits of breakage. There still seems to be a problem with the %Recover segment - the AST produced doesn't seem to record the symbols, for some reason. Still looking into that.