-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,092 additions
and
743 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
hugo/src/main/scala/com/reactific/riddl/hugo/GlossaryPass.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.reactific.riddl.hugo | ||
import com.reactific.riddl.language.AST.* | ||
import com.reactific.riddl.language.Messages | ||
import com.reactific.riddl.passes.{CollectingPass, CollectingPassOutput, PassInput, PassesOutput, PassesResult} | ||
|
||
import java.nio.file.Path | ||
import scala.collection.mutable | ||
|
||
case class GlossaryEntry( | ||
term: String, | ||
kind: String, | ||
brief: String, | ||
path: Seq[String], | ||
link: String = "", | ||
sourceLink: String = "" | ||
) | ||
|
||
case class GlossaryOutput( | ||
messages: Messages.Messages, | ||
entries: Seq[GlossaryEntry] | ||
) extends CollectingPassOutput[GlossaryEntry] | ||
|
||
case class GlossaryPass( | ||
input: PassInput, | ||
outputs: PassesOutput, | ||
options: HugoCommand.Options | ||
) extends CollectingPass[GlossaryEntry](input, outputs) | ||
with PassUtilities { | ||
|
||
// Members declared in com.reactific.riddl.passes.CollectingPass | ||
protected def collect( | ||
definition: Definition, | ||
parents: mutable.Stack[Definition] | ||
): Option[GlossaryEntry] = { | ||
definition match { | ||
case _: OnMessageClause | _: OnOtherClause | _: OnInitClause | _: OnTerminationClause | _: RootContainer | | ||
_: Include[Definition] @unchecked => | ||
// None of these kinds of definitions contribute to the glossary | ||
None | ||
case d: Definition => | ||
// everything else does | ||
val stack = parents.toSeq | ||
Some(makeGlossaryEntry(definition, stack)) | ||
} | ||
} | ||
|
||
def makeGlossaryEntry( | ||
d: Definition, | ||
stack: Seq[Definition] | ||
): GlossaryEntry = { | ||
val parents = makeStringParents(stack) | ||
val entry = GlossaryEntry( | ||
d.id.value, | ||
d.kind, | ||
d.brief.map(_.s).getOrElse("-- undefined --"), | ||
parents :+ d.id.value, | ||
makeDocLink(d, parents), | ||
makeSourceLink(d) | ||
) | ||
entry | ||
} | ||
|
||
def result: GlossaryOutput = { | ||
GlossaryOutput(messages.toMessages, collectedValues) | ||
} | ||
|
||
// Members declared in com.reactific.riddl.passes.Pass | ||
def name: String = GlossaryPass.name | ||
def postProcess(root: com.reactific.riddl.language.AST.RootContainer): Unit = () | ||
} | ||
|
||
object GlossaryPass { | ||
val name: String = "Glossary" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.