Skip to content

Commit

Permalink
Fixed infinite loop in whitespace with no comments in LanguageDef (#…
Browse files Browse the repository at this point in the history
…119)

* Fixed bug where whitespace with no comments does not advance program counter

* Added unit test
  • Loading branch information
j-mie6 authored Apr 25, 2022
1 parent 13f2d25 commit 7f2fb16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ private [instructions] abstract class WhiteSpaceLike(start: String, end: String,
else ctx.pushAndContinue(())
}

final def spacesAndContinue(ctx: Context): Unit = {
spaces(ctx)
ctx.pushAndContinue(())
}

private final val impl = {
if (!lineAllowed && !multiAllowed) spaces(_)
if (!lineAllowed && !multiAllowed) spacesAndContinue(_)
else if (!lineAllowed) multisOnly(_)
else if (!multiAllowed) singlesOnly(_)
else singlesAndMultis(_)
Expand Down Expand Up @@ -235,4 +240,4 @@ private [internal] final class TokenMaxOp(operator: String, _ops: Set[String]) e
// $COVERAGE-OFF$
override def toString: String = s"TokenMaxOp(${operator})"
// $COVERAGE-ON$
}
}
6 changes: 6 additions & 0 deletions src/test/scala/parsley/TokeniserTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,10 @@ class TokeniserTests extends ParsleyTest {
p.parse("bye") shouldBe a [Success[_]]
p.parse("Bye") shouldBe a [Success[_]]
}

"issue #199" should "not regress: whitespace should work without comments defined" in {
val lang = token.LanguageDef.plain.copy(space = token.Predicate(_.isWhitespace))
val lexer = new token.Lexer(lang)
lexer.whiteSpace.parse("[") shouldBe a [Success[_]]
}
}

0 comments on commit 7f2fb16

Please sign in to comment.