Added new state fields to tell if a state is a question or alternation
This commit is contained in:
@@ -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.
|
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)
|
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
|
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
|
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
|
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.
|
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)),
|
output: make([]*nfaState, len(stateToClone.output)),
|
||||||
transitions: make(map[int][]*nfaState),
|
transitions: make(map[int][]*nfaState),
|
||||||
isKleene: stateToClone.isKleene,
|
isKleene: stateToClone.isKleene,
|
||||||
|
isQuestion: stateToClone.isQuestion,
|
||||||
|
isAlternation: stateToClone.isAlternation,
|
||||||
assert: stateToClone.assert,
|
assert: stateToClone.assert,
|
||||||
zeroMatchFound: stateToClone.zeroMatchFound,
|
zeroMatchFound: stateToClone.zeroMatchFound,
|
||||||
allChars: stateToClone.allChars,
|
allChars: stateToClone.allChars,
|
||||||
@@ -341,6 +345,7 @@ func alternate(s1 *nfaState, s2 *nfaState) *nfaState {
|
|||||||
}
|
}
|
||||||
toReturn.content = newContents(epsilon)
|
toReturn.content = newContents(epsilon)
|
||||||
toReturn.isEmpty = true
|
toReturn.isEmpty = true
|
||||||
|
toReturn.isAlternation = true
|
||||||
|
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
@@ -351,6 +356,7 @@ func question(s1 *nfaState) *nfaState { // Use the fact that ab? == a(b|)
|
|||||||
s2.content = newContents(epsilon)
|
s2.content = newContents(epsilon)
|
||||||
s2.output = append(s2.output, s2)
|
s2.output = append(s2.output, s2)
|
||||||
s2.isEmpty = true
|
s2.isEmpty = true
|
||||||
|
s2.isQuestion = true
|
||||||
s3 := alternate(s1, s2)
|
s3 := alternate(s1, s2)
|
||||||
return s3
|
return s3
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user