@@ -10,7 +10,7 @@ import collection.JavaConverters._
10
10
import dotty .tools .scaladoc .tasty .comments .markdown .ExtendedFencedCodeBlock
11
11
12
12
object FlexmarkSnippetProcessor :
13
- def processSnippets (root : mdu.Node , debug : Boolean , checkingFunc : => SnippetChecker .SnippetCheckingFunc ): mdu.Node = {
13
+ def processSnippets (root : mdu.Node , debug : Boolean , checkingFunc : => SnippetChecker .SnippetCheckingFunc )( using CompilerContext ) : mdu.Node = {
14
14
lazy val cf : SnippetChecker .SnippetCheckingFunc = checkingFunc
15
15
16
16
val nodes = root.getDescendants().asScala.collect {
@@ -20,27 +20,37 @@ object FlexmarkSnippetProcessor:
20
20
nodes.foreach { node =>
21
21
val snippet = node.getContentChars.toString
22
22
val lineOffset = node.getStartLineNumber
23
- val info = node.getInfo.toString
24
- val argOverride =
25
- info.split(" " )
26
- .find(_.startsWith(" sc:" ))
27
- .map(_.stripPrefix(" sc:" ))
28
- .map(SCFlagsParser .parse)
29
- .flatMap(_.toOption)
30
- val snippetCompilationResult = cf(snippet, lineOffset, argOverride) match {
31
- case result@ Some (SnippetCompilationResult (wrapped, _, _, _)) if debug =>
32
- val s = sequence.BasedSequence .EmptyBasedSequence ()
33
- .append(wrapped)
34
- .append(sequence.BasedSequence .EOL )
35
- val content = mdu.BlockContent ()
36
- content.add(s, 0 )
37
- node.setContent(content)
38
- result
39
- case result => result
40
- }
23
+ val info = node.getInfo.toString.split(" " )
24
+ if info.contains(" scala" ) then {
25
+ val argOverride =
26
+ info
27
+ .find(_.startsWith(" sc:" ))
28
+ .map(_.stripPrefix(" sc:" ))
29
+ .map(SCFlagsParser .parse)
30
+ .flatMap(_ match {
31
+ case Right (flags) => Some (flags)
32
+ case Left (error) =>
33
+ report.warning(
34
+ s """ |Error occured during parsing flags in snippet:
35
+ | $error""" .stripMargin
36
+ )
37
+ None
38
+ })
39
+ val snippetCompilationResult = cf(snippet, lineOffset, argOverride) match {
40
+ case result@ Some (SnippetCompilationResult (wrapped, _, _, _)) if debug =>
41
+ val s = sequence.BasedSequence .EmptyBasedSequence ()
42
+ .append(wrapped)
43
+ .append(sequence.BasedSequence .EOL )
44
+ val content = mdu.BlockContent ()
45
+ content.add(s, 0 )
46
+ node.setContent(content)
47
+ result
48
+ case result => result
49
+ }
41
50
42
- node.insertBefore(new ExtendedFencedCodeBlock (node, snippetCompilationResult))
43
- node.unlink()
51
+ node.insertBefore(new ExtendedFencedCodeBlock (node, snippetCompilationResult))
52
+ node.unlink()
53
+ }
44
54
}
45
55
46
56
root
0 commit comments