simple/buggy comment highlighting

This commit is contained in:
Felix Angell 2018-04-14 01:57:01 +01:00
parent 18d4598940
commit 0b49a015ad
4 changed files with 32 additions and 15 deletions

View File

@ -54,8 +54,9 @@ func getDefaultConfig() string {
}
type SyntaxCriteria struct {
Colour int `toml:"colouring"`
Match []string `toml:"match"`
Colour int `toml:"colouring"`
Match []string `toml:"match"`
Pattern string `toml:"pattern"`
}
type Command struct {

View File

@ -38,6 +38,10 @@ match = [
"rune", "byte", "float32", "float64"
]
[syntax.go.comment]
colouring = 0xff00ff
pattern = "[\/]+.*"
[syntax.go.symbol]
colouring = 0xf0a400
match = [

View File

@ -4,6 +4,7 @@ import (
"io/ioutil"
"log"
"path"
"regexp"
"strings"
"time"
"unicode"
@ -736,30 +737,41 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
// char index => colour
matches := map[int]int{}
subjects := [][]string{}
subjects := []cfg.SyntaxCriteria{}
colours := []int{}
stuff := b.cfg.Syntax[b.languageInfo]
for _, criteria := range stuff {
colours = append(colours, criteria.Colour)
subj := criteria.Match
subjects = append(subjects, subj)
subjects = append(subjects, criteria)
}
// HOLY SLOW BATMAN
for idx, _ := range source {
for syntaxIndex, syntax := range subjects {
for _, subject := range syntax {
if idx+len(subject) > len(source) {
continue
}
a := source[idx : idx+len(subject)]
if strings.Compare(string(a), subject) == 0 {
for i := 0; i < len(subject); i++ {
matches[i+idx] = colours[syntaxIndex]
if syntax.Pattern != "" {
a := source[idx:]
match, _ := regexp.MatchString(syntax.Pattern, string(a))
if match {
for i := 0; i < len(string(a)); i++ {
matches[i] = colours[syntaxIndex]
}
}
} else {
for _, subject := range syntax.Match {
if idx+len(subject) > len(source) {
continue
}
a := source[idx : idx+len(subject)]
if strings.Compare(string(a), subject) == 0 {
for i := 0; i < len(subject); i++ {
if _, ok := matches[i+idx]; ok {
continue
}
matches[i+idx] = colours[syntaxIndex]
}
idx += len(subject)
}
idx += len(subject)
}
}
}

Binary file not shown.