mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 14:47:16 +09:00
Use bytes for highlight groups
This commit is contained in:
@@ -7,6 +7,18 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var groups map[string]uint8
|
||||
var numGroups uint8
|
||||
|
||||
func GetGroup(n uint8) string {
|
||||
for k, v := range groups {
|
||||
if v == n {
|
||||
return k
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// A Def is a full syntax definition for a language
|
||||
// It has a filetype, information about how to detect the filetype based
|
||||
// on filename or header (the first line of the file)
|
||||
@@ -21,7 +33,7 @@ type Def struct {
|
||||
// It has a group that the rule belongs to, as well as
|
||||
// the regular expression to match the pattern
|
||||
type Pattern struct {
|
||||
group string
|
||||
group uint8
|
||||
regex *regexp.Regexp
|
||||
}
|
||||
|
||||
@@ -39,13 +51,17 @@ type Rules struct {
|
||||
// region and also rules from the above region do not match inside this region
|
||||
// Note that a region may contain more regions
|
||||
type Region struct {
|
||||
group string
|
||||
group uint8
|
||||
parent *Region
|
||||
start *regexp.Regexp
|
||||
end *regexp.Regexp
|
||||
rules *Rules
|
||||
}
|
||||
|
||||
func init() {
|
||||
groups = make(map[string]uint8)
|
||||
}
|
||||
|
||||
// ParseDef parses an input syntax file into a highlight Def
|
||||
func ParseDef(input []byte) (s *Def, err error) {
|
||||
// This is just so if we have an error, we can exit cleanly and return the parse error to the user
|
||||
@@ -155,7 +171,13 @@ func parseRules(input []interface{}, curRegion *Region) (*Rules, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rules.patterns = append(rules.patterns, &Pattern{group.(string), r})
|
||||
groupStr := group.(string)
|
||||
if _, ok := groups[groupStr]; !ok {
|
||||
numGroups++
|
||||
groups[groupStr] = numGroups
|
||||
}
|
||||
groupNum := groups[groupStr]
|
||||
rules.patterns = append(rules.patterns, &Pattern{groupNum, r})
|
||||
}
|
||||
case map[interface{}]interface{}:
|
||||
// Region
|
||||
@@ -177,7 +199,12 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
|
||||
var err error
|
||||
|
||||
region := new(Region)
|
||||
region.group = group
|
||||
if _, ok := groups[group]; !ok {
|
||||
numGroups++
|
||||
groups[group] = numGroups
|
||||
}
|
||||
groupNum := groups[group]
|
||||
region.group = groupNum
|
||||
region.parent = prevRegion
|
||||
|
||||
region.start, err = regexp.Compile(regionInfo["start"].(string))
|
||||
|
||||
Reference in New Issue
Block a user