From 9cf9226e86a1d775e3a1a5d11c44c48247947abd Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 17 Jul 2013 23:36:10 -0500 Subject: [PATCH] Don't leave open parentheses hanging at line breaks --- src/zscript/ast.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/zscript/ast.cpp b/src/zscript/ast.cpp index e11d7fb32..bc1afd312 100644 --- a/src/zscript/ast.cpp +++ b/src/zscript/ast.cpp @@ -34,6 +34,7 @@ public: NestDepth = Column = 0; WrapWidth = 72; NeedSpace = false; + ConsecOpens = 0; } void Open(const char *label) @@ -43,8 +44,10 @@ public: if (NeedSpace) { Str << ' '; + ConsecOpens = 0; } Str << '('; + ConsecOpens++; if (label != NULL) { Str.AppendCStrPart(label, labellen); @@ -66,6 +69,15 @@ public: // Don't break if not needed. if (Column != NestDepth) { + if (NeedSpace) + { + ConsecOpens = 0; + } + else + { // Move hanging ( characters to the new line + Str.Truncate(long(Str.Len() - ConsecOpens)); + NestDepth -= ConsecOpens; + } Str << '\n'; Column = NestDepth; NeedSpace = false; @@ -73,6 +85,14 @@ public: { Str.AppendFormat("%*s", NestDepth, ""); } + if (ConsecOpens > 0) + { + for (size_t i = 0; i < ConsecOpens; ++i) + { + Str << '('; + } + NestDepth += ConsecOpens; + } } } bool CheckWrap(size_t len) @@ -143,6 +163,7 @@ private: size_t NestDepth; size_t Column; size_t WrapWidth; + size_t ConsecOpens; bool NeedSpace; };