mirror of
https://github.com/felixangell/phi.git
synced 2024-10-26 17:18:31 +03:00
simple/buggy comment highlighting
This commit is contained in:
parent
18d4598940
commit
0b49a015ad
@ -56,6 +56,7 @@ func getDefaultConfig() string {
|
||||
type SyntaxCriteria struct {
|
||||
Colour int `toml:"colouring"`
|
||||
Match []string `toml:"match"`
|
||||
Pattern string `toml:"pattern"`
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
|
@ -38,6 +38,10 @@ match = [
|
||||
"rune", "byte", "float32", "float64"
|
||||
]
|
||||
|
||||
[syntax.go.comment]
|
||||
colouring = 0xff00ff
|
||||
pattern = "[\/]+.*"
|
||||
|
||||
[syntax.go.symbol]
|
||||
colouring = 0xf0a400
|
||||
match = [
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
@ -736,27 +737,37 @@ 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 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)
|
||||
@ -764,6 +775,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var x_col int
|
||||
for idx, char := range source {
|
||||
|
BIN
phi-editor
BIN
phi-editor
Binary file not shown.
Loading…
Reference in New Issue
Block a user