Skip to content

Commit

Permalink
Switch to using Perforate
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Aug 10, 2023
1 parent 482e9df commit 3f93529
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fury
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project inimitable
module core
compiler scala
sources src/core
include rudiments/core
include rudiments/core perforate/core

module test
compiler scala
Expand Down
14 changes: 8 additions & 6 deletions src/core/uuid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package inimitable

import anticipation.*
import rudiments.*
import perforate.*
import fulminate.*

import scala.quoted.*
Expand All @@ -29,11 +30,11 @@ import language.experimental.captureChecking
case class UuidError(badUuid: Text) extends Error(msg"$badUuid is not a valid UUID")

object Uuid:
def parse(text: Text): Uuid throws UuidError =
val uuid =
try ju.UUID.fromString(text.s).nn catch case _: Exception => throw UuidError(text)

Uuid(uuid.getMostSignificantBits, uuid.getLeastSignificantBits)
def parse(text: Text)(using Raises[UuidError]): Uuid =
try
val uuid = ju.UUID.fromString(text.s).nn
Uuid(uuid.getMostSignificantBits, uuid.getLeastSignificantBits)
catch case _: Exception => raise(UuidError(text))(Uuid(0L, 0L))

def unapply(text: Text): Option[Uuid] =
try Some:
Expand All @@ -59,7 +60,8 @@ case class Uuid(msb: Long, lsb: Long):
object Inimitable:
def uuid(expr: Expr[StringContext])(using Quotes): Expr[Uuid] =
val text = expr.valueOrAbort.parts.head.tt
val uuid = try Uuid.parse(text) catch case error: UuidError => fail(error.message)
val uuid = failCompilation(Uuid.parse(text))

'{Uuid(${Expr(uuid.msb)}, ${Expr(uuid.lsb)})}

extension (inline context: StringContext)
Expand Down

0 comments on commit 3f93529

Please sign in to comment.