Skip to content

Commit 12f1a52

Browse files
Merge pull request #131 from alexarchambault/tweak-using-syntax
Tweak using syntax
2 parents e2fdfbf + 5ae7e35 commit 12f1a52

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ object TemporaryDirectivesParser {
1717
P(usingTpe | requireTpe)
1818
}
1919

20-
def simpleElem = P(CharPred(c => !c.isWhitespace && c != '"').rep(1).!)
20+
def simpleElemChar = P(
21+
CharPred(c => !c.isWhitespace && c != '"' && c != ',') |
22+
P("\\\\").map(_ => "\\") |
23+
P("\\\"").map(_ => "\"") |
24+
P("\\,").map(_ => ",")
25+
)
26+
def simpleElem = P(simpleElemChar.rep(1).!)
2127
def charInQuote = P(
2228
CharPred(c => c != '"' && c != '\\').! |
2329
P("\\\\").map(_ => "\\") |
@@ -26,9 +32,16 @@ object TemporaryDirectivesParser {
2632
def quotedElem = P("\"" ~ charInQuote.rep ~ "\"").map(_.mkString)
2733
def elem = P(simpleElem | quotedElem)
2834

29-
P(tpe ~ ws ~ elem ~ (ws ~ elem).rep(0) ~ nl.? ~ sc.? ~ nl.?).map {
30-
case (tpe0, firstElem, otherElems) =>
31-
Directive(tpe0, firstElem +: otherElems)
35+
def parser = P(
36+
tpe ~ ws ~
37+
elem.rep(1, sep = P(ws)).rep(1, sep = P(ws.? ~ "," ~ ws.?)) ~
38+
nl.? ~ sc.? ~
39+
nl.?
40+
)
41+
42+
parser.map {
43+
case (tpe0, allElems) =>
44+
allElems.map(elems => Directive(tpe0, elems))
3245
}
3346
}
3447

@@ -37,7 +50,7 @@ object TemporaryDirectivesParser {
3750
P(directive.?)
3851
}
3952

40-
private def parseDirective(content: String, fromIndex: Int): Option[(Directive, Int)] = {
53+
private def parseDirective(content: String, fromIndex: Int): Option[(Seq[Directive], Int)] = {
4154
// TODO Don't create a new String here
4255
val res = parse(content.drop(fromIndex), maybeDirective(_))
4356
res.fold((err, idx, _) => sys.error(err), (dirOpt, idx) => dirOpt.map((_, idx + fromIndex)))
@@ -48,7 +61,7 @@ object TemporaryDirectivesParser {
4861
def helper(fromIndex: Int, acc: List[Directive]): (List[Directive], Int) =
4962
parseDirective(content, fromIndex) match {
5063
case None => (acc.reverse, fromIndex)
51-
case Some((dir, newIndex)) => helper(newIndex, dir :: acc)
64+
case Some((dir, newIndex)) => helper(newIndex, dir.toList ::: acc)
5265
}
5366

5467
val (directives, codeStartsAt) = helper(0, Nil)

modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
146146
val successfulWeaverInputs = TestInputs(
147147
Seq(
148148
os.rel / "MyTests.scala" ->
149-
"""using "com.disneystreaming::weaver-cats:0.7.6"
150-
|using "com.eed3si9n.expecty::expecty:0.15.4+5-f1d8927e-SNAPSHOT"
149+
"""using com.disneystreaming::weaver-cats:0.7.6, com.eed3si9n.expecty::expecty:0.15.4+5-f1d8927e-SNAPSHOT
151150
|import weaver._
152151
|import cats.effect.IO
153152
|

0 commit comments

Comments
 (0)