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

Emit error tokens when there's a group mismatch.

Also don't panic/recover, as we no longer use panic to report "real"
errors.

Fixes #295.
This commit is contained in:
Alec Thomas
2019-10-24 17:02:24 +11:00
parent a1c4eaa235
commit bbc59ac372
9 changed files with 12 additions and 29 deletions

View File

@ -35,8 +35,13 @@ func ByGroups(emitters ...Emitter) Emitter {
return EmitterFunc(func(groups []string, lexer Lexer) Iterator {
iterators := make([]Iterator, 0, len(groups)-1)
// NOTE: If this panics, there is a mismatch with groups
for i, group := range groups[1:] {
iterators = append(iterators, emitters[i].Emit([]string{group}, lexer))
if len(emitters) != len(groups)-1 {
iterators = append(iterators, Error.Emit(groups, lexer))
// panic(errors.Errorf("number of groups %q does not match number of emitters %v", groups, emitters))
} else {
for i, group := range groups[1:] {
iterators = append(iterators, emitters[i].Emit([]string{group}, lexer))
}
}
return Concaterator(iterators...)
})