Skip to content

Commit

Permalink
Use new convention for unsafe methods
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Oct 16, 2023
1 parent 3159d8a commit a9155a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/core/kaleidoscope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ extension (inline ctx: StringContext)
transparent inline def g: Any = ${Kaleidoscope.glob('ctx)}

class NoExtraction(pattern: String):
inline def apply(): Regex = Regex.unsafeParse(List(pattern))
inline def apply(): Regex = Regex.make(List(pattern))(using Unsafe)
def unapply(scrutinee: Text): Boolean =
Regex.unsafeParse(List(pattern)).matches(scrutinee)
Regex.make(List(pattern))(using Unsafe).matches(scrutinee)

class Extractor[ResultType](parts: Seq[String]):
def unapply(scrutinee: Text): ResultType =
val result = Regex.unsafeParse(parts).matchGroups(scrutinee)
val result = Regex.make(parts)(using Unsafe).matchGroups(scrutinee)
if parts.length == 2 then result.map(_.head).asInstanceOf[ResultType]
else result.map(Tuple.fromIArray(_)).asInstanceOf[ResultType]

Expand Down
2 changes: 1 addition & 1 deletion src/core/regex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object Regex:
if quantifier.unitary then (index2, Text(s"($groupName$subpattern)"))
else (index2, Text(s"($groupName($subpattern)${quantifier.serialize}${greed.serialize})"))

def unsafeParse(parts: Seq[String]): Regex =
def make(parts: Seq[String])(using Unsafe.type): Regex =
import errorHandlers.throwUnsafely
parse(parts.to(List).map(Text(_)))

Expand Down

0 comments on commit a9155a3

Please sign in to comment.