MCPcopy
hub / github.com/micro-editor/micro / MakeHeader

Function MakeHeader

pkg/highlight/parser.go:99–126  ·  view source on GitHub ↗

MakeHeader takes a header (.hdr file) file and parses the header Header files make parsing more efficient when you only want to compute on the headers of syntax files A yaml file might take ~400us to parse while a header file only takes ~20us

(data []byte)

Source from the content-addressed store, hash-verified

97// on the headers of syntax files
98// A yaml file might take ~400us to parse while a header file only takes ~20us
99func MakeHeader(data []byte) (*Header, error) {
100 lines := bytes.Split(data, []byte{'\n'})
101 if len(lines) < 4 {
102 return nil, errors.New("Header file has incorrect format")
103 }
104 header := new(Header)
105 var err error
106 header.FileType = string(lines[0])
107 fnameRegexStr := string(lines[1])
108 headerRegexStr := string(lines[2])
109 signatureRegexStr := string(lines[3])
110
111 if fnameRegexStr != "" {
112 header.FileNameRegex, err = regexp.Compile(fnameRegexStr)
113 }
114 if err == nil && headerRegexStr != "" {
115 header.HeaderRegex, err = regexp.Compile(headerRegexStr)
116 }
117 if err == nil && signatureRegexStr != "" {
118 header.SignatureRegex, err = regexp.Compile(signatureRegexStr)
119 }
120
121 if err != nil {
122 return nil, err
123 }
124
125 return header, nil
126}
127
128// MakeHeaderYaml takes a yaml spec for a syntax file and parses the
129// header

Callers 2

filetypeCompleteFunction · 0.92
UpdateRulesMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected