From 54ffb9110445104370dc717ff1e13dde3d516adf Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Sun, 4 Dec 2022 17:23:42 -0500 Subject: [PATCH] with comment --- data/annotated-snake.asm | 1 + .../firepower/demo/PrintPrograms.scala | 1 + .../htmlism/firepower/demo/asm/AsmBlock.scala | 22 ++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/data/annotated-snake.asm b/data/annotated-snake.asm index 7131206..8869422 100644 --- a/data/annotated-snake.asm +++ b/data/annotated-snake.asm @@ -6,3 +6,4 @@ ; Change direction: W A S D labeled: + ; This is a subroutine description diff --git a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala index ba3d121..3030d3a 100644 --- a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala +++ b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala @@ -54,6 +54,7 @@ object PrintPrograms extends ZIOAppDefault: ), NamedCodeBlock( "labeled", + "This is a subroutine description".some, List( AsmBlock.Intent( None, diff --git a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala index 7f03a55..0482e69 100644 --- a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala +++ b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala @@ -6,24 +6,34 @@ sealed trait AsmBlock case class CommentBlock(xs: List[String]) extends AsmBlock -case class NamedCodeBlock(name: String, intents: List[AsmBlock.Intent]) extends AsmBlock +case class NamedCodeBlock(name: String, comment: Option[String], intents: List[AsmBlock.Intent]) extends AsmBlock case class AnonymousCodeBlock(intents: List[AsmBlock.Intent]) extends AsmBlock object AsmBlock: + def toComment(s: String): String = + "; " + s + + def withIndent(s: String): String = + " " + s + def toParagraphs(xs: AsmBlock): List[Paragraph] = xs match case CommentBlock(ys) => List( - Paragraph(ys.map("; " + _)) + Paragraph(ys.map(toComment)) ) - case NamedCodeBlock(label, _) => - List( + case NamedCodeBlock(label, oComment, _) => + val headerParagraph = Paragraph( - List(label + ":") + List(label + ":") ++ oComment.map(toComment).map(withIndent).toList ) - ) + + val intentParagraphs = + Nil + + headerParagraph :: intentParagraphs case AnonymousCodeBlock(_) => Nil