File tree 3 files changed +22
-7
lines changed
main/scala/scala/util/parsing/combinator/lexical
test/scala/scala/util/parsing/combinator
3 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class StdLexical extends Lexical with StdTokens {
58
58
whitespaceChar
59
59
| '/' ~ '*' ~ comment
60
60
| '/' ~ '/' ~ rep( chrExcept(EofCh , '\n ' ) )
61
- | '/' ~ '*' ~ failure (" unclosed comment" )
61
+ | '/' ~ '*' ~ rep( elem( " " , _ => true ) ) ~> err (" unclosed comment" )
62
62
)
63
63
64
64
protected def comment : Parser [Any ] = (
Original file line number Diff line number Diff line change @@ -25,12 +25,12 @@ class gh56 {
25
25
""" /* an unclosed comment
26
26
|of multiple lines
27
27
|just to check longString/lineContents
28
- """ .stripMargin
28
+ | """ .stripMargin
29
29
30
30
val fail =
31
- """ [1.1] failure: identifier expected
31
+ """ [4.1] failure: identifier expected
32
+ |
32
33
|
33
- |/* an unclosed comment
34
34
|^""" .stripMargin
35
35
36
36
val parseResult = phrase(term)(new lexical.Scanner (expr))
@@ -46,10 +46,10 @@ class gh56 {
46
46
val expr = " /* an unclosed comment without newline"
47
47
48
48
val fail =
49
- """ [1.1 ] failure: identifier expected
49
+ """ [1.39 ] failure: identifier expected
50
50
|
51
51
|/* an unclosed comment without newline
52
- |^""" .stripMargin
52
+ | ^""" .stripMargin
53
53
54
54
val parseResult = phrase(term)(new lexical.Scanner (expr))
55
55
assertTrue(parseResult.isInstanceOf [Failure ])
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ import org.junit.Assert.assertEquals
6
6
import scala .util .parsing .input .Reader
7
7
8
8
import scala .collection .mutable .ListBuffer
9
- import java .awt .RenderingHints .Key
10
9
11
10
class StdLexicalTest {
12
11
private def lex [Lexer <: StdLexical ](lexer : Lexer , input : String ): List [lexer.Token ] = {
@@ -123,4 +122,20 @@ class StdLexicalTest {
123
122
lex(Lexer , " /* single */ id1 /* multi \n line */ id2" )
124
123
)
125
124
}
125
+
126
+ @ Test
127
+ def parseUnclosedComments : Unit = {
128
+ object Lexer extends StdLexical
129
+ import Lexer ._
130
+
131
+ assertEquals(
132
+ List (Identifier (" id" ), ErrorToken (" unclosed comment" )),
133
+ lex(Lexer , " id /*" )
134
+ )
135
+
136
+ assertEquals(
137
+ List (Identifier (" id" ), ErrorToken (" unclosed comment" )),
138
+ lex(Lexer , " id /* " )
139
+ )
140
+ }
126
141
}
You can’t perform that action at this time.
0 commit comments