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

Fix: sort words in descending order of length before regex generation (#496)

* Fix: sort words in descending order of length before regex generation

* Avoid code duplication in Raku lexer
This commit is contained in:
mlpo
2021-05-08 01:10:18 +02:00
committed by GitHub
parent 225e1862d3
commit ff6eedba72
2 changed files with 9 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"regexp"
"sort"
"strings"
"sync"
"time"
@ -141,6 +142,9 @@ func UsingSelf(stateName string) Emitter {
// Words creates a regex that matches any of the given literal words.
func Words(prefix, suffix string, words ...string) string {
sort.Slice(words, func(i, j int) bool {
return len(words[j]) < len(words[i])
})
for i, word := range words {
words[i] = regexp.QuoteMeta(word)
}