@@ -17,7 +17,13 @@ object TemporaryDirectivesParser {
17
17
P (usingTpe | requireTpe)
18
18
}
19
19
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 ).! )
21
27
def charInQuote = P (
22
28
CharPred (c => c != '"' && c != '\\ ' ).! |
23
29
P (" \\\\ " ).map(_ => " \\ " ) |
@@ -26,9 +32,16 @@ object TemporaryDirectivesParser {
26
32
def quotedElem = P (" \" " ~ charInQuote.rep ~ " \" " ).map(_.mkString)
27
33
def elem = P (simpleElem | quotedElem)
28
34
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))
32
45
}
33
46
}
34
47
@@ -37,7 +50,7 @@ object TemporaryDirectivesParser {
37
50
P (directive.? )
38
51
}
39
52
40
- private def parseDirective (content : String , fromIndex : Int ): Option [(Directive , Int )] = {
53
+ private def parseDirective (content : String , fromIndex : Int ): Option [(Seq [ Directive ] , Int )] = {
41
54
// TODO Don't create a new String here
42
55
val res = parse(content.drop(fromIndex), maybeDirective(_))
43
56
res.fold((err, idx, _) => sys.error(err), (dirOpt, idx) => dirOpt.map((_, idx + fromIndex)))
@@ -48,7 +61,7 @@ object TemporaryDirectivesParser {
48
61
def helper (fromIndex : Int , acc : List [Directive ]): (List [Directive ], Int ) =
49
62
parseDirective(content, fromIndex) match {
50
63
case None => (acc.reverse, fromIndex)
51
- case Some ((dir, newIndex)) => helper(newIndex, dir :: acc)
64
+ case Some ((dir, newIndex)) => helper(newIndex, dir.toList : :: acc)
52
65
}
53
66
54
67
val (directives, codeStartsAt) = helper(0 , Nil )
0 commit comments