aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/parsers/Parser.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-07-17 16:36:09 +0200
committerPaweł Marks <pmarks@virtuslab.com>2020-07-17 16:36:09 +0200
commit6996b1135f61c7d2cb60b0652c6a2691dda31990 (patch)
treed568096c25e31c28d14d518a63458b5a7526b896 /plugins/base/src/main/kotlin/parsers/Parser.kt
parentde56cab76f556e5b4af0b8c8cb08d8b482b86d0a (diff)
parent1c3530dcbb50c347f80bef694829dbefe89eca77 (diff)
downloaddokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.gz
dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.bz2
dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.zip
Merge branch 'dev-0.11.0'
Diffstat (limited to 'plugins/base/src/main/kotlin/parsers/Parser.kt')
-rw-r--r--plugins/base/src/main/kotlin/parsers/Parser.kt42
1 files changed, 42 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/Parser.kt b/plugins/base/src/main/kotlin/parsers/Parser.kt
new file mode 100644
index 00000000..1dd0c34a
--- /dev/null
+++ b/plugins/base/src/main/kotlin/parsers/Parser.kt
@@ -0,0 +1,42 @@
+package org.jetbrains.dokka.base.parsers
+
+import org.jetbrains.dokka.model.doc.*
+
+abstract class Parser {
+
+ abstract fun parseStringToDocNode(extractedString: String): DocTag
+ abstract fun preparse(text: String): String
+
+ fun parse(text: String): DocumentationNode {
+
+ val list = jkdocToListOfPairs(preparse(text))
+
+ val mappedList: List<TagWrapper> = list.map {
+ when(it.first) {
+ "description" -> Description(parseStringToDocNode(it.second))
+ "author" -> Author(parseStringToDocNode(it.second))
+ "version" -> Version(parseStringToDocNode(it.second))
+ "since" -> Since(parseStringToDocNode(it.second))
+ "see" -> See(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' '), null)
+ "param" -> Param(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' '))
+ "property" -> Property(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' '))
+ "return" -> Return(parseStringToDocNode(it.second))
+ "constructor" -> Constructor(parseStringToDocNode(it.second))
+ "receiver" -> Receiver(parseStringToDocNode(it.second))
+ "throws", "exception" -> Throws(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' '))
+ "deprecated" -> Deprecated(parseStringToDocNode(it.second))
+ "sample" -> Sample(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' '))
+ "suppress" -> Suppress(parseStringToDocNode(it.second))
+ else -> CustomTagWrapper(parseStringToDocNode(it.second), it.first)
+ }
+ }
+ return DocumentationNode(mappedList)
+ }
+
+ private fun jkdocToListOfPairs(javadoc: String): List<Pair<String, String>> =
+ "description $javadoc"
+ .split("\n@")
+ .map {
+ it.substringBefore(' ') to it.substringAfter(' ')
+ }
+} \ No newline at end of file