diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFA.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFA.kt index ea8f56dac..6a71b3759 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFA.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFA.kt @@ -158,13 +158,13 @@ internal class NFA private constructor( val newStart = NFAState() val newEnd = NFAState() - newStart.assertion = NFAAssertion( + newStart.assertions.add(NFAAssertion( shouldConsume, isPositive, startState, acceptState, newEnd - ) + )) acceptState = newEnd startState = newStart @@ -229,10 +229,10 @@ internal class NFA private constructor( epsilonVisited: Set<NFAState> = HashSet() ): NFASimulationResult { updateCaptureGroups(editor, currentIndex, currentState) - currentState.assertion?.let { - val assertionResult = handleAssertion(editor, currentIndex, isCaseInsensitive, it) - if (!assertionResult.simulationResult) return NFASimulationResult(false, currentIndex) - else return simulate(editor, assertionResult.index, currentState.assertion!!.jumpTo, targetState, isCaseInsensitive) + for (assertion in currentState.assertions) { + val assertionResult = handleAssertion(editor, currentIndex, isCaseInsensitive, assertion) + return if (!assertionResult.simulationResult) NFASimulationResult(false, currentIndex) + else simulate(editor, assertionResult.index, assertion.jumpTo, targetState, isCaseInsensitive) } if (currentState === targetState) return NFASimulationResult(true, currentIndex) diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFAState.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFAState.kt index b8a6cccd3..cbb8fb487 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFAState.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/nfa/NFAState.kt @@ -21,10 +21,10 @@ internal class NFAState { internal val transitions: ArrayList<NFATransition> = ArrayList() /** - * If this is not null, then when simulation reaches this state, - * it has to check if this assertion is successful to continue. + * When a state has assertions, they have to be asserted + * 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