Skip to content

StdLexical now emits one ErrorToken for unclosed comments. #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class StdLexical extends Lexical with StdTokens {
whitespaceChar
| '/' ~ '*' ~ comment
| '/' ~ '/' ~ rep( chrExcept(EofCh, '\n') )
| '/' ~ '*' ~ failure("unclosed comment")
| '/' ~ '*' ~ rep( elem("", _ => true) ) ~> err("unclosed comment")
)

protected def comment: Parser[Any] = (
Expand Down
10 changes: 5 additions & 5 deletions shared/src/test/scala/scala/util/parsing/combinator/gh56.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class gh56 {
"""/* an unclosed comment
|of multiple lines
|just to check longString/lineContents
""".stripMargin
|""".stripMargin

val fail =
"""[1.1] failure: identifier expected
"""[4.1] failure: identifier expected
|
|
|/* an unclosed comment
|^""".stripMargin

val parseResult = phrase(term)(new lexical.Scanner(expr))
Expand All @@ -46,10 +46,10 @@ class gh56 {
val expr = "/* an unclosed comment without newline"

val fail =
"""[1.1] failure: identifier expected
"""[1.39] failure: identifier expected
|
|/* an unclosed comment without newline
|^""".stripMargin
| ^""".stripMargin

val parseResult = phrase(term)(new lexical.Scanner(expr))
assertTrue(parseResult.isInstanceOf[Failure])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.junit.Assert.assertEquals
import scala.util.parsing.input.Reader

import scala.collection.mutable.ListBuffer
import java.awt.RenderingHints.Key

class StdLexicalTest {
private def lex[Lexer <: StdLexical](lexer: Lexer, input: String): List[lexer.Token] = {
Expand Down Expand Up @@ -123,4 +122,20 @@ class StdLexicalTest {
lex(Lexer, "/* single */ id1 /* multi \n line */ id2")
)
}

@Test
def parseUnclosedComments: Unit = {
object Lexer extends StdLexical
import Lexer._

assertEquals(
List(Identifier("id"), ErrorToken("unclosed comment")),
lex(Lexer, "id /*")
)

assertEquals(
List(Identifier("id"), ErrorToken("unclosed comment")),
lex(Lexer, "id /* ")
)
}
}