1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-17 01:22:22 +02:00

Report file pattern errors when a lexer is initialised.

See #555
This commit is contained in:
Alec Thomas
2021-09-27 14:27:46 +10:00
parent 07a127dd74
commit 9a8a647afb

View File

@ -3,6 +3,7 @@ package chroma
import (
"fmt"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
@ -238,6 +239,12 @@ func NewLazyLexer(config *Config, rulesFunc func() Rules) (*RegexLexer, error) {
if config == nil {
config = &Config{}
}
for _, glob := range append(config.Filenames, config.AliasFilenames...) {
_, err := filepath.Match(glob, "")
if err != nil {
return nil, fmt.Errorf("%s: %q is not a valid glob: %w", config.Name, glob, err)
}
}
return &RegexLexer{
config: config,
compilerFunc: rulesFunc,