[education/rkward] rkward: Formatting

Thomas Friedrichsmeier null at kde.org
Mon May 26 15:06:38 BST 2025


Git commit 3a5bee06bb4eb7ec31892b0a01a6fa80a36de536 by Thomas Friedrichsmeier.
Committed on 26/05/2025 at 14:06.
Pushed by tfry into branch 'master'.

Formatting

M  +22   -13   rkward/autotests/rkparsedscript_test.cpp
M  +2    -2    rkward/misc/rkoutputdirectory.h
M  +8    -7    rkward/misc/rkparsedscript.cpp
M  +3    -3    rkward/misc/rkparsedscript.h

https://invent.kde.org/education/rkward/-/commit/3a5bee06bb4eb7ec31892b0a01a6fa80a36de536

diff --git a/rkward/autotests/rkparsedscript_test.cpp b/rkward/autotests/rkparsedscript_test.cpp
index 7761fa28e..28e785e35 100644
--- a/rkward/autotests/rkparsedscript_test.cpp
+++ b/rkward/autotests/rkparsedscript_test.cpp
@@ -78,29 +78,38 @@ class RKParsedScriptTest : public QObject {
 		for (int startpos = 0; startpos < script.length(); ++startpos) {
 			const auto ctx0 = ps.contextAtPos(script.length() / 2);
 			auto ctx = ctx0;
-			while (ctx.valid()) ctx = ps.nextContext(ctx);
+			while (ctx.valid())
+				ctx = ps.nextContext(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.nextSibling(ctx);
+			while (ctx.valid())
+				ctx = ps.nextSibling(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.nextSiblingOrOuter(ctx);
+			while (ctx.valid())
+				ctx = ps.nextSiblingOrOuter(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.nextStatement(ctx);
+			while (ctx.valid())
+				ctx = ps.nextStatement(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.prevContext(ctx);
+			while (ctx.valid())
+				ctx = ps.prevContext(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.prevSibling(ctx);
+			while (ctx.valid())
+				ctx = ps.prevSibling(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.prevSiblingOrOuter(ctx);
+			while (ctx.valid())
+				ctx = ps.prevSiblingOrOuter(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.prevStatement(ctx);
+			while (ctx.valid())
+				ctx = ps.prevStatement(ctx);
 			ctx = ctx0;
-			while (ctx.valid()) ctx = ps.parentRegion(ctx);
+			while (ctx.valid())
+				ctx = ps.parentRegion(ctx);
 		}
 	}
 
 	void nextPrevStatement() {
 		loadScript(u"script1.R"_s);
-//		ps.serialize();
+		//		ps.serialize();
 		auto ctx = ps.contextAtPos(0);
 		QVERIFY(ctx.valid());
 		testLog("Block1");
@@ -116,7 +125,7 @@ class RKParsedScriptTest : public QObject {
 		ctx = moveAndCheck(ps.prevStatement(ctx), u"Symbol19"_s);
 		ctx = moveAndCheck(ps.prevStatement(ctx), u"Symbol01"_s);
 		ctx = moveAndCheck(ps.prevStatement(ctx), u"Symbol00"_s);
-		//QVERIFY(!ps.prevStatement(ctx).valid());  // not sure that we want this
+		// QVERIFY(!ps.prevStatement(ctx).valid());  // not sure that we want this
 
 		testLog("Block3");
 		ctx = ps.contextAtPos(script.indexOf(u"Symbol11"));
@@ -140,8 +149,8 @@ class RKParsedScriptTest : public QObject {
 
 		testLog("Block5");
 		const auto symb14 = ps.contextAtPos(script.indexOf(u"Symbol14"));
-		ctx = moveAndCheck(ps.prevStatement(symb14), u"Symbol11"_s);  // shall stay in parenthesis
-		ctx = moveAndCheck(ps.prevStatement(ctx), u"Symbol10"_s); // shall move out
+		ctx = moveAndCheck(ps.prevStatement(symb14), u"Symbol11"_s); // shall stay in parenthesis
+		ctx = moveAndCheck(ps.prevStatement(ctx), u"Symbol10"_s);    // shall move out
 
 		testLog("Block6");
 		ctx = ps.contextAtPos(script.indexOf(u"Argname"));
diff --git a/rkward/misc/rkoutputdirectory.h b/rkward/misc/rkoutputdirectory.h
index c61aa6efb..92f5c443a 100644
--- a/rkward/misc/rkoutputdirectory.h
+++ b/rkward/misc/rkoutputdirectory.h
@@ -24,8 +24,8 @@ class RKOutputDirectory;
 /** Convenience struct to avoid defining separate functions for R API and C++ API in RKOutputDirectory.
  *  This struct encapsulates the relevant results for both */
 struct RKOutputDirectoryCallResult : public GenericRRequestResult {
-	RKOutputDirectoryCallResult() : GenericRRequestResult(), _dir(nullptr){};
-	RKOutputDirectoryCallResult(const GenericRRequestResult &other) : GenericRRequestResult(other), _dir(nullptr){};
+	RKOutputDirectoryCallResult() : GenericRRequestResult(), _dir(nullptr) {};
+	RKOutputDirectoryCallResult(const GenericRRequestResult &other) : GenericRRequestResult(other), _dir(nullptr) {};
 	void setDir(RKOutputDirectory *d);
 	RKOutputDirectory *dir() const { return _dir; }
 
diff --git a/rkward/misc/rkparsedscript.cpp b/rkward/misc/rkparsedscript.cpp
index e4b41719d..f7aed2c44 100644
--- a/rkward/misc/rkparsedscript.cpp
+++ b/rkward/misc/rkparsedscript.cpp
@@ -36,7 +36,7 @@ int RKParsedScript::addContext(ContextType type, int start, const QString &conte
 		if (prevtype == Comment) { // comment region implies a newline
 			auto pprevtype = context_list.at(index - 2).type;
 			if (pprevtype != OtherOperator && pprevtype != SubsetOperator) {
-				context_list.emplace_back(Delimiter, start-1, start-1);
+				context_list.emplace_back(Delimiter, start - 1, start - 1);
 				++index;
 			}
 		}
@@ -118,7 +118,7 @@ RKParsedScript::ContextIndex RKParsedScript::contextAtPos(int pos) const {
 RKParsedScript::ContextIndex RKParsedScript::nextContext(const ContextIndex from) const {
 	if (!from.valid()) return ContextIndex();
 	int i = from.index + 1;
-	if (i >= (int) context_list.size()) i = -1;
+	if (i >= (int)context_list.size()) i = -1;
 	return ContextIndex(i);
 }
 
@@ -131,9 +131,9 @@ RKParsedScript::ContextIndex RKParsedScript::prevContext(const ContextIndex from
 /** Find the innermost region (Context::maybeNesting()) containing this context */
 RKParsedScript::ContextIndex RKParsedScript::parentRegion(const ContextIndex from) const {
 	RK_TRACE(MISC);
-	if (from.valid())  {
+	if (from.valid()) {
 		int startpos = context_list.at(from.index).start;
-		for (int i = from.index-1; i >= 0; --i) {
+		for (int i = from.index - 1; i >= 0; --i) {
 			if (context_list.at(i).maybeNesting() && context_list.at(i).end >= startpos) {
 				return ContextIndex(i);
 			}
@@ -145,7 +145,7 @@ RKParsedScript::ContextIndex RKParsedScript::parentRegion(const ContextIndex fro
 /** Find next sibling context (no inner or outer contexts) */
 RKParsedScript::ContextIndex RKParsedScript::nextSiblingOrOuter(const ContextIndex from) const {
 	RK_TRACE(MISC);
-	if (from.valid())  {
+	if (from.valid()) {
 		int endpos = context_list.at(from.index).end;
 		unsigned int i = from.index;
 		do {
@@ -165,7 +165,7 @@ RKParsedScript::ContextIndex RKParsedScript::nextSibling(const ContextIndex from
 
 RKParsedScript::ContextIndex RKParsedScript::prevSiblingOrOuter(const ContextIndex from) const {
 	RK_TRACE(MISC);
-	if (from.valid())  {
+	if (from.valid()) {
 		int startpos = context_list.at(from.index).start;
 		const auto parent = parentRegion(from);
 		int i = from.index;
@@ -302,7 +302,8 @@ QString RKParsedScript::serializeContextEnd(const Context &ctx, int level) const
 	if (ptype == BackQuoted) return u"`"_s;
 	if (ptype == Comment || ptype == Delimiter) {
 		QString ret = u"\n"_s;
-		for (int j = 0; j < (level-1) * 4; ++j) ret += u" "_s;
+		for (int j = 0; j < (level - 1) * 4; ++j)
+			ret += u" "_s;
 		return ret;
 	}
 	return QString();
diff --git a/rkward/misc/rkparsedscript.h b/rkward/misc/rkparsedscript.h
index b5db0601c..faa71bfd1 100644
--- a/rkward/misc/rkparsedscript.h
+++ b/rkward/misc/rkparsedscript.h
@@ -51,7 +51,7 @@ class RKParsedScript {
 		int end;
 	};
 
-	explicit RKParsedScript(const QString &content=QString());
+	explicit RKParsedScript(const QString &content = QString());
 
 	enum SearchFlags {
 		NoFlags,
@@ -102,8 +102,8 @@ class RKParsedScript {
 	// add and parse a context. This is where the actual parsing takes place
 	int addContext(ContextType type, int start, const QString &content);
 
-friend class RKParsedScriptTest;
-friend class RKCodeNavigation;
+	friend class RKParsedScriptTest;
+	friend class RKCodeNavigation;
 	// NOTE: used in debugging, only
 	QString serialize() const;
 	QString serializeContextEnd(const Context &ctx, int level) const;



More information about the rkward-tracker mailing list