with comment

This commit is contained in:
Mark Canlas 2022-12-04 17:23:42 -05:00
parent c9ac5ee14b
commit 54ffb91104
3 changed files with 18 additions and 6 deletions

View File

@ -6,3 +6,4 @@
; Change direction: W A S D
labeled:
; This is a subroutine description

View File

@ -54,6 +54,7 @@ object PrintPrograms extends ZIOAppDefault:
),
NamedCodeBlock(
"labeled",
"This is a subroutine description".some,
List(
AsmBlock.Intent(
None,

View File

@ -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