-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove
inline
modifier from HasInner components, what led to the bu…
…g. Inline some methods. Use Scala 3 implicit conversion with context parameter
- Loading branch information
1 parent
f7a15ce
commit 48e2459
Showing
14 changed files
with
68 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
package halotukozak.smark | ||
|
||
import tables.Table | ||
import utils.HasInner | ||
import utils.{HasInner, MdElement} | ||
|
||
type MdContent = String | MdElement | Table | ||
opaque type MdUnit = Unit | ||
|
||
private trait MdElement extends HasInner[MdContent]: | ||
private[smark] def eval: String | ||
end MdElement | ||
opaque type MdUnit = Unit | ||
|
||
private class Markdown extends MdElement: | ||
private[smark] def eval = inner.mkString("\n\n") | ||
|
||
end Markdown | ||
override def eval: String = evaluated.mkString("\n\n") | ||
|
||
extension (s: MdContent) | ||
private def eval: String = s match | ||
case s: String => s | ||
case e: MdElement => e.eval | ||
case t: Table => t.eval | ||
|
||
implicit def stringToModifier(s: String)(using m: MdElement): MdUnit = m.add(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
package halotukozak.smark | ||
package typography | ||
|
||
final class Comment extends MdElement: | ||
override private[smark] def eval: String = | ||
val lines = inner.map(e => e.eval).toSeq | ||
commentMacro(if lines.length == 1 then lines.mkString("\n") else lines.mkString("\n", "\n", "\n")) | ||
import utils.MdElement | ||
|
||
private[smark] inline def commentMacro(inline inner: String): String = s"<!-- $inner -->" | ||
final class Comment extends MdElement: | ||
override def eval: String = | ||
s"<!-- ${if evaluated.length == 1 then evaluated.mkString("\n") else evaluated.mkString("\n", "\n", "\n")} -->" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package halotukozak.smark | ||
package typography | ||
|
||
import utils.MdElement | ||
|
||
|
||
private[smark] type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6 | ||
|
||
final class Heading[N <: HeadingLevel : ValueOf] extends MdElement: | ||
override private[smark] def eval: String = inner.map(e => headingMacro[N](e.eval)).mkString("\n") | ||
|
||
private[smark] inline def headingMacro[N <: HeadingLevel : ValueOf](inline inner: String): String = "#" * valueOf[N] + inner | ||
override def eval: String = | ||
evaluated.map(e => s"${"#" * valueOf[N]}$e").mkString("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package halotukozak.smark | ||
package typography | ||
|
||
final class Paragraph extends MdElement: | ||
|
||
override private[smark] def eval: String = paragraphMacro(inner.map(e => e.eval).mkString("\n\n")) | ||
import utils.MdElement | ||
|
||
private[smark] inline def paragraphMacro(inline inner: String): String = "\n" + inner | ||
final class Paragraph extends MdElement: | ||
override def eval: String = "\n" + evaluated.mkString("\n\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package halotukozak.smark | ||
package utils | ||
|
||
import scala.collection.mutable | ||
import scala.collection.mutable.{ListBuffer, Seq} | ||
private[smark] abstract class HasInner[T](private var inner: Seq[T] = Nil): | ||
|
||
private[smark] abstract class HasInner[T](private[smark] val inner: ListBuffer[T] = new ListBuffer[T]): | ||
final def add(e: T): Unit = inner.addOne(e) | ||
final def elements: Seq[T] = inner | ||
|
||
final def add(e: T): MdUnit = { | ||
inner = inner :+ e | ||
}.asInstanceOf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package halotukozak.smark | ||
package utils | ||
|
||
private[smark] trait MdElement extends HasInner[MdContent]: | ||
def eval: String | ||
|
||
final protected def evaluated: Seq[String] = elements.map(_.eval) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters