mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-17 05:54:59 +02:00
Make config line parsing in Go use same algorithm as in python
This commit is contained in:
@@ -11,7 +11,9 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
@@ -49,6 +51,10 @@ func (self *ConfigParser) BadLines() []ConfigLine {
|
||||
return self.bad_lines
|
||||
}
|
||||
|
||||
var key_pat = sync.OnceValue(func() *regexp.Regexp {
|
||||
return regexp.MustCompile(`([a-zA-Z][a-zA-Z0-9_-]*)\s+(.+)$`)
|
||||
})
|
||||
|
||||
func (self *ConfigParser) parse(scanner Scanner, name, base_path_for_includes string, depth int) error {
|
||||
if self.seen_includes[name] { // avoid include loops
|
||||
return nil
|
||||
@@ -119,7 +125,12 @@ func (self *ConfigParser) parse(scanner Scanner, name, base_path_for_includes st
|
||||
}
|
||||
continue
|
||||
}
|
||||
key, val := line, ""
|
||||
m := key_pat().FindStringSubmatch(line)
|
||||
if len(m) < 3 {
|
||||
self.bad_lines = append(self.bad_lines, ConfigLine{Src_file: name, Line: line, Line_number: lnum, Err: fmt.Errorf("Invalid config line: %#v", line)})
|
||||
continue
|
||||
}
|
||||
key, val := m[1], m[2]
|
||||
for i, ch := range line {
|
||||
if ch == ' ' || ch == '\t' {
|
||||
key = line[:i]
|
||||
|
||||
Reference in New Issue
Block a user