Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions effekt/jvm/src/test/scala/effekt/LexerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,33 @@ class LexerTests extends munit.FunSuite {
)
}

test("string splice hole") {
val prog = "<${x}>"
assertTokensEq(
prog,
`<`, `${`, Ident("x"), `}$`, `>`,
EOF
)
}

test("all holes") {
val prog = "<{<\"str\">; <>}>"
assertTokensEq(
prog,
`<{`, HoleStr("str"), `;`, `<>`, `}>`,
EOF
)
}

test("all holes imbriqued") {
val prog = "<{< <\"str\"> >}>"
assertTokensEq(
prog,
`<{`, `<`, HoleStr("str"), `>`, `}>`,
EOF
)
}

test("multiline string holes") {
val prog1: String =
"""<" Here it starts
Expand Down
12 changes: 8 additions & 4 deletions effekt/shared/src/main/scala/effekt/Lexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ object Position {
* interpolation boundaries. When we see ${, we record the current brace depth
* and know the interpolation ends when we return to that depth.
*/
case class DepthTracker(var parens: Int, var braces: Int, var brackets: Int)
case class DepthTracker(var parens: Int, var braces: Int, var brackets: Int, var holes: Int)

/**
* Never throws exceptions - always returns Error tokens for errors.
Expand All @@ -246,7 +246,7 @@ class Lexer(source: Source) extends Iterator[Token] {

// String interpolation state
private val delimiters = mutable.Stack[Delimiter]()
private val depthTracker = DepthTracker(0, 0, 0)
private val depthTracker = DepthTracker(0, 0, 0, 0)
private val interpolationDepths = mutable.Stack[Int]()

/**
Expand Down Expand Up @@ -444,7 +444,9 @@ class Lexer(source: Source) extends Iterator[Token] {
case ('<', '<') => advance2With(TokenKind.`<<`)
case ('<', '=') => advance2With(TokenKind.`<=`)
case ('<', '>') => advance2With(TokenKind.`<>`)
case ('<', '{') => advance2With(TokenKind.`<{`)
case ('<', '{') =>
depthTracker.holes += 1
advance2With(TokenKind.`<{`)
case ('<', '~') => advance2With(TokenKind.`<~`)
case ('<', _) => advanceWith(TokenKind.`<`)

Expand Down Expand Up @@ -480,7 +482,9 @@ class Lexer(source: Source) extends Iterator[Token] {
case ('$', _) =>
advanceWith(TokenKind.Error(LexerError.UnknownChar('$')))

case ('}', '>') => advance2With(TokenKind.`}>`)
case ('}', '>') if depthTracker.holes > 0 =>
depthTracker.holes -= 1
advance2With(TokenKind.`}>`)
case ('}', _) if isAtInterpolationBoundary =>
interpolationDepths.pop()
depthTracker.braces -= 1
Expand Down
2 changes: 2 additions & 0 deletions examples/pos/issue1301.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<1>
test
12 changes: 12 additions & 0 deletions examples/pos/issue1301.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def main() = {
def f() = <{def g() = <{<"myFun">}>; 42}>
val x = println(s"<${1.show}>")
def g() = <{
val x = 42 + <" here's a string ">
println(x)
<>
}>
val x = println(s"${"test"}")
def h() = println(s"<${"1" ++ <"string"> ++ <>}>")
()
}
Loading