forked from JetBrains/markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkerBlock.kt
66 lines (52 loc) · 2.29 KB
/
MarkerBlock.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.intellij.markdown.parser.markerblocks
import org.intellij.markdown.IElementType
import org.intellij.markdown.parser.LookaheadText
import org.intellij.markdown.parser.ProductionHolder
import org.intellij.markdown.parser.constraints.MarkdownConstraints
interface MarkerBlock {
fun getNextInterestingOffset(pos: LookaheadText.Position): Int
fun isInterestingOffset(pos: LookaheadText.Position): Boolean
fun allowsSubBlocks(): Boolean
fun processToken(pos: LookaheadText.Position,
currentConstraints: MarkdownConstraints): ProcessingResult
fun getBlockConstraints(): MarkdownConstraints
/**
* @param action to accept
* @return true if this block is to be deleted after this action, false otherwise
*/
fun acceptAction(action: ClosingAction): Boolean
enum class ClosingAction {
DONE {
override fun doAction(marker: ProductionHolder.Marker, type: IElementType) {
marker.done(type)
}
},
DROP {
override fun doAction(marker: ProductionHolder.Marker, type: IElementType) {
}
},
DEFAULT {
override fun doAction(marker: ProductionHolder.Marker, type: IElementType) {
throw UnsupportedOperationException("Should not be invoked")
}
},
NOTHING {
override fun doAction(marker: ProductionHolder.Marker, type: IElementType) {
}
};
abstract fun doAction(marker: ProductionHolder.Marker, `type`: IElementType)
}
enum class EventAction {
PROPAGATE,
CANCEL
}
class ProcessingResult internal constructor(val childrenAction: ClosingAction,
val selfAction: ClosingAction,
val eventAction: EventAction) {
companion object {
val PASS: ProcessingResult = ProcessingResult(ClosingAction.NOTHING, ClosingAction.NOTHING, EventAction.PROPAGATE)
val CANCEL: ProcessingResult = ProcessingResult(ClosingAction.NOTHING, ClosingAction.NOTHING, EventAction.CANCEL)
val DEFAULT: ProcessingResult = ProcessingResult(ClosingAction.DEFAULT, ClosingAction.DONE, EventAction.PROPAGATE)
}
}
}