Initial support for multiple matching

This commit is contained in:
2024-10-23 11:18:45 -04:00
parent 60b798d904
commit 9d786997df
2 changed files with 35 additions and 12 deletions

17
main.go
View File

@@ -178,14 +178,21 @@ func main() {
re_postfix := shuntingYard(re)
// fmt.Println(re_postfix)
startState := thompson(re_postfix)
start, end, matched := match(startState, os.Args[2])
if matched {
matchIndices := match(startState, os.Args[2])
inColor := false
if len(matchIndices) > 0 {
for i, c := range os.Args[2] {
if i >= start && i < end {
color.New(color.FgRed).Printf("%c", c)
} else {
for _, indices := range matchIndices {
if i >= indices.startIdx && i < indices.endIdx {
color.New(color.FgRed).Printf("%c", c)
inColor = true
break
}
}
if inColor == false {
fmt.Printf("%c", c)
}
inColor = false
}
fmt.Printf("\n")
} else {