diff --git a/highlighter.go b/highlighter.go index cf0fb48..eea429a 100644 --- a/highlighter.go +++ b/highlighter.go @@ -4,6 +4,7 @@ import ( "regexp" "strings" "unicode/utf8" + "path/filepath" ) // RunePos returns the rune index of a given byte index @@ -60,6 +61,29 @@ func NewHighlighter(def *Def) *Highlighter { // color's group (represented as one byte) type LineMatch map[int]Group +func ParseSyntaxFiles (dir string, defs *[]*highlight.Def) error{ + pattern := "*.yaml" + files, err := filepath.Glob(dir + "/" + pattern) + if err != nil { + return err + } + + for _, file_path := range(files){ + file, err := ioutil.ReadFile(file_path) + if err != nil { + return err + } + + d, err := highlight.ParseDef(file) + if err != nil { + log.Output(1, err.Error()) + continue + } + *defs = append(*defs, d) + return nil + } +} + func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int { regexStr := regex.String() if strings.Contains(regexStr, "^") {