1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-31 16:34:06 +02:00

commenting new classes

This commit is contained in:
Emanuel Gestosa 2023-09-15 14:50:20 +01:00 committed by lippfi
parent 1c4a6b2274
commit 232f81ff48
4 changed files with 33 additions and 4 deletions
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/engine

View File

@ -12,14 +12,30 @@ import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.regexp.VimRegexErrors
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.SimulationResult
import com.maddyhome.idea.vim.regexp.engine.strategies.SimulationStrategy
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 {
// 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())
/**
* 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 {
for (strategy in strategies) {
val result = strategy.simulate(nfa, editor, startIndex, isCaseInsensitive)

View File

@ -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.VimEditor
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.NFAAssertion
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
/**
* 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.
*/
internal class BacktrackingStrategy : SimulationStrategy {

View File

@ -6,11 +6,23 @@
* 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
/**
* The result of applying a SimulationStrategy.
*/
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()
/**
* The simulation is deemed "incomplete" if it just isn't powerful
* enough to determine whether there is match.
*/
object Incomplete : SimulationResult()
}

View File

@ -9,9 +9,11 @@
package com.maddyhome.idea.vim.regexp.engine.strategies
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.regexp.engine.SimulationResult
import com.maddyhome.idea.vim.regexp.engine.nfa.NFA
/**
* A strategy that can be used to simulate a NFA
*/
internal interface SimulationStrategy {
/**