Skip to content

Commit 08ee811

Browse files
Accept several namespaces in "// using"
1 parent ce5e346 commit 08ee811

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ object TemporaryDirectivesParser {
1212
private def emptyLine[_: P] = P(ws.rep() ~ nl)
1313

1414
private def singleLineComment[_: P] =
15-
P(ws.rep() ~ !"// require" ~ !"// using" ~ "//" ~ P(CharPred(c => c != '\n')).rep() ~ nl)
15+
P(ws.rep() ~ !("//" ~ ws ~ "require") ~ !("//" ~ ws ~ "using") ~ "//" ~ P(CharPred(c =>
16+
c != '\n'
17+
)).rep() ~ nl)
1618
.map(_ => ())
1719

1820
private def directive[_: P] = {
1921
def sc = P(";")
2022
def tpe = {
21-
def commentedUsingTpe = P("// using")
23+
def commentedUsingTpe = P("//" ~ ws ~ "using")
2224
.map(_ => (Directive.Using: Directive.Type, true))
2325
def usingKeywordTpe = P("using")
2426
.map(_ => (Directive.Using: Directive.Type, false))
2527
def usingTpe = P(ws.? ~ (commentedUsingTpe | usingKeywordTpe))
26-
def commentedRequireTpe = P("// require")
28+
def commentedRequireTpe = P("//" ~ ws ~ "require")
2729
.map(_ => (Directive.Require: Directive.Type, true))
2830
def requireKeywordTpe = P("require")
2931
.map(_ => (Directive.Require: Directive.Type, false))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package scala.build.tests
2+
3+
import com.eed3si9n.expecty.Expecty.expect
4+
5+
import scala.build.preprocessing.TemporaryDirectivesParser
6+
import scala.build.preprocessing.directives.Directive
7+
8+
class TemporaryDirectivesParserTests extends munit.FunSuite {
9+
10+
test("spaces") {
11+
val res = TemporaryDirectivesParser.parseDirectives(
12+
"""// using foo
13+
|// using a
14+
|""".stripMargin
15+
).map(_._1)
16+
val expectedRes = Some(
17+
Seq(
18+
Directive(Directive.Using, Seq("foo"), None, isComment = true),
19+
Directive(Directive.Using, Seq("a"), None, isComment = true)
20+
)
21+
)
22+
expect(res == expectedRes)
23+
}
24+
25+
}

0 commit comments

Comments
 (0)