1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-07-30 09:59:08 +02:00

allow for a state to have multiple assertitions

This commit is contained in:
Emanuel Gestosa 2023-08-22 16:47:07 +01:00 committed by lippfi
parent b9b8d30f3b
commit c78a5d3cab
2 changed files with 9 additions and 9 deletions
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa

View File

@ -158,13 +158,13 @@ internal class NFA private constructor(
val newStart = NFAState() val newStart = NFAState()
val newEnd = NFAState() val newEnd = NFAState()
newStart.assertion = NFAAssertion( newStart.assertions.add(NFAAssertion(
shouldConsume, shouldConsume,
isPositive, isPositive,
startState, startState,
acceptState, acceptState,
newEnd newEnd
) ))
acceptState = newEnd acceptState = newEnd
startState = newStart startState = newStart
@ -229,10 +229,10 @@ internal class NFA private constructor(
epsilonVisited: Set<NFAState> = HashSet() epsilonVisited: Set<NFAState> = HashSet()
): NFASimulationResult { ): NFASimulationResult {
updateCaptureGroups(editor, currentIndex, currentState) updateCaptureGroups(editor, currentIndex, currentState)
currentState.assertion?.let { for (assertion in currentState.assertions) {
val assertionResult = handleAssertion(editor, currentIndex, isCaseInsensitive, it) val assertionResult = handleAssertion(editor, currentIndex, isCaseInsensitive, assertion)
if (!assertionResult.simulationResult) return NFASimulationResult(false, currentIndex) return if (!assertionResult.simulationResult) NFASimulationResult(false, currentIndex)
else return simulate(editor, assertionResult.index, currentState.assertion!!.jumpTo, targetState, isCaseInsensitive) else simulate(editor, assertionResult.index, assertion.jumpTo, targetState, isCaseInsensitive)
} }
if (currentState === targetState) return NFASimulationResult(true, currentIndex) if (currentState === targetState) return NFASimulationResult(true, currentIndex)

View File

@ -21,10 +21,10 @@ internal class NFAState {
internal val transitions: ArrayList<NFATransition> = ArrayList() internal val transitions: ArrayList<NFATransition> = ArrayList()
/** /**
* If this is not null, then when simulation reaches this state, * When a state has assertions, they have to be asserted
* it has to check if this assertion is successful to continue. * in order to continue with the simulation.
*/ */
internal var assertion: NFAAssertion? = null internal var assertions: ArrayList<NFAAssertion> = ArrayList()
/** /**
* Stores the numbers of the capture groups that start * Stores the numbers of the capture groups that start