mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
simple/buggy comment highlighting
This commit is contained in:
parent
18d4598940
commit
0b49a015ad
@ -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 {
|
||||||
|
@ -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 = [
|
||||||
|
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
phi-editor
BIN
phi-editor
Binary file not shown.
Loading…
Reference in New Issue
Block a user