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 { type SyntaxCriteria struct {
Colour int `toml:"colouring"` Colour int `toml:"colouring"`
Match []string `toml:"match"` Match []string `toml:"match"`
Pattern string `toml:"pattern"`
} }
type Command struct { type Command struct {

View File

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

View File

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