File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
directive-handler/src/main/scala/scala/cli/directivehandler Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ package scala .cli .directivehandler
2
+
3
+ import scala .cli .directivehandler .EitherSequence ._
4
+
5
+ final case class DirectiveHandlers [T ](handlers : Seq [DirectiveHandler [T ]]) {
6
+
7
+ private lazy val handlersMap = handlers.flatMap(h => h.keys.map(_ -> h)).toMap
8
+
9
+ def parse (
10
+ input : String ,
11
+ path : Either [String , os.Path ],
12
+ scopePath : ScopePath
13
+ ): Either [DirectiveException , Seq [ProcessedDirective [T ]]] = {
14
+
15
+ val directives = ExtractedDirectives .from(input.toCharArray, path)
16
+ .fold(e => throw e, identity)
17
+ .directives
18
+ .map(dir => ScopedDirective (dir, path, scopePath))
19
+
20
+ directives
21
+ .map { dir =>
22
+ handlersMap.get(dir.directive.key) match {
23
+ case Some (h) =>
24
+ h.handleValues(dir)
25
+ case None =>
26
+ Left (dir.unusedDirectiveError)
27
+ }
28
+ }
29
+ .sequence
30
+ .left.map(CompositeDirectiveException (_))
31
+ }
32
+
33
+ }
You can’t perform that action at this time.
0 commit comments