Add blank lines to make the output somewhat prettier

Add blank lines between functions, between functions and states, between variables and functions or states, between states, and between events.

Or more concisely: add blank lines between events and between all elements at the global level except between variables (that actually describes the algorithm).

Some test cases expected no newlines; fix them.
This commit is contained in:
Sei Lisa 2018-12-23 17:33:45 +01:00
parent fab3ce4d24
commit fa547cd9e8
2 changed files with 19 additions and 4 deletions

View file

@ -456,8 +456,14 @@ class outscript(object):
ret += self.dent() + '{\n'
self.indentlevel += 1
firstnode = True
for stmt in node.ch:
if stmt.nt == 'LAMBDA':
continue
if nt == 'STDEF' and not firstnode:
ret += '\n'
ret += self.OutCode(stmt)
firstnode = False
self.indentlevel -= 1
return ret + self.dent() + '}\n'
@ -499,9 +505,18 @@ class outscript(object):
self.indentlevel = 0
self.globalmode = False
self.listmode = False
firstnode = True
prevnt = None
for node in self.tree:
if node.nt == 'LAMBDA':
# these don't produce output, skip
continue
if not firstnode and (node.nt != 'DECL' or prevnt != 'DECL'):
ret += '\n'
self.globalmode = node.nt == 'DECL'
ret += self.OutCode(node)
self.globalmode = False
firstnode = False
prevnt = node.nt
return ret