Use my regex engine instead of the stdlib one
This commit is contained in:
		@@ -6,11 +6,11 @@ import (
 | 
			
		||||
	"io/fs"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"gitea.twomorecents.org/Rockingcool/ccat/stack"
 | 
			
		||||
	"gitea.twomorecents.org/Rockingcool/kleingrep/regex"
 | 
			
		||||
 | 
			
		||||
	"gopkg.in/yaml.v2"
 | 
			
		||||
)
 | 
			
		||||
@@ -88,13 +88,13 @@ func loadConfig(configFilename string) (stack.Stack[regColor], error) {
 | 
			
		||||
	//  returned.
 | 
			
		||||
	regColorStack := stack.NewStack[regColor](len(strings.Split(string(configFile), "\n"))) // The stack will have the same size as the number of lines in the file
 | 
			
		||||
	for _, item := range tempMapSlice {
 | 
			
		||||
		re := regexp.MustCompile(item.Key.(string))
 | 
			
		||||
		re := regex.MustCompile(item.Key.(string))
 | 
			
		||||
		clr, err := newColor(item.Value.(string))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return *stack.NewStack[regColor](0), err
 | 
			
		||||
		}
 | 
			
		||||
		// If we got past the errors, then the color _must_ be valid.
 | 
			
		||||
		regColorStack.Push(regColor{re, clr})
 | 
			
		||||
		regColorStack.Push(regColor{&re, clr})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return *regColorStack, nil
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@
 | 
			
		||||
"'(.)'": BLUE
 | 
			
		||||
"'\\\\(.)'": BLUE # The escape backslash needs to be escaped as well
 | 
			
		||||
# Assignments and comparisons
 | 
			
		||||
'(?:\s|\b)(=|==|!=|<=|>=)(\s|\b)' : CYAN
 | 
			
		||||
'(?:\s|\b)(=|==|!=|\<=|\>=)(\s|\b)' : CYAN
 | 
			
		||||
'(&&)|(\|\|)': CYAN
 | 
			
		||||
# Keywords
 | 
			
		||||
'\b(if|else|for|range|go|func|return|break|continue)\b': CYAN
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,11 +1,14 @@
 | 
			
		||||
module gitea.twomorecents.org/Rockingcool/ccat
 | 
			
		||||
 | 
			
		||||
go 1.22.5
 | 
			
		||||
go 1.23.1
 | 
			
		||||
 | 
			
		||||
toolchain go1.24.2
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/fatih/color v1.17.0 // indirect
 | 
			
		||||
	gitea.twomorecents.org/Rockingcool/kleingrep v0.7.0 // indirect
 | 
			
		||||
	github.com/fatih/color v1.18.0 // indirect
 | 
			
		||||
	github.com/mattn/go-colorable v0.1.13 // indirect
 | 
			
		||||
	github.com/mattn/go-isatty v0.0.20 // indirect
 | 
			
		||||
	golang.org/x/sys v0.18.0 // indirect
 | 
			
		||||
	golang.org/x/sys v0.25.0 // indirect
 | 
			
		||||
	gopkg.in/yaml.v2 v2.4.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,7 +1,13 @@
 | 
			
		||||
gitea.twomorecents.org/Rockingcool/kleingrep v0.6.1 h1:eeryIhh2lDMXsu3D1i95IgW2SPte1DaJxlfmiQjrpsE=
 | 
			
		||||
gitea.twomorecents.org/Rockingcool/kleingrep v0.6.1/go.mod h1:8bcYe2hyjNIDM9J2xnyH5veMCAMzVJQR3c0OkatcEPg=
 | 
			
		||||
gitea.twomorecents.org/Rockingcool/kleingrep v0.7.0 h1:owDJjgulFmg9DmgKBtwZMxdf19wM9VbGchMXq7ZlhIM=
 | 
			
		||||
gitea.twomorecents.org/Rockingcool/kleingrep v0.7.0/go.mod h1:8bcYe2hyjNIDM9J2xnyH5veMCAMzVJQR3c0OkatcEPg=
 | 
			
		||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
 | 
			
		||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
 | 
			
		||||
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
 | 
			
		||||
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
 | 
			
		||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
 | 
			
		||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
 | 
			
		||||
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
 | 
			
		||||
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
 | 
			
		||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
 | 
			
		||||
@@ -13,6 +19,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
 | 
			
		||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
 | 
			
		||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
			
		||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
 | 
			
		||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
			
		||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
			
		||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 | 
			
		||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.go
									
									
									
									
									
								
							@@ -157,13 +157,13 @@ func main() {
 | 
			
		||||
		clr := regclr.clr
 | 
			
		||||
		// Returns an int double-slice, where each slice contains the start and end indices
 | 
			
		||||
		// of the match. In this case, I am finding all the matches of 're' in 'data'.
 | 
			
		||||
		matches := re.FindAllSubmatchIndex(data, -1)
 | 
			
		||||
		matches := re.FindAllSubmatch(string(data))
 | 
			
		||||
		if matches == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		// For each match, apply the corresponding color to all characters in the match.
 | 
			
		||||
		for _, match := range matches {
 | 
			
		||||
			units = applyColor(units, match[0], match[1], clr)
 | 
			
		||||
			units = applyColor(units, match[0].StartIdx, match[0].EndIdx, clr)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import "regexp"
 | 
			
		||||
import "gitea.twomorecents.org/Rockingcool/kleingrep/regex"
 | 
			
		||||
 | 
			
		||||
// A regColor is a regex-color pair. The config file is read
 | 
			
		||||
// into a stack of this data type.
 | 
			
		||||
type regColor struct {
 | 
			
		||||
	re  *regexp.Regexp
 | 
			
		||||
	re  *regex.Reg
 | 
			
		||||
	clr color
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user