From abe7c7e255646184475832f09dbf3c2b6fbb1ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Mon, 11 Nov 2024 02:03:55 +0100 Subject: [PATCH] refactor for consistency --- .../main/scala/playground/parsergen/ParserGen.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala b/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala index a2a022b4..d5850a44 100644 --- a/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala +++ b/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala @@ -49,6 +49,11 @@ private def renderUnion(u: Type.Union): String = { // format: on } + val instanceMethods = + show"""extension (node: $name) { + |${projections.mkString_("\n").indentTrim(2)} + |}""".stripMargin + val applyMethod = { val cases = u .subtypes @@ -69,9 +74,7 @@ private def renderUnion(u: Type.Union): String = { | |object $name { | - | extension (node: $name) { - |${projections.mkString_("\n").indentTrim(4)} - | } + |${instanceMethods.indentTrim(2)} | |${applyMethod.indentTrim(2)} | @@ -164,7 +167,7 @@ private def renderProduct(p: Type.Product): String = { show"""def ${fieldType.asChildName.render}: $fieldTypeAnnotation = $childValue""".stripMargin } - val methods = + val instanceMethods = if (fieldGetters.nonEmpty || typedChildren.nonEmpty || typedChildrenPrecise.nonEmpty) { show"""extension (node: $name) { | // fields @@ -185,7 +188,7 @@ private def renderProduct(p: Type.Product): String = { |opaque type $name <: Node = Node | |object $name { - |${methods.indentTrim(2)} + |${instanceMethods.indentTrim(2)} | | def apply(node: Node): Either[String, $name] = | if node.tpe == ${p.name.value.literal}