Added new state fields to tell if a state is a question or alternation

remotes/origin/implementPCREMatchingRules
Aadhavan Srinivasan 1 month ago
parent 4e597f8eb1
commit ad0f7d0178

@ -31,6 +31,8 @@ type nfaState struct {
output []*nfaState // The outputs of the current state ie. the 'outward arrows'. A union operator state will have more than one of these.
transitions map[int][]*nfaState // Transitions to different states (maps a character (int representation) to a _list of states. This is useful if one character can lead multiple states eg. ab|aa)
isKleene bool // Identifies whether current node is a 0-state representing Kleene star
isQuestion bool // Identifies whether current node is a 0-state representing the question operator
isAlternation bool // Identifies whether current node is a 0-state representing an alternation
assert assertType // Type of assertion of current node - NONE means that the node doesn't assert anything
allChars bool // Whether or not the state represents all characters (eg. a 'dot' metacharacter). A 'dot' node doesn't store any contents directly, as it would take up too much space
except []rune // Only valid if allChars is true - match all characters _except_ the ones in this block. Useful for inverting character classes.
@ -70,6 +72,8 @@ func cloneStateHelper(stateToClone *nfaState, cloneMap map[*nfaState]*nfaState)
output: make([]*nfaState, len(stateToClone.output)),
transitions: make(map[int][]*nfaState),
isKleene: stateToClone.isKleene,
isQuestion: stateToClone.isQuestion,
isAlternation: stateToClone.isAlternation,
assert: stateToClone.assert,
zeroMatchFound: stateToClone.zeroMatchFound,
allChars: stateToClone.allChars,
@ -341,6 +345,7 @@ func alternate(s1 *nfaState, s2 *nfaState) *nfaState {
}
toReturn.content = newContents(epsilon)
toReturn.isEmpty = true
toReturn.isAlternation = true
return toReturn
}
@ -351,6 +356,7 @@ func question(s1 *nfaState) *nfaState { // Use the fact that ab? == a(b|)
s2.content = newContents(epsilon)
s2.output = append(s2.output, s2)
s2.isEmpty = true
s2.isQuestion = true
s3 := alternate(s1, s2)
return s3
}

Loading…
Cancel
Save