mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-02-25 02:46:01 +01:00
implementing \& operator
This commit is contained in:
parent
755b47ef19
commit
1c4538af72
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp
@ -158,13 +158,13 @@ internal class NFA private constructor(
|
||||
val newStart = NFAState()
|
||||
val newEnd = NFAState()
|
||||
|
||||
newStart.assertions.add(NFAAssertion(
|
||||
newStart.assertion = 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)
|
||||
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)
|
||||
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)
|
||||
}
|
||||
if (currentState === targetState) return NFASimulationResult(true, currentIndex)
|
||||
|
||||
|
@ -21,10 +21,10 @@ internal class NFAState {
|
||||
internal val transitions: ArrayList<NFATransition> = ArrayList()
|
||||
|
||||
/**
|
||||
* When a state has assertions, they have to be asserted
|
||||
* When a state has an assertion, it has to be asserted
|
||||
* in order to continue with the simulation.
|
||||
*/
|
||||
internal var assertions: ArrayList<NFAAssertion> = ArrayList()
|
||||
internal var assertion: NFAAssertion? = null
|
||||
|
||||
/**
|
||||
* Stores the numbers of the capture groups that start
|
||||
|
@ -60,9 +60,12 @@ internal object PatternVisitor : RegexParserBaseVisitor<NFA>() {
|
||||
val nfaStart = if (ctx.CARET() != null) NFA.fromMatcher(StartOfLineMatcher()) else NFA.fromSingleState()
|
||||
val nfaEnd = if (ctx.DOLLAR() != null) NFA.fromMatcher(EndOfLineMatcher()) else NFA.fromSingleState()
|
||||
|
||||
// TODO: handle multiple concats
|
||||
|
||||
return nfaStart.concatenate(visit(ctx.concat)).concatenate(nfaEnd)
|
||||
for (concat in ctx.concats.dropLast(1)) {
|
||||
val subNFA = visit(concat)
|
||||
subNFA.assert(shouldConsume = false, isPositive = true)
|
||||
nfaStart.concatenate(subNFA)
|
||||
}
|
||||
return nfaStart.concatenate(visit(ctx.concats.last())).concatenate(nfaEnd)
|
||||
}
|
||||
|
||||
override fun visitConcat(ctx: RegexParser.ConcatContext): NFA {
|
||||
|
Loading…
Reference in New Issue
Block a user