mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-06 00:47:15 -04:00
Helper method to parse syntax files
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunePos returns the rune index of a given byte index
|
// 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)
|
// color's group (represented as one byte)
|
||||||
type LineMatch map[int]Group
|
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 {
|
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
|
||||||
regexStr := regex.String()
|
regexStr := regex.String()
|
||||||
if strings.Contains(regexStr, "^") {
|
if strings.Contains(regexStr, "^") {
|
||||||
|
|||||||
Reference in New Issue
Block a user