File tree 3 files changed +22
-6
lines changed
main/scala/scala/util/parsing/combinator/lexical
test/scala/scala/util/parsing/combinator
3 files changed +22
-6
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 @@ -123,4 +123,20 @@ class StdLexicalTest {
123
123
lex(Lexer , " /* single */ id1 /* multi \n line */ id2" )
124
124
)
125
125
}
126
+
127
+ @ Test
128
+ def parseUnclosedComments : Unit = {
129
+ object Lexer extends StdLexical
130
+ import Lexer ._
131
+
132
+ assertEquals(
133
+ List (Identifier (" id" ), ErrorToken (" unclosed comment" )),
134
+ lex(Lexer , " id /*" )
135
+ )
136
+
137
+ assertEquals(
138
+ List (Identifier (" id" ), ErrorToken (" unclosed comment" )),
139
+ lex(Lexer , " id /* " )
140
+ )
141
+ }
126
142
}
You can’t perform that action at this time.
0 commit comments