SDF3-symbolsorts’s generated pretty-printer will indent poorly when presented with both indentation and newlines in a template.

For example, in this syntax I want the import directives indented one level in, each on a line, all on the same column:

Start.Module = <
	module <ID> 
	
		<Import*>
>

Import.Import = <
	import <ID>;

>

So the pretty-printer should generate something like this:

module X

  import a;
  import b;
  import c;

But it generates this:

module X

  import a;
   import b;
   import c;
Submitted by D. Pelsmaeker on 22 July 2014 at 15:36

On 22 July 2014 at 16:34 Eduardo Amorim commented:

There is a “bug” in the box pretty printer for lists. It adds a default single space layout as separator when pretty printing lists with no separator.

In this case you have two approaches to fix it:

  • The first one would be by adding a newline separator to the <Import*> element and removing the newline from the Import definition:

    Start.Module = <
    	module <ID>
    
    		<{Import "\n"}*>
    
    >
    
    Import.Import = <
    	import <ID>;
    >
    
  • The second one would be by adding an empty separator to the <Import*> element and keeping the newline:

    Start.Module = <
    	module <ID>
    
    		<{Import ""}*>
    
    >
    
    Import.Import = <
    	import <ID>;
    
    >
    

I think the first one is more descriptive of how your intended pretty-printer should behave.


On 22 July 2014 at 16:34 Eduardo Amorim closed this issue.

On 22 July 2014 at 17:12 D. Pelsmaeker commented:

Thank you, both work. I expected adding the newline separator ({Import "\n"}*) to change the semantics of the language, requiring a newline between every import. But apparently layout is stripped from the separators in the generated SDF2, which makes this work.

However, I noticed spaces, tabs and newlines are always removed from the separators even when it is not part of the LAYOUT rule of the project. For example in Python where newlines and tabs matter, it is impossible to enforce those newlines and tabs in the separators.

Log in to post comments