diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index f7181e996d..5f64c99a24 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -682,30 +682,22 @@ func calcHash(b *Buffer, out *[md5.Size]byte) error { return nil } -// UpdateRules updates the syntax rules and filetype for this buffer -// This is called when the colorscheme changes -func (b *Buffer) UpdateRules() { - if !b.Type.Syntax { - return - } - ft := b.Settings["filetype"].(string) - if ft == "off" { - return - } - - // syntaxFileBuffer is a helper structure - // to store properties of one single syntax file - type syntaxFileBuffer struct { - header *highlight.Header - fileName string - syntaxDef *highlight.Def - } +// syntaxFileBuffer is a helper structure +// to store properties of one single syntax file +type syntaxFileBuffer struct { + header *highlight.Header + fileName string + syntaxDef *highlight.Def +} - syntaxFiles := []syntaxFileBuffer{} +// searchUserSyntax searches for the syntax file +// in the user's custom syntax files +func (b *Buffer) searchUserSyntax(ft string, syntaxFiles *[]syntaxFileBuffer, useHeader bool) (string, bool, *highlight.Header) { syntaxFile := "" foundDef := false + match := false var header *highlight.Header - // search for the syntax file in the user's custom syntax files + for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) { data, err := f.Data() if err != nil { @@ -724,7 +716,13 @@ func (b *Buffer) UpdateRules() { continue } - if ((ft == "unknown" || ft == "") && header.MatchFileName(b.Path)) || header.FileType == ft { + if !useHeader { + match = header.MatchFileName(b.Path) + } else { + match = header.MatchFileHeader(b.lines[0].data) + } + + if ((ft == "unknown" || ft == "") && match) || header.FileType == ft { syndef, err := highlight.ParseDef(file, header) if err != nil { screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) @@ -736,130 +734,180 @@ func (b *Buffer) UpdateRules() { b.SyntaxDef = syndef syntaxFile = f.Name() break + } + if syntaxFiles != nil { + *syntaxFiles = append(*syntaxFiles, syntaxFileBuffer{header, f.Name(), syndef}) + } + } + } + + return syntaxFile, foundDef, header +} + +// searchRuntimeHeader search in the runtime hdr files +func (b *Buffer) searchRuntimeHeader(ft string, syntaxFiles *[]syntaxFileBuffer, useHeader bool) (string, *highlight.Header) { + syntaxFile := "" + var header *highlight.Header + + for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) { + data, err := f.Data() + if err != nil { + screen.TermMessage("Error loading syntax header file " + f.Name() + ": " + err.Error()) + continue + } + + header, err = highlight.MakeHeader(data) + if err != nil { + screen.TermMessage("Error reading syntax header file", f.Name(), err) + continue + } + + if ft == "unknown" || ft == "" { + if !useHeader { + if header.MatchFileName(b.Path) && syntaxFiles != nil { + *syntaxFiles = append(*syntaxFiles, syntaxFileBuffer{header, f.Name(), nil}) + } } else { - syntaxFiles = append(syntaxFiles, syntaxFileBuffer{header, f.Name(), syndef}) + if header.MatchFileHeader(b.lines[0].data) && syntaxFiles != nil { + *syntaxFiles = append(*syntaxFiles, syntaxFileBuffer{header, f.Name(), nil}) + } } + } else if header.FileType == ft { + syntaxFile = f.Name() + break } } - if !foundDef { - // search in the default syntax files - for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) { + return syntaxFile, header +} + +// searchRuntimeSyntax search in the runtime syntax files +func (b *Buffer) searchRuntimeSyntax(name string, header *highlight.Header) { + for _, f := range config.ListRuntimeFiles(config.RTSyntax) { + if f.Name() == name { data, err := f.Data() if err != nil { - screen.TermMessage("Error loading syntax header file " + f.Name() + ": " + err.Error()) + screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error()) continue } - header, err = highlight.MakeHeader(data) + file, err := highlight.ParseFile(data) if err != nil { - screen.TermMessage("Error reading syntax header file", f.Name(), err) + screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) continue } - if ft == "unknown" || ft == "" { - if header.MatchFileName(b.Path) { - syntaxFiles = append(syntaxFiles, syntaxFileBuffer{header, f.Name(), nil}) - } - } else if header.FileType == ft { - syntaxFile = f.Name() - break + syndef, err := highlight.ParseDef(file, header) + if err != nil { + screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) + continue } + b.SyntaxDef = syndef + break } } +} - if syntaxFile == "" { - length := len(syntaxFiles) - if length > 0 { - signatureMatch := false - if length > 1 { - detectlimit := util.IntOpt(b.Settings["detectlimit"]) - lineCount := len(b.lines) - limit := lineCount - if detectlimit > 0 && lineCount > detectlimit { - limit = detectlimit - } - for i := 0; i < length && !signatureMatch; i++ { - if syntaxFiles[i].header.HasFileSignature() { - for j := 0; j < limit && !signatureMatch; j++ { - if syntaxFiles[i].header.MatchFileSignature(b.lines[j].data) { - syntaxFile = syntaxFiles[i].fileName - b.SyntaxDef = syntaxFiles[i].syntaxDef - header = syntaxFiles[i].header - signatureMatch = true - } - } - } - } - } - if length == 1 || !signatureMatch { - syntaxFile = syntaxFiles[0].fileName - b.SyntaxDef = syntaxFiles[0].syntaxDef - header = syntaxFiles[0].header - } - } - } +// solveSyntaxIncludes search includes in the runtime syntax files +func (b *Buffer) solveSyntaxIncludes(*highlight.Def) { + includes := highlight.GetIncludes(b.SyntaxDef) - if syntaxFile != "" && !foundDef { - // we found a syntax file using a syntax header file - for _, f := range config.ListRuntimeFiles(config.RTSyntax) { - if f.Name() == syntaxFile { - data, err := f.Data() - if err != nil { - screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error()) - continue - } + var files []*highlight.File + for _, f := range config.ListRuntimeFiles(config.RTSyntax) { + data, err := f.Data() + if err != nil { + screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) + continue + } + header, err := highlight.MakeHeaderYaml(data) + if err != nil { + screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) + continue + } + for _, i := range includes { + if header.FileType == i { file, err := highlight.ParseFile(data) if err != nil { screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) continue } - - syndef, err := highlight.ParseDef(file, header) - if err != nil { - screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) - continue - } - b.SyntaxDef = syndef + files = append(files, file) break } } + if len(files) >= len(includes) { + break + } } - if b.SyntaxDef != nil && highlight.HasIncludes(b.SyntaxDef) { - includes := highlight.GetIncludes(b.SyntaxDef) + highlight.ResolveIncludes(b.SyntaxDef, files) +} - var files []*highlight.File - for _, f := range config.ListRuntimeFiles(config.RTSyntax) { - data, err := f.Data() - if err != nil { - screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) - continue - } - header, err := highlight.MakeHeaderYaml(data) - if err != nil { - screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) - continue - } +// UpdateRules updates the syntax rules and filetype for this buffer +// This is called when the colorscheme changes +func (b *Buffer) UpdateRules() { + if !b.Type.Syntax { + return + } + ft := b.Settings["filetype"].(string) + if ft == "off" { + return + } + + syntaxFiles := []syntaxFileBuffer{} + + // check for filenames first... + syntaxFile, foundDef, header := b.searchUserSyntax(ft, &syntaxFiles, false) + if !foundDef { + syntaxFile, header = b.searchRuntimeHeader(ft, &syntaxFiles, false) + } - for _, i := range includes { - if header.FileType == i { - file, err := highlight.ParseFile(data) - if err != nil { - screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) - continue + // ...try the file header definition afterwards + if syntaxFile == "" { + syntaxFile, foundDef, header = b.searchUserSyntax(ft, &syntaxFiles, true) + if !foundDef { + syntaxFile, header = b.searchRuntimeHeader(ft, &syntaxFiles, true) + } + } + + length := len(syntaxFiles) + if length > 0 { + signatureMatch := false + if length > 1 { + detectlimit := util.IntOpt(b.Settings["detectlimit"]) + lineCount := len(b.lines) + limit := lineCount + if detectlimit > 0 && lineCount > detectlimit { + limit = detectlimit + } + for i := 0; i < length && !signatureMatch; i++ { + if syntaxFiles[i].header.HasFileSignature() { + for j := 0; j < limit && !signatureMatch; j++ { + if syntaxFiles[i].header.MatchFileSignature(b.lines[j].data) { + syntaxFile = syntaxFiles[i].fileName + b.SyntaxDef = syntaxFiles[i].syntaxDef + header = syntaxFiles[i].header + signatureMatch = true + } } - files = append(files, file) - break } } - if len(files) >= len(includes) { - break - } } + if length == 1 || !signatureMatch { + syntaxFile = syntaxFiles[0].fileName + b.SyntaxDef = syntaxFiles[0].syntaxDef + header = syntaxFiles[0].header + } + } - highlight.ResolveIncludes(b.SyntaxDef, files) + if syntaxFile != "" && !foundDef { + // we found a syntax file using a syntax header file + b.searchRuntimeSyntax(syntaxFile, header) + } + + if b.SyntaxDef != nil && highlight.HasIncludes(b.SyntaxDef) { + b.solveSyntaxIncludes(b.SyntaxDef) } if b.Highlighter == nil || syntaxFile != "" { diff --git a/pkg/highlight/parser.go b/pkg/highlight/parser.go index 92e290fe85..63ffecebc7 100644 --- a/pkg/highlight/parser.go +++ b/pkg/highlight/parser.go @@ -39,6 +39,7 @@ type Def struct { type Header struct { FileType string FileNameRegex *regexp.Regexp + HeaderRegex *regexp.Regexp SignatureRegex *regexp.Regexp } @@ -46,6 +47,7 @@ type HeaderYaml struct { FileType string `yaml:"filetype"` Detect struct { FNameRegexStr string `yaml:"filename"` + HeaderRegexStr string `yaml:"header"` SignatureRegexStr string `yaml:"signature"` } `yaml:"detect"` } @@ -103,11 +105,15 @@ func MakeHeader(data []byte) (*Header, error) { var err error header.FileType = string(lines[0]) fnameRegexStr := string(lines[1]) - signatureRegexStr := string(lines[2]) + headerRegexStr := string(lines[2]) + signatureRegexStr := string(lines[3]) if fnameRegexStr != "" { header.FileNameRegex, err = regexp.Compile(fnameRegexStr) } + if err == nil && headerRegexStr != "" { + header.HeaderRegex, err = regexp.Compile(headerRegexStr) + } if err == nil && signatureRegexStr != "" { header.SignatureRegex, err = regexp.Compile(signatureRegexStr) } @@ -134,6 +140,9 @@ func MakeHeaderYaml(data []byte) (*Header, error) { if hdrYaml.Detect.FNameRegexStr != "" { header.FileNameRegex, err = regexp.Compile(hdrYaml.Detect.FNameRegexStr) } + if err == nil && hdrYaml.Detect.HeaderRegexStr != "" { + header.HeaderRegex, err = regexp.Compile(hdrYaml.Detect.HeaderRegexStr) + } if err == nil && hdrYaml.Detect.SignatureRegexStr != "" { header.SignatureRegex, err = regexp.Compile(hdrYaml.Detect.SignatureRegexStr) } @@ -154,6 +163,20 @@ func (header *Header) MatchFileName(filename string) bool { return false } +// HasFileHeader checks the presence of a stored header +func (header *Header) HasFileHeader() bool { + return header.HeaderRegex != nil +} + +// MatchFileHeader will check the given line with the stored regex +func (header *Header) MatchFileHeader(line []byte) bool { + if header.HasFileHeader() { + return header.HeaderRegex.Match(line) + } + + return false +} + // HasFileSignature checks the presence of a stored signature func (header *Header) HasFileSignature() bool { return header.SignatureRegex != nil @@ -161,7 +184,7 @@ func (header *Header) HasFileSignature() bool { // MatchFileSignature will check the given line with the stored regex func (header *Header) MatchFileSignature(line []byte) bool { - if header.SignatureRegex != nil { + if header.HasFileSignature() { return header.SignatureRegex.Match(line) } diff --git a/runtime/help/colors.md b/runtime/help/colors.md index 80a877d738..09d2850232 100644 --- a/runtime/help/colors.md +++ b/runtime/help/colors.md @@ -271,13 +271,27 @@ detect: ``` Micro will match this regex against a given filename to detect the filetype. -You may also provide an optional `signature` regex that will check a certain -amount of lines of a file to find specific marks. For example: + +You may also provide an optional `header` regex that will check the first line +of the file. For example: ``` detect: filename: "\\.ya?ml$" - signature: "%YAML" + header: "%YAML" +``` + +You may also provide an optional `signature` regex. This will be used in the +moment multiple `filename` regex have matched for different filetypes. +Popular for such a situation are C-like header files (*.h). The file will then +be checked line by line for the amount of `detectlimit` to try to solve the +ambiguity. +For example: + +``` +detect: + filename: "(\\.c(c|pp|xx)$|\\.h(h|pp|xx)?$|\\.ii?$|\\.(def)$)" + signature: "namespace|template|public|protected|private" ``` ### Syntax rules diff --git a/runtime/syntax/PowerShell.yaml b/runtime/syntax/PowerShell.yaml index daaa2b2107..a778199d4b 100644 --- a/runtime/syntax/PowerShell.yaml +++ b/runtime/syntax/PowerShell.yaml @@ -5,7 +5,6 @@ filetype: powershell detect: filename: "\\.ps(1|m1|d1)$" - #signature: "" rules: # - comment.block: # Block Comment diff --git a/runtime/syntax/README.md b/runtime/syntax/README.md index 5bcbf1380e..57c5cc4b6f 100644 --- a/runtime/syntax/README.md +++ b/runtime/syntax/README.md @@ -2,7 +2,8 @@ Here are micro's syntax files. -Each yaml file specifies how to detect the filetype based on file extension or given signature. The signature can be matched to all available lines of the file or to the value defined with the option `detectlimit` (to limit parse times) for a best "guess". +Each yaml file specifies how to detect the filetype based on file extension or if nothing matched based on headers (first line of the file). +In case more than one file type matched a signature can be used to solve the ambiguity by parsing all available lines of the file or to the value defined with the option `detectlimit` (to limit parse times) for a best "guess". Then there are patterns and regions linked to highlight groups which tell micro how to highlight that filetype. Making your own syntax files is very simple. I recommend you check the file after you are finished with the diff --git a/runtime/syntax/awk.yaml b/runtime/syntax/awk.yaml index 93ddf9ae98..ff3f6988e7 100644 --- a/runtime/syntax/awk.yaml +++ b/runtime/syntax/awk.yaml @@ -2,7 +2,7 @@ filetype: awk detect: filename: "\\.awk$" - signature: "^#!.*bin/(env +)?awk( |$)" + header: "^#!.*bin/(env +)?awk( |$)" rules: - preproc: "\\$[A-Za-z0-9_!@#$*?\\-]+" diff --git a/runtime/syntax/bat.yaml b/runtime/syntax/bat.yaml index 741f743778..a719a6d4ef 100644 --- a/runtime/syntax/bat.yaml +++ b/runtime/syntax/bat.yaml @@ -2,7 +2,6 @@ filetype: batch detect: filename: "(\\.bat$|\\.cmd$)" - # signature: "" rules: # Numbers diff --git a/runtime/syntax/crontab.yaml b/runtime/syntax/crontab.yaml index a5ee3746f6..86566512a7 100644 --- a/runtime/syntax/crontab.yaml +++ b/runtime/syntax/crontab.yaml @@ -2,7 +2,7 @@ filetype: crontab detect: filename: "crontab$" - signature: "^#.*?/etc/crontab" + header: "^#.*?/etc/crontab" rules: # The time and date fields are: diff --git a/runtime/syntax/csx.yaml b/runtime/syntax/csx.yaml index 61c5d6eac3..5ba6ea1117 100644 --- a/runtime/syntax/csx.yaml +++ b/runtime/syntax/csx.yaml @@ -1,7 +1,7 @@ filetype: csharp-script detect: filename: "\\.csx$" - signature: "^#!.*/(env +)?dotnet-script( |$)" + header: "^#!.*/(env +)?dotnet-script( |$)" rules: - include: "csharp" diff --git a/runtime/syntax/fish.yaml b/runtime/syntax/fish.yaml index e507809702..88798a04aa 100644 --- a/runtime/syntax/fish.yaml +++ b/runtime/syntax/fish.yaml @@ -2,7 +2,7 @@ filetype: fish detect: filename: "\\.fish$" - signature: "^#!.*/(env +)?fish( |$)" + header: "^#!.*/(env +)?fish( |$)" rules: # Numbers diff --git a/runtime/syntax/godoc.yaml b/runtime/syntax/godoc.yaml index 3d926b68e3..383f309774 100644 --- a/runtime/syntax/godoc.yaml +++ b/runtime/syntax/godoc.yaml @@ -5,7 +5,7 @@ filetype: godoc detect: filename: "\\.godoc$" - signature: package.*import + header: package.*import rules: - preproc: "^[^ ].*" diff --git a/runtime/syntax/groovy.yaml b/runtime/syntax/groovy.yaml index a19cdcd386..3aa0e28343 100644 --- a/runtime/syntax/groovy.yaml +++ b/runtime/syntax/groovy.yaml @@ -2,7 +2,7 @@ filetype: groovy detect: filename: "(\\.(groovy|gy|gvy|gsh|gradle)$|^[Jj]enkinsfile$)" - signature: "^#!.*/(env +)?groovy *$" + header: "^#!.*/(env +)?groovy *$" rules: # And the style guide for constants is CONSTANT_CASE diff --git a/runtime/syntax/html4.yaml b/runtime/syntax/html4.yaml index a7cfae3f0c..c132d61e98 100644 --- a/runtime/syntax/html4.yaml +++ b/runtime/syntax/html4.yaml @@ -2,7 +2,7 @@ filetype: html4 detect: filename: "\\.htm[l]?4$" - signature: "" + header: "" rules: - error: "<[^!].*?>" diff --git a/runtime/syntax/html5.yaml b/runtime/syntax/html5.yaml index 97bffde273..411d538581 100644 --- a/runtime/syntax/html5.yaml +++ b/runtime/syntax/html5.yaml @@ -2,7 +2,7 @@ filetype: html5 detect: filename: "\\.htm[l]?5$" - signature: "" + header: "" rules: - error: "<[^!].*?>" diff --git a/runtime/syntax/javascript.yaml b/runtime/syntax/javascript.yaml index 0b42caa69e..b2bfe4873f 100644 --- a/runtime/syntax/javascript.yaml +++ b/runtime/syntax/javascript.yaml @@ -2,7 +2,7 @@ filetype: javascript detect: filename: "(\\.js$|\\.es[5678]?$|\\.mjs$)" - signature: "^#!.*/(env +)?node( |$)" + header: "^#!.*/(env +)?node( |$)" rules: - constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b" diff --git a/runtime/syntax/json.yaml b/runtime/syntax/json.yaml index 35705b1db9..6d8408333b 100644 --- a/runtime/syntax/json.yaml +++ b/runtime/syntax/json.yaml @@ -2,7 +2,7 @@ filetype: json detect: filename: "\\.json$" - signature: "^\\{$" + header: "^\\{$" rules: - constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b" diff --git a/runtime/syntax/julia.yaml b/runtime/syntax/julia.yaml index 8a46e5cf29..c96ef0f34f 100644 --- a/runtime/syntax/julia.yaml +++ b/runtime/syntax/julia.yaml @@ -2,7 +2,7 @@ filetype: julia detect: filename: "\\.jl$" - signature: "^#!.*/(env +)?julia( |$)" + header: "^#!.*/(env +)?julia( |$)" rules: diff --git a/runtime/syntax/justfile.yaml b/runtime/syntax/justfile.yaml index 2a856edb8e..926edb21e2 100644 --- a/runtime/syntax/justfile.yaml +++ b/runtime/syntax/justfile.yaml @@ -3,7 +3,7 @@ filetype: 'justfile' detect: filename: "(^\\.?[Jj]ustfile|\\.just)$" - signature: "^#!.*/(env +)?[bg]?just --justfile" + header: "^#!.*/(env +)?[bg]?just --justfile" rules: - preproc: "\\<(ifeq|ifdef|ifneq|ifndef|else|endif)\\>" diff --git a/runtime/syntax/mail.yaml b/runtime/syntax/mail.yaml index 4cf588cea1..6ffe8733fd 100644 --- a/runtime/syntax/mail.yaml +++ b/runtime/syntax/mail.yaml @@ -2,7 +2,7 @@ filetype: mail detect: filename: "(.*/mutt-.*|\\.eml)$" - signature: "^From .* \\d+:\\d+:\\d+ \\d+" + header: "^From .* \\d+:\\d+:\\d+ \\d+" rules: - type: "^From .*" diff --git a/runtime/syntax/make_headers.go b/runtime/syntax/make_headers.go index c80c680e60..c00c27da8e 100644 --- a/runtime/syntax/make_headers.go +++ b/runtime/syntax/make_headers.go @@ -18,6 +18,7 @@ type HeaderYaml struct { FileType string `yaml:"filetype"` Detect struct { FNameRgx string `yaml:"filename"` + HeaderRgx string `yaml:"header"` SignatureRgx string `yaml:"signature"` } `yaml:"detect"` } @@ -25,6 +26,7 @@ type HeaderYaml struct { type Header struct { FileType string FNameRgx string + HeaderRgx string SignatureRgx string } @@ -59,6 +61,7 @@ func encode(name string, c HeaderYaml) { f, _ := os.Create(name + ".hdr") f.WriteString(c.FileType + "\n") f.WriteString(c.Detect.FNameRgx + "\n") + f.WriteString(c.Detect.HeaderRgx + "\n") f.WriteString(c.Detect.SignatureRgx + "\n") f.Close() } @@ -70,7 +73,8 @@ func decode(name string) Header { var hdr Header hdr.FileType = string(strs[0]) hdr.FNameRgx = string(strs[1]) - hdr.SignatureRgx = string(strs[2]) + hdr.HeaderRgx = string(strs[2]) + hdr.SignatureRgx = string(strs[3]) fmt.Printf("took %v\n", time.Since(start)) return hdr diff --git a/runtime/syntax/makefile.yaml b/runtime/syntax/makefile.yaml index 670935fa7e..7e90cdeb76 100644 --- a/runtime/syntax/makefile.yaml +++ b/runtime/syntax/makefile.yaml @@ -2,7 +2,7 @@ filetype: makefile detect: filename: "([Mm]akefile|\\.ma?k)$" - signature: "^#!.*/(env +)?[bg]?make( |$)" + header: "^#!.*/(env +)?[bg]?make( |$)" rules: - preproc: "\\<(ifeq|ifdef|ifneq|ifndef|else|endif)\\>" diff --git a/runtime/syntax/nginx.yaml b/runtime/syntax/nginx.yaml index 4a103ca326..02ea6eb0c2 100644 --- a/runtime/syntax/nginx.yaml +++ b/runtime/syntax/nginx.yaml @@ -2,7 +2,7 @@ filetype: nginx detect: filename: "nginx.*\\.conf$|\\.nginx$" - signature: "^(server|upstream)[a-z ]*\\{$" + header: "^(server|upstream)[a-z ]*\\{$" rules: - preproc: "\\b(events|server|http|location|upstream)[[:space:]]*\\{" diff --git a/runtime/syntax/patch.yaml b/runtime/syntax/patch.yaml index 6275d42381..996bdc38f5 100644 --- a/runtime/syntax/patch.yaml +++ b/runtime/syntax/patch.yaml @@ -2,7 +2,7 @@ filetype: patch detect: filename: "\\.(patch|diff)$" - signature: "^diff" + header: "^diff" rules: - brightgreen: "^\\+.*" diff --git a/runtime/syntax/perl.yaml b/runtime/syntax/perl.yaml index d43c264f1e..2b01b8942a 100644 --- a/runtime/syntax/perl.yaml +++ b/runtime/syntax/perl.yaml @@ -2,7 +2,7 @@ filetype: perl detect: filename: "\\.p[lmp]$" - signature: "^#!.*/(env +)?perl( |$)" + header: "^#!.*/(env +)?perl( |$)" rules: - type: "\\b(accept|alarm|atan2|bin(d|mode)|c(aller|homp|h(dir|mod|op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close|open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|ists|it|p))|f(cntl|ileno|lock|ork))\\b|\\b(get(c|login|peername|pgrp|ppid|priority|pwnam|(host|net|proto|serv)byname|pwuid|grgid|(host|net)byaddr|protobynumber|servbyport)|([gs]et|end)(pw|gr|host|net|proto|serv)ent|getsock(name|opt)|gmtime|goto|grep|hex|index|int|ioctl|join)\\b|\\b(keys|kill|last|length|link|listen|local(time)?|log|lstat|m|mkdir|msg(ctl|get|snd|rcv)|next|oct|open(dir)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re(ad(dir|link)?|cv|say|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|s|scalar|seek(dir)?)\\b|\\b(se(lect|mctl|mget|mop|nd|tpgrp|tpriority|tsockopt)|shift|shm(ctl|get|read|write)|shutdown|sin|sleep|socket(pair)?|sort|spli(ce|t)|sprintf|sqrt|srand|stat|study|substr|symlink|sys(call|read|tem|write)|tell(dir)?|time|tr(y)?|truncate|umask)\\b|\\b(un(def|link|pack|shift)|utime|values|vec|wait(pid)?|wantarray|warn|write)\\b" diff --git a/runtime/syntax/python2.yaml b/runtime/syntax/python2.yaml index 42f7ffb4ff..3a993b056c 100644 --- a/runtime/syntax/python2.yaml +++ b/runtime/syntax/python2.yaml @@ -2,7 +2,7 @@ filetype: python2 detect: filename: "\\.py2$" - signature: "^#!.*/(env +)?python2$" + header: "^#!.*/(env +)?python2$" rules: diff --git a/runtime/syntax/python3.yaml b/runtime/syntax/python3.yaml index 7e18df6e3a..5a060bff4c 100644 --- a/runtime/syntax/python3.yaml +++ b/runtime/syntax/python3.yaml @@ -2,7 +2,7 @@ filetype: python detect: filename: "\\.py(3)?$" - signature: "^#!.*/(env +)?python(3)?$" + header: "^#!.*/(env +)?python(3)?$" rules: # built-in objects diff --git a/runtime/syntax/ruby.yaml b/runtime/syntax/ruby.yaml index c84ada441c..03dac2e517 100644 --- a/runtime/syntax/ruby.yaml +++ b/runtime/syntax/ruby.yaml @@ -2,7 +2,7 @@ filetype: ruby detect: filename: "\\.(rb|rake|gemspec)$|^(.*[\\/])?(Gemfile|config.ru|Rakefile|Capfile|Vagrantfile|Guardfile|Appfile|Fastfile|Pluginfile|Podfile|\\.?[Bb]rewfile)$" - signature: "^#!.*/(env +)?ruby( |$)" + header: "^#!.*/(env +)?ruby( |$)" rules: - comment.bright: diff --git a/runtime/syntax/sage.yaml b/runtime/syntax/sage.yaml index 8d2cb07a7d..e24fbeb603 100644 --- a/runtime/syntax/sage.yaml +++ b/runtime/syntax/sage.yaml @@ -2,7 +2,7 @@ filetype: sage detect: filename: "\\.sage$" - signature: "^#!.*/(env +)?sage( |$)" + header: "^#!.*/(env +)?sage( |$)" rules: diff --git a/runtime/syntax/sed.yaml b/runtime/syntax/sed.yaml index a3bf1595df..ed33bae599 100644 --- a/runtime/syntax/sed.yaml +++ b/runtime/syntax/sed.yaml @@ -2,7 +2,7 @@ filetype: sed detect: filename: "\\.sed$" - signature: "^#!.*bin/(env +)?sed( |$)" + header: "^#!.*bin/(env +)?sed( |$)" rules: - symbol.operator: "[|^$.*+]" diff --git a/runtime/syntax/sh.yaml b/runtime/syntax/sh.yaml index 3a0d9d4540..3ace32680d 100644 --- a/runtime/syntax/sh.yaml +++ b/runtime/syntax/sh.yaml @@ -24,7 +24,7 @@ filetype: shell # * bash-fc. (followed by a random string) detect: filename: "(\\.(sh|bash|ash|ebuild)$|(\\.bash(rc|_aliases|_functions|_profile)|\\.?profile|Pkgfile|pkgmk\\.conf|rc\\.conf|PKGBUILD|APKBUILD)$|bash-fc\\.)" - signature: "^#!.*/(env +)?(ba)?(a)?(mk)?sh( |$)" + header: "^#!.*/(env +)?(ba)?(a)?(mk)?sh( |$)" rules: # Numbers diff --git a/runtime/syntax/syntax_converter.go b/runtime/syntax/syntax_converter.go index f8af15dc6c..d2954e3aa7 100644 --- a/runtime/syntax/syntax_converter.go +++ b/runtime/syntax/syntax_converter.go @@ -137,7 +137,7 @@ func generateFile(filetype, syntax, header string, rules []interface{}) string { output += fmt.Sprintf("detect: \n filename: \"%s\"\n", strings.Replace(strings.Replace(syntax, "\\", "\\\\", -1), "\"", "\\\"", -1)) if header != "" { - output += fmt.Sprintf(" signature: \"%s\"\n", strings.Replace(strings.Replace(header, "\\", "\\\\", -1), "\"", "\\\"", -1)) + output += fmt.Sprintf(" header: \"%s\"\n", strings.Replace(strings.Replace(header, "\\", "\\\\", -1), "\"", "\\\"", -1)) } output += "\nrules:\n" diff --git a/runtime/syntax/systemd.yaml b/runtime/syntax/systemd.yaml index 9b66877624..a8650be4b2 100644 --- a/runtime/syntax/systemd.yaml +++ b/runtime/syntax/systemd.yaml @@ -2,7 +2,7 @@ filetype: systemd detect: filename: "\\.(service|socket|timer)$" - signature: "^\\[Unit\\]$" + header: "^\\[Unit\\]$" rules: - statement: "^(Accept|After|Alias|AllowIsolate|Also|ANSI_COLOR|_AUDIT_LOGINUID|_AUDIT_SESSION|Backlog|Before|BindIPv6Only|BindsTo|BindToDevice|BlockIOReadBandwidth|BlockIOWeight|BlockIOWriteBandwidth|_BOOT_ID|Broadcast|BUG_REPORT_URL|BusName|Capabilities|CapabilityBoundingSet|CHASSIS|cipher|class|_CMDLINE|CODE_FILE|CODE_FUNC|CODE_LINE|_COMM|Compress|ConditionACPower|ConditionCapability|ConditionDirectoryNotEmpty|ConditionFileIsExecutable|ConditionFileNotEmpty|ConditionHost|ConditionKernelCommandLine|ConditionNull|ConditionPathExists|ConditionPathExistsGlob|ConditionPathIsDirectory|ConditionPathIsMountPoint|ConditionPathIsReadWrite|ConditionPathIsSymbolicLink|ConditionSecurity|ConditionVirtualization|Conflicts|ControlGroup|ControlGroupAttribute|ControlGroupModify|ControlGroupPersistent|controllers|Controllers|CPE_NAME|CPUAffinity|CPUSchedulingPolicy|CPUSchedulingPriority|CPUSchedulingResetOnFork|CPUShares|CrashChVT|CrashShell|__CURSOR|debug|DefaultControllers|DefaultDependencies|DefaultLimitAS|DefaultLimitCORE|DefaultLimitCPU|DefaultLimitDATA|DefaultLimitFSIZE|DefaultLimitLOCKS|DefaultLimitMEMLOCK|DefaultLimitMSGQUEUE|DefaultLimitNICE|DefaultLimitNOFILE|DefaultLimitNPROC|DefaultLimitRSS|DefaultLimitRTPRIO|DefaultLimitRTTIME|DefaultLimitSIGPENDING|DefaultLimitSTACK|DefaultStandardError|DefaultStandardOutput|Description|DeviceAllow|DeviceDeny|DirectoryMode|DirectoryNotEmpty|Documentation|DumpCore|entropy|Environment|EnvironmentFile|ERRNO|event_timeout|_EXE|ExecReload|ExecStart|ExecStartPost|ExecStartPre|ExecStop|ExecStopPost|ExecStopPre|filter|FONT|FONT_MAP|FONT_UNIMAP|ForwardToConsole|ForwardToKMsg|ForwardToSyslog|FreeBind|freq|FsckPassNo|fstab|_GID|Group|GuessMainPID|HandleHibernateKey|HandleLidSwitch|HandlePowerKey|HandleSuspendKey|hash|HibernateKeyIgnoreInhibited|HOME_URL|_HOSTNAME|ICON_NAME|ID|IdleAction|IdleActionSec|ID_LIKE|ID_MODEL|ID_MODEL_FROM_DATABASE|IgnoreOnIsolate|IgnoreOnSnapshot|IgnoreSIGPIPE|InaccessibleDirectories|InhibitDelayMaxSec|init|IOSchedulingClass|IOSchedulingPriority|IPTOS|IPTTL|JobTimeoutSec|JoinControllers|KeepAlive|KEYMAP|KEYMAP_TOGGLE|KillExcludeUsers|KillMode|KillOnlyUsers|KillSignal|KillUserProcesses|LidSwitchIgnoreInhibited|LimitAS|LimitCORE|LimitCPU|LimitDATA|LimitFSIZE|LimitLOCKS|LimitMEMLOCK|LimitMSGQUEUE|LimitNICE|LimitNOFILE|LimitNPROC|LimitRSS|LimitRTPRIO|LimitRTTIME|LimitSIGPENDING|LimitSTACK|link_priority|valueListenDatagram|ListenFIFO|ListenMessageQueue|ListenNetlink|ListenSequentialPacket|ListenSpecial|ListenStream|LogColor|LogLevel|LogLocation|LogTarget|luks|_MACHINE_ID|MakeDirectory|Mark|MaxConnections|MaxFileSec|MaxLevelConsole|MaxLevelKMsg|MaxLevelStore|MaxLevelSyslog|MaxRetentionSec|MemoryLimit|MemorySoftLimit|MESSAGE|MESSAGE_ID|MessageQueueMaxMessages|MessageQueueMessageSize|__MONOTONIC_TIMESTAMP|MountFlags|NAME|NAutoVTs|Nice|NonBlocking|NoNewPrivileges|NotifyAccess|OnActiveSec|OnBootSec|OnCalendar|OnFailure|OnFailureIsolate|OnStartupSec|OnUnitActiveSec|OnUnitInactiveSec|OOMScoreAdjust|Options|output|PAMName|PartOf|PassCredentials|PassSecurity|PathChanged|PathExists|PathExistsGlob|PathModified|PermissionsStartOnly|_PID|PIDFile|PipeSize|PowerKeyIgnoreInhibited|PRETTY_HOSTNAME|PRETTY_NAME|Priority|PRIORITY|PrivateNetwork|PrivateTmp|PropagatesReloadTo|pss|RateLimitBurst|RateLimitInterval|ReadOnlyDirectories|ReadWriteDirectories|__REALTIME_TIMESTAMP|ReceiveBuffer|RefuseManualStart|RefuseManualStop|rel|ReloadPropagatedFrom|RemainAfterExit|RequiredBy|Requires|RequiresMountsFor|RequiresOverridable|Requisite|RequisiteOverridable|ReserveVT|ResetControllers|Restart|RestartPreventExitStatus|RestartSec|RootDirectory|RootDirectoryStartOnly|RuntimeKeepFree|RuntimeMaxFileSize|RuntimeMaxUse|RuntimeWatchdogSec|samples|scale_x|scale_y|Seal|SecureBits|_SELINUX_CONTEXT|SendBuffer|SendSIGKILL|Service|ShowStatus|ShutdownWatchdogSec|size|SmackLabel|SmackLabelIPIn|SmackLabelIPOut|SocketMode|Sockets|SourcePath|_SOURCE_REALTIME_TIMESTAMP|SplitMode|StandardError|StandardInput|StandardOutput|StartLimitAction|StartLimitBurst|StartLimitInterval|static_node|StopWhenUnneeded|Storage|string_escape|none|replaceSuccessExitStatus|SupplementaryGroups|SUPPORT_URL|SuspendKeyIgnoreInhibited|SyslogFacility|SYSLOG_FACILITY|SyslogIdentifier|SYSLOG_IDENTIFIER|SyslogLevel|SyslogLevelPrefix|SYSLOG_PID|SystemCallFilter|SYSTEMD_ALIAS|_SYSTEMD_CGROUP|_SYSTEMD_OWNER_UID|SYSTEMD_READY|_SYSTEMD_SESSION|_SYSTEMD_UNIT|_SYSTEMD_USER_UNIT|SYSTEMD_WANTS|SystemKeepFree|SystemMaxFileSize|SystemMaxUse|SysVStartPriority|TCPCongestion|TCPWrapName|timeout|TimeoutSec|TimeoutStartSec|TimeoutStopSec|TimerSlackNSec|Transparent|_TRANSPORT|tries|TTYPath|TTYReset|TTYVHangup|TTYVTDisallocate|Type|_UID|UMask|Unit|User|UtmpIdentifier|VERSION|VERSION_ID|WantedBy|Wants|WatchdogSec|What|Where|WorkingDirectory)=" diff --git a/runtime/syntax/tcl.yaml b/runtime/syntax/tcl.yaml index 1b4ae7e5c9..b87a7d7906 100644 --- a/runtime/syntax/tcl.yaml +++ b/runtime/syntax/tcl.yaml @@ -2,7 +2,7 @@ filetype: tcl detect: filename: "\\.tcl$" - signature: "^#!.*/(env +)?tclsh( |$)" + header: "^#!.*/(env +)?tclsh( |$)" rules: - statement: "\\b(after|append|array|auto_execok|auto_import|auto_load|auto_load_index|auto_qualify|binary|break|case|catch|cd|clock|close|concat|continue|else|elseif|encoding|eof|error|eval|exec|exit|expr|fblocked|fconfigure|fcopy|file|fileevent|flush|for|foreach|format|gets|glob|global|history|if|incr|info|interp|join|lappend|lindex|linsert|list|llength|load|lrange|lreplace|lsearch|lset|lsort|namespace|open|package|pid|puts|pwd|read|regexp|regsub|rename|return|scan|seek|set|socket|source|split|string|subst|switch|tclLog|tell|time|trace|unknown|unset|update|uplevel|upvar|variable|vwait|while)\\b" diff --git a/runtime/syntax/xml.yaml b/runtime/syntax/xml.yaml index 0e9b901e85..df4cde8118 100644 --- a/runtime/syntax/xml.yaml +++ b/runtime/syntax/xml.yaml @@ -2,7 +2,7 @@ filetype: xml detect: filename: "\\.(xml|sgml?|rng|svg|plist)$" - signature: "<\\?xml.*\\?>" + header: "<\\?xml.*\\?>" rules: - preproc: diff --git a/runtime/syntax/yaml.yaml b/runtime/syntax/yaml.yaml index c21286e4f6..54d4a64725 100644 --- a/runtime/syntax/yaml.yaml +++ b/runtime/syntax/yaml.yaml @@ -2,7 +2,7 @@ filetype: yaml detect: filename: "\\.ya?ml$" - signature: "%YAML" + header: "%YAML" rules: - type: "(^| )!!(binary|bool|float|int|map|null|omap|seq|set|str) " diff --git a/runtime/syntax/zsh.yaml b/runtime/syntax/zsh.yaml index 3b7e059396..a283213104 100644 --- a/runtime/syntax/zsh.yaml +++ b/runtime/syntax/zsh.yaml @@ -2,7 +2,7 @@ filetype: zsh detect: filename: "(\\.zsh$|\\.?(zshenv|zprofile|zshrc|zlogin|zlogout)$)" - signature: "^#!.*/(env +)?zsh( |$)" + header: "^#!.*/(env +)?zsh( |$)" rules: ## Numbers