[CMI] Parse description of meta info and save it to ParsedCodeMetaInfo
This commit is contained in:
+20
-10
@@ -8,11 +8,16 @@ package org.jetbrains.kotlin.codeMetaInfo
|
||||
import org.jetbrains.kotlin.codeMetaInfo.model.ParsedCodeMetaInfo
|
||||
|
||||
object CodeMetaInfoParser {
|
||||
private val openingRegex = "(<!([^>]+?)!>)".toRegex()
|
||||
private val closingRegex = "(<!>)".toRegex()
|
||||
private val openingRegex = """(<!([^>]+?)!>)""".toRegex()
|
||||
private val closingRegex = """(<!>)""".toRegex()
|
||||
|
||||
private val descriptionRegex = "\\(\".*?\"\\)".toRegex()
|
||||
private val platformRegex = "\\{(.+)}".toRegex()
|
||||
/*
|
||||
* ([\S&&[^,(){}]]+) -- tag, allowing all non-space characters except bracers and curly bracers
|
||||
* ([{](.*?)[}])? -- list of platforms
|
||||
* (\("(.*?)"\))? -- arguments of meta info
|
||||
* (, )? -- possible separator between different infos
|
||||
*/
|
||||
private val tagRegex = """([\S&&[^,(){}]]+)([{](.*?)[}])?(\("(.*?)"\))?(, )?""".toRegex()
|
||||
|
||||
fun getCodeMetaInfoFromText(renderedText: String): List<ParsedCodeMetaInfo> {
|
||||
var text = renderedText
|
||||
@@ -48,14 +53,19 @@ object CodeMetaInfoParser {
|
||||
while (!openingMatchResults.isEmpty()) {
|
||||
val openingMatchResult = openingMatchResults.removeLast()
|
||||
val closingMatchResult = closingMatchResults.removeLast()
|
||||
val metaInfoWithoutParams = openingMatchResult.groups[2]!!.value.replace(descriptionRegex, "")
|
||||
metaInfoWithoutParams.split(",").forEach {
|
||||
val tag = platformRegex.replace(it, "").trim()
|
||||
val platforms =
|
||||
if (platformRegex.containsMatchIn(it)) platformRegex.find(it)!!.destructured.component1().split(";") else listOf()
|
||||
val allMetaInfos = openingMatchResult.groups[2]!!.value
|
||||
tagRegex.findAll(allMetaInfos).map { it.groups }.forEach {
|
||||
val tag = it[1]!!.value
|
||||
val platforms = it[3]?.value?.split(";") ?: emptyList()
|
||||
val description = it[5]?.value
|
||||
|
||||
result.add(
|
||||
ParsedCodeMetaInfo(
|
||||
openingMatchResult.range.first, closingMatchResult.range.first, platforms.toMutableList(), tag,
|
||||
openingMatchResult.range.first,
|
||||
closingMatchResult.range.first,
|
||||
platforms.toMutableList(),
|
||||
tag,
|
||||
description
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+2
-1
@@ -11,7 +11,8 @@ class ParsedCodeMetaInfo(
|
||||
override val start: Int,
|
||||
override val end: Int,
|
||||
override val platforms: MutableList<String>,
|
||||
private val tag: String
|
||||
private val tag: String,
|
||||
val description: String?
|
||||
) : CodeMetaInfo {
|
||||
override val renderConfiguration = object : AbstractCodeMetaInfoRenderConfiguration(false) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user