Skip to content
Open
Changes from 1 commit
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
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: Boolean)

/**
* 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, false)
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 = true
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 =>
depthTracker.holes = false
advance2With(TokenKind.`}>`)
case ('}', _) if isAtInterpolationBoundary =>
interpolationDepths.pop()
depthTracker.braces -= 1
Expand Down
Loading