mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-07-30 00:59:08 +02:00
commenting new classes
This commit is contained in:
parent
1c4a6b2274
commit
232f81ff48
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/engine
@ -12,14 +12,30 @@ import com.maddyhome.idea.vim.api.VimEditor
|
|||||||
import com.maddyhome.idea.vim.regexp.VimRegexErrors
|
import com.maddyhome.idea.vim.regexp.VimRegexErrors
|
||||||
import com.maddyhome.idea.vim.regexp.engine.nfa.NFA
|
import com.maddyhome.idea.vim.regexp.engine.nfa.NFA
|
||||||
import com.maddyhome.idea.vim.regexp.engine.strategies.BacktrackingStrategy
|
import com.maddyhome.idea.vim.regexp.engine.strategies.BacktrackingStrategy
|
||||||
|
import com.maddyhome.idea.vim.regexp.engine.strategies.SimulationResult
|
||||||
import com.maddyhome.idea.vim.regexp.engine.strategies.SimulationStrategy
|
import com.maddyhome.idea.vim.regexp.engine.strategies.SimulationStrategy
|
||||||
import com.maddyhome.idea.vim.regexp.match.VimMatchResult
|
import com.maddyhome.idea.vim.regexp.match.VimMatchResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A meta-engine for simulating a nfa. It combines strategies that can be used to simulate the nfa,
|
||||||
|
* some more powerful but slower, others less powerful but faster. The engine combines these strategies,
|
||||||
|
* in order to always use the strategy that is less powerful (and thus faster), but powerful enough to
|
||||||
|
* simulate the nfa.
|
||||||
|
* This is a singleton.
|
||||||
|
*/
|
||||||
internal object VimRegexEngine {
|
internal object VimRegexEngine {
|
||||||
|
|
||||||
// TODO: optimize by adding more strategies. The strategies should go from less powerful but faster, to more powerful but slower
|
// TODO: optimize by adding more strategies. The strategies should go from less powerful but faster, to more powerful but slower
|
||||||
|
/**
|
||||||
|
* The list of strategies that the engine has available. They should be ordered from less powerful to more powerful.
|
||||||
|
*/
|
||||||
private val strategies: List<SimulationStrategy> = listOf(BacktrackingStrategy())
|
private val strategies: List<SimulationStrategy> = listOf(BacktrackingStrategy())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulate the nfa using the available strategies. The approach used is very simple: start with the least powerful
|
||||||
|
* strategy; if this strategy is powerful enough to determine if there is a match, return that match. If it isn't
|
||||||
|
* powerful enough, use the next (more powerful) strategy.
|
||||||
|
*/
|
||||||
internal fun simulate(nfa: NFA, editor: VimEditor, startIndex: Int = 0, isCaseInsensitive: Boolean = false): VimMatchResult {
|
internal fun simulate(nfa: NFA, editor: VimEditor, startIndex: Int = 0, isCaseInsensitive: Boolean = false): VimMatchResult {
|
||||||
for (strategy in strategies) {
|
for (strategy in strategies) {
|
||||||
val result = strategy.simulate(nfa, editor, startIndex, isCaseInsensitive)
|
val result = strategy.simulate(nfa, editor, startIndex, isCaseInsensitive)
|
||||||
|
@ -11,7 +11,6 @@ package com.maddyhome.idea.vim.regexp.engine.strategies
|
|||||||
import com.maddyhome.idea.vim.api.VimCaret
|
import com.maddyhome.idea.vim.api.VimCaret
|
||||||
import com.maddyhome.idea.vim.api.VimEditor
|
import com.maddyhome.idea.vim.api.VimEditor
|
||||||
import com.maddyhome.idea.vim.regexp.VimRegexErrors
|
import com.maddyhome.idea.vim.regexp.VimRegexErrors
|
||||||
import com.maddyhome.idea.vim.regexp.engine.SimulationResult
|
|
||||||
import com.maddyhome.idea.vim.regexp.engine.nfa.NFA
|
import com.maddyhome.idea.vim.regexp.engine.nfa.NFA
|
||||||
import com.maddyhome.idea.vim.regexp.engine.nfa.NFAAssertion
|
import com.maddyhome.idea.vim.regexp.engine.nfa.NFAAssertion
|
||||||
import com.maddyhome.idea.vim.regexp.engine.nfa.NFAState
|
import com.maddyhome.idea.vim.regexp.engine.nfa.NFAState
|
||||||
@ -22,7 +21,7 @@ import com.maddyhome.idea.vim.regexp.match.VimMatchResult
|
|||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses a backtracking base strategy to simulate the nfa. This strategy is very powerful, since it
|
* Uses a backtracking based strategy to simulate the nfa. This strategy is very powerful, since it
|
||||||
* can be used with any nfa, but comes at the cost of speed.
|
* can be used with any nfa, but comes at the cost of speed.
|
||||||
*/
|
*/
|
||||||
internal class BacktrackingStrategy : SimulationStrategy {
|
internal class BacktrackingStrategy : SimulationStrategy {
|
||||||
|
@ -6,11 +6,23 @@
|
|||||||
* https://opensource.org/licenses/MIT.
|
* https://opensource.org/licenses/MIT.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.maddyhome.idea.vim.regexp.engine
|
package com.maddyhome.idea.vim.regexp.engine.strategies
|
||||||
|
|
||||||
import com.maddyhome.idea.vim.regexp.match.VimMatchResult
|
import com.maddyhome.idea.vim.regexp.match.VimMatchResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result of applying a SimulationStrategy.
|
||||||
|
*/
|
||||||
internal sealed class SimulationResult {
|
internal sealed class SimulationResult {
|
||||||
|
/**
|
||||||
|
* The simulation is deemed "complete" if it found a match, or if
|
||||||
|
* it can determine with absolute certainty there are no matches.
|
||||||
|
*/
|
||||||
data class Complete(val matchResult: VimMatchResult) : SimulationResult()
|
data class Complete(val matchResult: VimMatchResult) : SimulationResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The simulation is deemed "incomplete" if it just isn't powerful
|
||||||
|
* enough to determine whether there is match.
|
||||||
|
*/
|
||||||
object Incomplete : SimulationResult()
|
object Incomplete : SimulationResult()
|
||||||
}
|
}
|
@ -9,9 +9,11 @@
|
|||||||
package com.maddyhome.idea.vim.regexp.engine.strategies
|
package com.maddyhome.idea.vim.regexp.engine.strategies
|
||||||
|
|
||||||
import com.maddyhome.idea.vim.api.VimEditor
|
import com.maddyhome.idea.vim.api.VimEditor
|
||||||
import com.maddyhome.idea.vim.regexp.engine.SimulationResult
|
|
||||||
import com.maddyhome.idea.vim.regexp.engine.nfa.NFA
|
import com.maddyhome.idea.vim.regexp.engine.nfa.NFA
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A strategy that can be used to simulate a NFA
|
||||||
|
*/
|
||||||
internal interface SimulationStrategy {
|
internal interface SimulationStrategy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user