demonstrate code block

This commit is contained in:
Mark Canlas 2022-12-04 16:56:03 -05:00
parent 67c77196f1
commit 844d34dd5d
3 changed files with 24 additions and 3 deletions

View File

@ -4,3 +4,6 @@
; |___/_||_\__,_|_\_\___\___/___/\__/___|
; Change direction: W A S D
labeled:

View File

@ -27,11 +27,13 @@ object PrintPrograms extends ZIOAppDefault:
),
"annotated-snake.asm" -> (Line.mkString _)
.compose(Paragraph.mkLines)
.compose((xs: List[CommentBlock]) => xs.map(CommentBlock.toParagraph))
.compose((xs: List[AsmBlock]) => xs.map(AsmBlock.toParagraph))
.apply(
List(
CommentBlock.fromMultiline(asciiArt),
CommentBlock(List("Change direction: W A S D"))
CommentBlock(List("Change direction: W A S D")),
CodeBlock(None, Nil),
CodeBlock(Some("labeled"), Nil)
)
)
)

View File

@ -6,11 +6,27 @@ sealed trait AsmBlock
case class CommentBlock(xs: List[String]) extends AsmBlock
object CommentBlock:
case class CodeBlock(name: Option[String], chunks: List[CodeBlock.Chunk]) extends AsmBlock
object CodeBlock:
case class Chunk(label: Option[String], instructions: List[Chunk.Instruction])
object Chunk:
case class Instruction(code: String, comment: Option[String])
object AsmBlock:
def toParagraph(xs: AsmBlock): Paragraph =
xs match
case CommentBlock(ys) =>
Paragraph(ys.map("; " + _))
case CodeBlock(oLabel, _) =>
Paragraph(
oLabel
.map(_ + ":")
.toList
)
object CommentBlock:
def fromMultiline(s: String): CommentBlock =
CommentBlock(s.split("\\n").toList)