@@ -10,7 +10,7 @@ import collection.JavaConverters._
1010import dotty .tools .scaladoc .tasty .comments .markdown .ExtendedFencedCodeBlock
1111
1212object 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 = {
1414 lazy val cf : SnippetChecker .SnippetCheckingFunc = checkingFunc
1515
1616 val nodes = root.getDescendants().asScala.collect {
@@ -20,27 +20,37 @@ object FlexmarkSnippetProcessor:
2020 nodes.foreach { node =>
2121 val snippet = node.getContentChars.toString
2222 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+ }
4150
42- node.insertBefore(new ExtendedFencedCodeBlock (node, snippetCompilationResult))
43- node.unlink()
51+ node.insertBefore(new ExtendedFencedCodeBlock (node, snippetCompilationResult))
52+ node.unlink()
53+ }
4454 }
4555
4656 root
0 commit comments