Skip to content

Commit f40f126

Browse files
authored
Merge pull request #358 from lwronski/using-directives-space
Accept //using directive without a space
2 parents bc2f815 + cb9c30e commit f40f126

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

modules/build/src/main/scala/scala/build/preprocessing/TemporaryDirectivesParser.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@ import scala.build.preprocessing.directives.Directive
99
object TemporaryDirectivesParser {
1010

1111
private def ws[_: P] = P(" ".rep(1))
12+
private def optWs[_: P] = P(" ".rep(0))
1213
private def nl[_: P] = P(("\r".? ~ "\n").rep(1))
1314
private def emptyLine[_: P] = P(ws.rep() ~ nl)
1415

1516
private def singleLineComment[_: P] =
16-
P(ws.rep() ~ !("//" ~ ws ~ "require") ~ !("//" ~ ws ~ "using") ~ "//" ~ P(CharPred(c =>
17+
P(ws.rep() ~ !("//" ~ optWs ~ "require") ~ !("//" ~ optWs ~ "using") ~ "//" ~ P(CharPred(c =>
1718
c != '\n'
1819
)).rep() ~ nl)
1920
.map(_ => ())
2021

2122
private def directive[_: P] = {
2223
def sc = P(";")
2324
def tpe = {
24-
def commentedUsingTpe = P("//" ~ ws ~ Index ~ "using")
25+
def commentedUsingTpe = P("//" ~ optWs ~ Index ~ "using")
2526
.map(actualStartIdx => (Directive.Using: Directive.Type, Some(actualStartIdx)))
2627
def usingKeywordTpe = P("using")
2728
.map(_ => (Directive.Using: Directive.Type, None))
2829
def usingTpe = P(ws.? ~ (commentedUsingTpe | usingKeywordTpe) ~ !(ws ~ "target"))
29-
def commentedRequireTpe = P("//" ~ ws ~ Index ~ "require")
30+
def commentedRequireTpe = P("//" ~ optWs ~ Index ~ "require")
3031
.map(actualStartIdx => (Directive.Require: Directive.Type, Some(actualStartIdx)))
3132
def requireKeywordTpe = P("require")
3233
.map(_ => (Directive.Require: Directive.Type, None))
33-
def commentedUsingTargetTpe = P("//" ~ ws ~ Index ~ "using" ~ ws ~ "target")
34+
def commentedUsingTargetTpe = P("//" ~ optWs ~ Index ~ "using" ~ ws ~ "target")
3435
.map(actualStartIdx => (Directive.Require: Directive.Type, Some(actualStartIdx)))
3536
def usingTargetKeywordTpe = P("using" ~ ws ~ "target")
3637
.map(_ => (Directive.Require: Directive.Type, None))

modules/build/src/test/scala/scala/build/tests/TemporaryDirectivesParserTests.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ class TemporaryDirectivesParserTests extends munit.FunSuite {
3636
expect(res == expectedRes)
3737
}
3838

39+
test("no spaces after //") {
40+
val res = TemporaryDirectivesParser.parseDirectives(
41+
Left(""),
42+
"""//using foo
43+
|//require foo
44+
|""".stripMargin
45+
).map(_._1)
46+
val expectedRes = Some(
47+
Seq(
48+
Directive(
49+
Directive.Using,
50+
Seq("foo"),
51+
None,
52+
isComment = true,
53+
Position.File(Left(""), (0, 2), (0, 11))
54+
),
55+
Directive(
56+
Directive.Require,
57+
Seq("foo"),
58+
None,
59+
isComment = true,
60+
Position.File(Left(""), (1, 2), (1, 14))
61+
)
62+
)
63+
)
64+
expect(res == expectedRes)
65+
}
66+
3967
test("using target as require") {
4068
val res = TemporaryDirectivesParser.parseDirectives(
4169
Left(""),

0 commit comments

Comments
 (0)