glob/cmd/globdraw/main.go

46 lines
895 B
Go
Raw Permalink Normal View History

2016-01-22 19:16:46 +03:00
package main
import (
"flag"
"fmt"
"os"
"strings"
2016-02-02 22:03:37 +03:00
"unicode/utf8"
2022-12-12 17:24:35 +03:00
"git.internal/re/glob"
"git.internal/re/glob/match"
"git.internal/re/glob/match/debug"
2016-01-22 19:16:46 +03:00
)
func main() {
pattern := flag.String("p", "", "pattern to draw")
2016-02-02 22:03:37 +03:00
sep := flag.String("s", "", "comma separated list of separators characters")
2016-01-22 19:16:46 +03:00
flag.Parse()
if *pattern == "" {
flag.Usage()
os.Exit(1)
}
2016-02-02 22:03:37 +03:00
var separators []rune
2016-02-24 20:23:24 +03:00
if len(*sep) > 0 {
for _, c := range strings.Split(*sep, ",") {
if r, w := utf8.DecodeRuneInString(c); len(c) > w {
fmt.Println("only single charactered separators are allowed")
os.Exit(1)
} else {
separators = append(separators, r)
}
2016-02-02 22:03:37 +03:00
}
}
glob, err := glob.Compile(*pattern, separators...)
2016-01-22 19:16:46 +03:00
if err != nil {
fmt.Println("could not compile pattern:", err)
os.Exit(1)
}
matcher := glob.(match.Matcher)
2016-02-24 20:23:24 +03:00
fmt.Fprint(os.Stdout, debug.Graphviz(*pattern, matcher))
2016-01-22 19:16:46 +03:00
}