Compare commits
2 Commits
3f5f8fad2c
...
5e3801af7c
Author | SHA1 | Date | |
---|---|---|---|
5e3801af7c | |||
d44a25f412 |
@@ -176,7 +176,7 @@ func FindNthMatch(regex Reg, str string, n int) (Match, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We haven't found the nth match after scanning the string - Return an error
|
// We haven't found the nth match after scanning the string - Return an error
|
||||||
return nil, fmt.Errorf("Invalid match index. Too few matches found.")
|
return nil, fmt.Errorf("invalid match index - too few matches found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindAllMatches tries to find all matches of the regex represented by given start-state, with
|
// FindAllMatches tries to find all matches of the regex represented by given start-state, with
|
||||||
|
5
nfa.go
5
nfa.go
@@ -205,11 +205,6 @@ func (s State) matchesFor(str []rune, idx int) ([]*State, int) {
|
|||||||
return listTransitions, numTransitions
|
return listTransitions, numTransitions
|
||||||
}
|
}
|
||||||
|
|
||||||
type NFA struct {
|
|
||||||
start State
|
|
||||||
outputs []State
|
|
||||||
}
|
|
||||||
|
|
||||||
// verifyLastStatesHelper performs the depth-first recursion needed for verifyLastStates
|
// verifyLastStatesHelper performs the depth-first recursion needed for verifyLastStates
|
||||||
func verifyLastStatesHelper(state *State, visited map[*State]bool) {
|
func verifyLastStatesHelper(state *State, visited map[*State]bool) {
|
||||||
if len(state.transitions) == 0 {
|
if len(state.transitions) == 0 {
|
||||||
|
@@ -5,7 +5,7 @@ import "errors"
|
|||||||
// Helper functions for slices, to make them behave more like stacks
|
// Helper functions for slices, to make them behave more like stacks
|
||||||
func peek[T any](s []T) (T, error) {
|
func peek[T any](s []T) (T, error) {
|
||||||
if len(s) < 1 {
|
if len(s) < 1 {
|
||||||
return *new(T), errors.New("Stack empty")
|
return *new(T), errors.New("stack empty")
|
||||||
}
|
}
|
||||||
return s[len(s)-1], nil
|
return s[len(s)-1], nil
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ func mustPop[T any](sp *[]T) T {
|
|||||||
|
|
||||||
func pop[T any](sp *[]T) (T, error) {
|
func pop[T any](sp *[]T) (T, error) {
|
||||||
if len(*sp) < 1 {
|
if len(*sp) < 1 {
|
||||||
return *new(T), errors.New("Stack empty")
|
return *new(T), errors.New("stack empty")
|
||||||
}
|
}
|
||||||
to_return := (*sp)[len(*sp)-1]
|
to_return := (*sp)[len(*sp)-1]
|
||||||
*sp = (*sp)[:len(*sp)-1]
|
*sp = (*sp)[:len(*sp)-1]
|
||||||
|
Reference in New Issue
Block a user