Helper method to parse syntax files

This commit is contained in:
Jesse Portnoy
2023-07-16 16:26:54 +01:00
parent 5fa7eb841e
commit 0606b69176
+24
View File
@@ -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, "^") {