Skip to content

Commit

Permalink
Started using
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jan 23, 2025
1 parent d8fc54f commit b617c57
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/kaleidoscope.Kaleidoscope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object Kaleidoscope:
halt(RegexError(exception.getIndex, RegexError.Reason.InvalidPattern).message)

if types.length == 0 then '{NoExtraction(${Expr(parts.head)})}
else (tupleType.asType: @unchecked) match
else tupleType.asType.runtimeChecked match
case '[resultType] => '{RExtractor[Option[resultType]](${Expr(parts)})}

class NoExtraction(pattern: String):
Expand Down
2 changes: 1 addition & 1 deletion src/core/kaleidoscope.Regex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object Regex:
def apply(text: Text): Regex raises RegexError = parse(List(text))

def parse(parts: List[Text]): Regex raises RegexError =
(parts: @unchecked) match
parts.runtimeChecked match
case head :: tail =>
if !tail.all(_.s.startsWith("(")) then abort(RegexError(0, ExpectedGroup))

Expand Down
16 changes: 8 additions & 8 deletions src/test/kaleidoscope.Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -251,49 +251,49 @@ object Tests extends Suite(t"Kaleidoscope tests"):

suite(t"Match tests"):
test(t"simple match"):
(t"hello world": @unchecked) match
t"hello world".runtimeChecked match
case r"hello world" => 1

. assert(_ == 1)

test(t"basic extractor"):
(t"hello world": @unchecked) match
t"hello world".runtimeChecked match
case r"(hello world)" => 2

. assert(_ == 2)

test(t"extract one word"):
(t"hello world": @unchecked) match
t"hello world".runtimeChecked match
case r"$first(hello) world" => first.show

. check(_ == t"hello")

test(t"extract a nested capture group"):
(t"hello world": @unchecked) match
t"hello world".runtimeChecked match
case r"(($first(hello)) world)" => first.show

. assert(_ == t"hello")

test(t"extract words"):
(t"hello world": @unchecked) match
t"hello world".runtimeChecked match
case r"$first(hello) $second(world)" => List(first, second)

. assert(_ == List(t"hello", t"world"))

test(t"skipped capture group"):
(t"hello world": @unchecked) match
t"hello world".runtimeChecked match
case r"(hello) $second(world)" => second.show

. assert(_ == t"world")

test(t"skipped capture group 2"):
(t"1 2 3 4 5": @unchecked) match
t"1 2 3 4 5".runtimeChecked match
case r"1 $two(2) 3 4 5" => two.show

. assert(_ == t"2")

test(t"nested unbound capture group"):
(t"anyval": @unchecked) match
t"anyval".runtimeChecked match
case r"$x(any(val))" => x.show
. assert(_ == t"anyval")

Expand Down

0 comments on commit b617c57

Please sign in to comment.