Only include syntax layers specified by build tags; lazy-load syntax layers

This commit is contained in:
2025-06-14 09:37:24 -04:00
parent 4966337b1f
commit a427b4a907
3 changed files with 36 additions and 10 deletions
+25
View File
@@ -0,0 +1,25 @@
package syntax
import "sync"
var syntaxMap = make(map[string]*lazySyntax)
type lazySyntax struct {
once sync.Once
syntaxLayer []byte
init func() []byte
}
func (ls *lazySyntax) get() []byte {
ls.once.Do(func() {
ls.syntaxLayer = ls.init()
})
return ls.syntaxLayer
}
func Get(id string) []byte {
if syntax, exists := syntaxMap[id]; exists {
return syntax.get()
}
return nil
}