Added function to determine if a state is a lookaround
This commit is contained in:
6
nfa.go
6
nfa.go
@@ -98,7 +98,7 @@ func (s State) checkAssertion(str []rune, idx int) bool {
|
||||
if s.assert == NONWBOUND {
|
||||
return !isWordBoundary(str, idx)
|
||||
}
|
||||
if s.assert == PLA || s.assert == PLB || s.assert == NLA || s.assert == NLB { // Lookaround
|
||||
if s.isLookaround() {
|
||||
// The process here is simple:
|
||||
// 1. Compile the regex stored in the state's contents.
|
||||
// 2. Run it on the test string.
|
||||
@@ -143,6 +143,10 @@ func (s State) contentContains(str []rune, idx int) bool {
|
||||
return slices.Contains(s.content, int(str[idx]))
|
||||
}
|
||||
|
||||
func (s State) isLookaround() bool {
|
||||
return s.assert == PLA || s.assert == PLB || s.assert == NLA || s.assert == NLB
|
||||
}
|
||||
|
||||
// Returns the matches for the character at the given index of the given string.
|
||||
// Also returns the number of matches. Returns -1 if an assertion failed.
|
||||
func (s State) matchesFor(str []rune, idx int) ([]*State, int) {
|
||||
|
Reference in New Issue
Block a user