Skip to content

Commit 96aa8ca

Browse files
authored
Merge pull request #67 from Gedochao/maintenance/remove-comments-support
Remove `/* (...) */` comments support
2 parents f904a1c + d387684 commit 96aa8ca

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

src/main/java/com/virtuslab/using_directives/custom/Scanner.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private boolean doFetchToken() {
188188
reader.nextChar();
189189
getOperatorRest();
190190
} else if (ch == '/') {
191-
if (skipComment()) return true;
191+
if (skipLine()) return true;
192192
else {
193193
putChar('/');
194194
getOperatorRest();
@@ -272,46 +272,18 @@ private boolean doFetchToken() {
272272
}
273273

274274
// Unsupported: Keeping comments
275-
private boolean skipComment() {
275+
private boolean skipLine() {
276276
Runnable skipLine =
277277
() -> {
278278
reader.nextChar();
279279
while (reader.ch != CR && reader.ch != LF && reader.ch != SU) {
280280
reader.nextChar();
281281
}
282282
};
283-
Runnable skipComment =
284-
() -> {
285-
int nested = 0;
286-
boolean flag = true;
287-
while (flag) {
288-
if (reader.ch == '/') {
289-
reader.nextChar();
290-
if (reader.ch == '*') {
291-
nested += 1;
292-
reader.nextChar();
293-
}
294-
} else if (reader.ch == '*') {
295-
reader.nextChar();
296-
if (reader.ch == '/') {
297-
if (nested > 0) {
298-
nested -= 1;
299-
} else flag = false;
300-
reader.nextChar();
301-
}
302-
} else {
303-
reader.nextChar();
304-
}
305-
}
306-
};
307283
reader.nextChar();
308284
if (reader.ch == '/') {
309285
skipLine.run();
310286
return true;
311-
} else if (reader.ch == '*') {
312-
reader.nextChar();
313-
skipComment.run();
314-
return true;
315287
} else {
316288
return false;
317289
}
@@ -378,7 +350,7 @@ public void getOperatorRest() {
378350
break;
379351
case '/':
380352
char nxch = reader.lookaheadChar();
381-
if (nxch == '/' || nxch == '*') finishNamed(Tokens.IDENTIFIER, td);
353+
if (nxch == '/') finishNamed(Tokens.IDENTIFIER, td);
382354
else {
383355
putChar(reader.ch);
384356
reader.nextChar();

src/test/java/com/virtuslab/using_directives/parser/ParserUnitTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,23 @@ public void testListJustComma() {
187187
assertValueListSize(parsedDirective, "keyA", 1);
188188
assertValueListAtPath(parsedDirective, "keyA", List.of("0,2,3"));
189189
}
190+
191+
@Test
192+
public void testAsterisksAndSlashes() {
193+
String input = "//> using exclude */*/Foo.scala";
194+
UsingDirectives parsedDirective = testCode(1, input);
195+
assertValueListSize(parsedDirective, "exclude", 1);
196+
assertValueListAtPath(parsedDirective, "exclude", List.of("*/*/Foo.scala"));
197+
}
198+
199+
@Test
200+
public void oldCommentsArentSkipped() {
201+
String input = "//> using /* comment1 */ notTheKeyActually /* comment2 */ 42";
202+
UsingDirectives parsedDirective = testCode(1, input);
203+
assertValueListSize(parsedDirective, "/*", 7);
204+
assertValueListAtPath(
205+
parsedDirective,
206+
"/*",
207+
List.of("comment1", "*/", "notTheKeyActually", "/*", "comment2", "*/", "42"));
208+
}
190209
}

0 commit comments

Comments
 (0)