From fa547cd9e8f434097c2a42898863e8a20ea7c4e7 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 23 Dec 2018 17:33:45 +0100 Subject: [PATCH] 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. --- lslopt/lsloutput.py | 15 +++++++++++++++ testparser.py | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lslopt/lsloutput.py b/lslopt/lsloutput.py index edf428f..f8b535f 100644 --- a/lslopt/lsloutput.py +++ b/lslopt/lsloutput.py @@ -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 diff --git a/testparser.py b/testparser.py index 5a9c978..f1b56bf 100644 --- a/testparser.py +++ b/testparser.py @@ -442,8 +442,8 @@ class Test03_Optimizer(UnitTestCase): ''', ['extendedassignment']) self.opt.optimize(p) out = self.outscript.output(p) - self.assertEqual(out, 'integer a;\nx()\n{\n {\n ' - 'string s = "x";\n s = s + (string)a;\n }\n}\n' + self.assertEqual(out, 'integer a;\n\nx()\n{\n {\n ' + 'string s = "x";\n s = s + (string)a;\n }\n}\n\n' 'default\n{\n timer()\n {\n x();\n a = 3;\n' ' llOwnerSay((string)a);\n' ' }\n}\n' @@ -462,7 +462,7 @@ class Test03_Optimizer(UnitTestCase): self.opt.optimize(p) out = self.outscript.output(p) self.assertEqual(out, 'key k = "blah";\nlist L = [k, "xxxx", 1.];\n' - 'float f = 0;\ninteger i;\nvector v = ;\n' + 'float f = 0;\ninteger i;\nvector v = ;\n\n' 'default\n{\n timer()\n {\n' ' f = 4;\n k = "";\n i = 0;\n' ' v = <((float)0), ((float)0), ((float)0)>;\n L = [];\n' @@ -476,7 +476,7 @@ class Test03_Optimizer(UnitTestCase): ['extendedglobalexpr']) self.opt.optimize(p) out = self.outscript.output(p) - self.assertEqual(out, 'list L;\nfloat f = 0;\n' + self.assertEqual(out, 'list L;\nfloat f = 0;\n\n' 'default\n{\n timer()\n {\n' ' L = [];\n f = 3;\n' ' llOwnerSay((string)(L + f));\n'