Don't skip included rules in end

This commit is contained in:
Zachary Yedidia
2017-03-29 09:21:54 -04:00
parent 079cbe11f4
commit 342f3c223d
4 changed files with 21 additions and 31 deletions

View File

@@ -60,7 +60,7 @@ func NewHighlighter(def *Def) *Highlighter {
// color's group (represented as one byte)
type LineMatch map[int]Group
func findIndex(regex *regexp.Regexp, skip []*regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
regexStr := regex.String()
if strings.Contains(regexStr, "^") {
if !canMatchStart {
@@ -73,16 +73,14 @@ func findIndex(regex *regexp.Regexp, skip []*regexp.Regexp, str []rune, canMatch
}
}
strbytes := []byte(string(str))
if skip != nil && len(skip) > 0 {
for _, r := range skip {
if r != nil {
strbytes = r.ReplaceAllFunc(strbytes, func(match []byte) []byte {
res := make([]byte, utf8.RuneCount(match))
return res
})
}
}
var strbytes []byte
if skip != nil {
strbytes = skip.ReplaceAllFunc(strbytes, func(match []byte) []byte {
res := make([]byte, utf8.RuneCount(match))
return res
})
} else {
strbytes = []byte(string(str))
}
match := regex.FindIndex(strbytes)
@@ -122,15 +120,7 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE
}
}
skips := make([]*regexp.Regexp, len(curRegion.rules.patterns)+1)
for i := range skips {
if i != len(skips)-1 {
skips[i] = curRegion.rules.patterns[i].regex
} else {
skips[i] = curRegion.skip
}
}
loc := findIndex(curRegion.end, skips, line, start == 0, canMatchEnd)
loc := findIndex(curRegion.end, curRegion.skip, line, start == 0, canMatchEnd)
if loc != nil {
if !statesOnly {
highlights[start+loc[1]-1] = curRegion.group

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
filetype: csharp
detect:
filename: "\\.cs"
filename: "\\.cs$"
rules:
# Class

File diff suppressed because one or more lines are too long