commonMain.org.intellij.markdown.parser.sequentialparsers.SequentialParser.kt Maven / Gradle / Ivy
package org.intellij.markdown.parser.sequentialparsers
import org.intellij.markdown.IElementType
interface SequentialParser {
fun parse(tokens: TokensCache, rangesToGlue: List): ParsingResult
data class Node(val range: IntRange, val type: IElementType)
interface ParsingResult {
val parsedNodes: Collection
val rangesToProcessFurther: Collection>
}
class ParsingResultBuilder : ParsingResult {
private val _parsedNodes : MutableCollection = ArrayList()
override val parsedNodes : Collection
get() = _parsedNodes
private val _rangesToProcessFurther : MutableCollection> = ArrayList()
override val rangesToProcessFurther : Collection>
get() = _rangesToProcessFurther
fun withNode(result: Node): ParsingResultBuilder {
_parsedNodes.add(result)
return this
}
fun withNodes(parsedNodes: Collection): ParsingResultBuilder {
_parsedNodes.addAll(parsedNodes)
return this
}
fun withFurtherProcessing(ranges: List): ParsingResultBuilder {
_rangesToProcessFurther.add(ranges)
return this
}
fun withOtherParsingResult(parsingResult: ParsingResult): ParsingResultBuilder {
_parsedNodes.addAll(parsingResult.parsedNodes)
_rangesToProcessFurther.addAll(parsingResult.rangesToProcessFurther)
return this
}
}
}
data class LocalParsingResult(val iteratorPosition: TokensCache.Iterator,
override val parsedNodes: Collection,
override val rangesToProcessFurther: Collection>) : SequentialParser.ParsingResult {
constructor(iteratorPosition: TokensCache.Iterator,
parsedNodes: Collection,
delegateRanges: List)
: this(iteratorPosition, parsedNodes, listOf(delegateRanges))
constructor(iteratorPosition: TokensCache.Iterator,
parsedNodes: Collection)
: this(iteratorPosition, parsedNodes, emptyList>())
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy