Initial support for multiple matching
This commit is contained in:
17
main.go
17
main.go
@@ -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 {
|
||||
|
Reference in New Issue
Block a user