// A State represents the region at the end of a line
type State *region
+var EmptyDef = Def{nil, &rules{}}
+
// LineStates is an interface for a buffer-like object which can also store the states and matches for every line
type LineStates interface {
LineBytes(n int) []byte
return highlights
}
- if lineLen == 0 || statesOnly {
+ if lineLen == 0 {
if canMatchEnd {
h.lastRegion = curRegion
}
}
}
if firstLoc[0] != lineLen {
- highlights[start+firstLoc[0]] = firstRegion.limitGroup
+ if !statesOnly {
+ highlights[start+firstLoc[0]] = firstRegion.limitGroup
+ }
h.highlightRegion(highlights, start, false, lineNum, sliceEnd(line, firstLoc[0]), curRegion, statesOnly)
h.highlightRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, sliceStart(line, firstLoc[1]), firstRegion, statesOnly)
return highlights
}
- fullHighlights := make([]Group, lineLen)
- for i := 0; i < len(fullHighlights); i++ {
- fullHighlights[i] = curRegion.group
- }
+ if !statesOnly {
+ fullHighlights := make([]Group, lineLen)
+ for i := 0; i < len(fullHighlights); i++ {
+ fullHighlights[i] = curRegion.group
+ }
- for _, p := range curRegion.rules.patterns {
- matches := findAllIndex(p.regex, line, start == 0, canMatchEnd)
- for _, m := range matches {
- for i := m[0]; i < m[1]; i++ {
- fullHighlights[i] = p.group
+ for _, p := range curRegion.rules.patterns {
+ matches := findAllIndex(p.regex, line, start == 0, canMatchEnd)
+ for _, m := range matches {
+ for i := m[0]; i < m[1]; i++ {
+ fullHighlights[i] = p.group
+ }
}
}
- }
- for i, h := range fullHighlights {
- if i == 0 || h != fullHighlights[i-1] {
- highlights[start+i] = h
+ for i, h := range fullHighlights {
+ if i == 0 || h != fullHighlights[i-1] {
+ highlights[start+i] = h
+ }
}
}
}
// ReHighlightStates will scan down from `startline` and set the appropriate end of line state
-// for each line until it comes across the same state in two consecutive lines
-func (h *Highlighter) ReHighlightStates(input LineStates, startline int) {
+// for each line until it comes across a line whose state does not change
+// returns the number of the final line
+func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
// lines := input.LineData()
h.lastRegion = nil
input.SetState(i, curState)
if curState == lastState {
- break
+ return i
}
}
+
+ return input.LinesNum() - 1
}
// ReHighlightLine will rehighlight the state and match for a single line