├── examples ├── README.md └── syncat.go ├── syntax_files ├── patch.yaml ├── conf.yaml ├── man.yaml ├── po.yaml ├── xml.yaml ├── r.yaml ├── pkg-config.yaml ├── sed.yaml ├── git-config.yaml ├── yum.yaml ├── xresources.yaml ├── inputrc.yaml ├── reST.yaml ├── sls.yaml ├── ini.yaml ├── privoxy-filter.yaml ├── mpdconf.yaml ├── ledger.yaml ├── peg.yaml ├── colortest.yaml ├── lisp.yaml ├── caddyfile.yaml ├── lfe.yaml ├── syntax_checker.go ├── haml.yaml ├── README.md ├── kickstart.yaml ├── mail.yaml ├── keymap.yaml ├── gentoo-etc-portage.yaml ├── pov.yaml ├── ocaml.yaml ├── micro.yaml ├── vi.yaml ├── git-rebase-todo.yaml ├── tex.yaml ├── groff.yaml ├── privoxy-config.yaml ├── git-commit.yaml ├── json.yaml ├── dockerfile.yaml ├── yaml.yaml ├── coffeescript.yaml ├── scala.yaml ├── toml.yaml ├── vala.yaml ├── dot.yaml ├── glsl.yaml ├── clojure.yaml ├── java.yaml ├── nanorc.yaml ├── markdown.yaml ├── cmake.yaml ├── rust.yaml ├── html5.yaml ├── makefile.yaml ├── pony.yaml ├── swift.yaml ├── ruby.yaml ├── asciidoc.yaml ├── html4.yaml ├── c++.yaml ├── cython.yaml ├── dart.yaml ├── puppet.yaml ├── javascript.yaml ├── awk.yaml ├── privoxy-action.yaml ├── perl.yaml ├── perl6.yaml ├── haskell.yaml ├── solidity.yaml ├── html.yaml ├── typescript.yaml ├── rpmspec.yaml ├── c.yaml ├── pascal.yaml ├── crystal.yaml ├── sh.yaml ├── cpp.yaml ├── go.yaml ├── csharp.yaml ├── fish.yaml ├── tcl.yaml ├── zsh.yaml ├── sql.yaml ├── gentoo-ebuild.yaml ├── nim.yaml ├── gdscript.yaml ├── vhdl.yaml ├── erb.yaml ├── objc.yaml ├── python3.yaml ├── python2.yaml ├── php.yaml ├── fortran.yaml ├── lua.yaml ├── arduino.yaml ├── lilypond.yaml ├── golo.yaml ├── d.yaml ├── nginx.yaml ├── systemd.yaml ├── conky.yaml ├── apacheconf.yaml ├── css.yaml └── asm.yaml ├── ftdetect.go ├── LICENSE ├── README.md ├── parser.go └── highlighter.go /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | These examples will find the `syntax_files` directory by using your `GOPATH` environment variable. 4 | -------------------------------------------------------------------------------- /syntax_files/patch.yaml: -------------------------------------------------------------------------------- 1 | filetype: patch 2 | 3 | detect: 4 | filename: "\\.(patch|diff)$" 5 | 6 | rules: 7 | - brightgreen: "^\\+.*" 8 | - green: "^\\+\\+\\+.*" 9 | - brightblue: "^ .*" 10 | - brightred: "^-.*" 11 | - red: "^---.*" 12 | - brightyellow: "^@@.*" 13 | - magenta: "^diff.*" 14 | -------------------------------------------------------------------------------- /syntax_files/conf.yaml: -------------------------------------------------------------------------------- 1 | filetype: conf 2 | 3 | detect: 4 | filename: "\\.c[o]?nf$" 5 | 6 | rules: 7 | - constant.string: 8 | start: "\"" 9 | end: "\"" 10 | skip: "\\\\." 11 | rules: [] 12 | 13 | - comment: 14 | start: "#" 15 | end: "$" 16 | rules: [] 17 | 18 | -------------------------------------------------------------------------------- /syntax_files/man.yaml: -------------------------------------------------------------------------------- 1 | filetype: man 2 | 3 | detect: 4 | filename: "\\.[1-9]x?$" 5 | 6 | rules: 7 | - green: "\\.(S|T)H.*$" 8 | - brightgreen: "\\.(S|T)H|\\.TP" 9 | - brightred: "\\.(BR?|I[PR]?).*$" 10 | - brightblue: "\\.(BR?|I[PR]?|PP)" 11 | - brightwhite: "\\\\f[BIPR]" 12 | - yellow: "\\.(br|DS|RS|RE|PD)" 13 | -------------------------------------------------------------------------------- /syntax_files/po.yaml: -------------------------------------------------------------------------------- 1 | filetype: po 2 | 3 | detect: 4 | filename: "\\.pot?$" 5 | 6 | rules: 7 | - preproc: "\\b(msgid|msgstr)\\b" 8 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 9 | - special: "\\\\.?" 10 | - comment: "(^|[[:space:]])#([^{].*)?$" 11 | - indent-char.whitespace: "[[:space:]]+$" 12 | - indent-char: " + +| + +" 13 | -------------------------------------------------------------------------------- /syntax_files/xml.yaml: -------------------------------------------------------------------------------- 1 | filetype: xml 2 | 3 | detect: 4 | filename: "\\.(xml|sgml?|rng|plist)$" 5 | 6 | rules: 7 | - identifier: "<.*?>" 8 | - comment: 9 | start: "" 11 | rules: [] 12 | - comment: 13 | start: "" 15 | rules: [] 16 | - special: "&[^;]*;" 17 | -------------------------------------------------------------------------------- /syntax_files/r.yaml: -------------------------------------------------------------------------------- 1 | filetype: r 2 | 3 | detect: 4 | filename: "\\.(r|R)$" 5 | 6 | rules: 7 | - statement: "\\b(break|else|for|function|if|in|next|repeat|return|while)\\b" 8 | - constant: "\\b(TRUE|FALSE|NULL|Inf|NaN|NA|NA_integer_|NA_real_|NA_complex_|NA_character_)\\b" 9 | - comment: 10 | start: "#" 11 | end: "$" 12 | rules: [] 13 | -------------------------------------------------------------------------------- /syntax_files/pkg-config.yaml: -------------------------------------------------------------------------------- 1 | filetype: pc 2 | 3 | detect: 4 | filename: "\\.pc$" 5 | 6 | rules: 7 | - preproc: "^(Name|Description|URL|Version|Conflicts|Cflags):" 8 | - preproc: "^(Requires|Libs)(\\.private)?:" 9 | - symbol.operator: "=" 10 | - identifier.var: "\\$\\{[A-Za-z_][A-Za-z0-9_]*\\}" 11 | - indent-char.whitespace: "[[:space:]]+$" 12 | - indent-char: " + +| + +" 13 | -------------------------------------------------------------------------------- /syntax_files/sed.yaml: -------------------------------------------------------------------------------- 1 | filetype: sed 2 | 3 | detect: 4 | filename: "\\.sed$" 5 | header: "^#!.*bin/(env +)?sed( |$)" 6 | 7 | rules: 8 | - symbol.operator: "[|^$.*+]" 9 | - constant.number: "\\{[0-9]+,?[0-9]*\\}" 10 | - constant.specialChar: "\\\\." 11 | - comment: "(^|[[:space:]])#([^{].*)?$" 12 | - indent-char.whitespace: "[[:space:]]+$" 13 | - indent-char: " + +| + +" 14 | -------------------------------------------------------------------------------- /syntax_files/git-config.yaml: -------------------------------------------------------------------------------- 1 | filetype: git-config 2 | 3 | detect: 4 | filename: "git(config|modules)$|\\.git/config$" 5 | 6 | rules: 7 | - constant: "\\<(true|false)\\>" 8 | - keyword: "^[[:space:]]*[^=]*=" 9 | - constant: "^[[:space:]]*\\[.*\\]$" 10 | - constant: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 11 | - comment: 12 | start: "#" 13 | end: "$" 14 | rules: [] 15 | -------------------------------------------------------------------------------- /syntax_files/yum.yaml: -------------------------------------------------------------------------------- 1 | filetype: yum 2 | 3 | detect: 4 | filename: "\\.repo$|yum.*\\.conf$" 5 | 6 | rules: 7 | - identifier: "^[[:space:]]*[^=]*=" 8 | - constant.specialChar: "^[[:space:]]*\\[.*\\]$" 9 | - statement: "\\$(releasever|arch|basearch|uuid|YUM[0-9])" 10 | - comment: "(^|[[:space:]])#([^{].*)?$" 11 | - indent-char.whitespace: "[[:space:]]+$" 12 | - indent-char: " + +| + +" 13 | -------------------------------------------------------------------------------- /syntax_files/xresources.yaml: -------------------------------------------------------------------------------- 1 | filetype: xresources 2 | 3 | detect: 4 | filename: "X(defaults|resources)$" 5 | 6 | rules: 7 | - special: "^[[:alnum:]]+\\*" 8 | - identifier.var: "\\*[[:alnum:]]+\\:" 9 | - constant.number: "\\b[0-9]+\\b" 10 | - symbol.operator: "[*:=]" 11 | - constant.bool: "\\b(true|false)\\b" 12 | - comment: "(^|[[:space:]])#([^{].*)?$" 13 | - indent-char.whitespace: "[[:space:]]+$" 14 | - indent-char: " + +| + +" 15 | -------------------------------------------------------------------------------- /syntax_files/inputrc.yaml: -------------------------------------------------------------------------------- 1 | filetype: inputrc 2 | 3 | detect: 4 | filename: "inputrc$" 5 | 6 | rules: 7 | - constant.bool.false: "\\b(off|none)\\b" 8 | - constant.bool.true: "\\bon\\b" 9 | - preproc: "\\bset|\\$include\\b" 10 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 11 | - constant.specialChar: "\\\\.?" 12 | - comment: "(^|[[:space:]])#([^{].*)?$" 13 | - indent-char.whitespace: "[[:space:]]+$" 14 | - indent-char: " + +| + +" 15 | -------------------------------------------------------------------------------- /syntax_files/reST.yaml: -------------------------------------------------------------------------------- 1 | filetype: rst 2 | 3 | detect: 4 | filename: "\\.rest$|\\.rst$" 5 | 6 | rules: 7 | - statement: "\\*\\*[^*]+\\*\\*" 8 | - preproc: "::" 9 | - constant.string: "`[^`]+`_{1,2}" 10 | - constant.string: "``[^`]+``" 11 | - identifier: "^\\.\\. .*$" 12 | - identifier: "^__ .*$" 13 | - type: "^###+$" 14 | - type: "^\\*\\*\\*+$" 15 | - special: "^===+$" 16 | - special: "^---+$" 17 | - special: "^\\^\\^\\^+$" 18 | - special: "^\"\"\"+$" 19 | -------------------------------------------------------------------------------- /syntax_files/sls.yaml: -------------------------------------------------------------------------------- 1 | filetype: salt 2 | 3 | detect: 4 | filename: "\\.sls$" 5 | 6 | rules: 7 | - identifier.var: "^[^ -].*:$" 8 | - identifier.var: ".*:" 9 | - default: "salt:" 10 | - constant.number: "/*[0-9]/*" 11 | - constant.bool: "\\b(True|False)\\b" 12 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 13 | - special: "\\b(grain|grains|compound|pcre|grain_pcre|list|pillar)\\b" 14 | - comment: "^#.*" 15 | - statement: "\\b(if|elif|else|or|not|and|endif|end)\\b" 16 | -------------------------------------------------------------------------------- /syntax_files/ini.yaml: -------------------------------------------------------------------------------- 1 | filetype: ini 2 | 3 | detect: 4 | filename: "\\.(ini|desktop|lfl|override)$|(mimeapps\\.list|pinforc|setup\\.cfg)$|weechat/.+\\.conf$" 5 | header: "^\\[[A-Za-z]+\\]$" 6 | 7 | rules: 8 | - constant.bool.true: "\\btrue\\b" 9 | - constant.bool.false: "\\bfalse\\b" 10 | - identifier: "^[[:space:]]*[^=]*=" 11 | - special: "^[[:space:]]*\\[.*\\]$" 12 | - statement: "[=;]" 13 | - comment: "(^|[[:space:]])#([^{].*)?$" 14 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 15 | -------------------------------------------------------------------------------- /syntax_files/privoxy-filter.yaml: -------------------------------------------------------------------------------- 1 | filetype: privoxy-filter 2 | 3 | detect: 4 | filename: "\\.filter$" 5 | 6 | rules: 7 | - statement: "^(FILTER|CLIENT-HEADER-FILTER|CLIENT-HEADER-TAGGER|SERVER-HEADER-FILTER|SERVER-HEADER-TAGGER): [a-z-]+" 8 | - identifier: "^(FILTER|CLIENT-HEADER-FILTER|CLIENT-HEADER-TAGGER|SERVER-HEADER-FILTER|SERVER-HEADER-TAGGER):" 9 | - constant.specialChar: "\\\\.?" 10 | - comment: "(^|[[:space:]])#([^{].*)?$" 11 | - indent-char.whitespace: "[[:space:]]+$" 12 | - indent-char: " + +| + +" 13 | -------------------------------------------------------------------------------- /syntax_files/mpdconf.yaml: -------------------------------------------------------------------------------- 1 | filetype: mpd 2 | 3 | detect: 4 | filename: "mpd\\.conf$" 5 | 6 | rules: 7 | - statement: "\\b(user|group|bind_to_address|host|port|plugin|name|type)\\b" 8 | - statement: "\\b((music|playlist)_directory|(db|log|state|pid|sticker)_file)\\b" 9 | - special: "^(input|audio_output|decoder)[[:space:]]*\\{|\\}" 10 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 11 | - comment: "(^|[[:space:]])#([^{].*)?$" 12 | - indent-char.whitespace: "[[:space:]]+$" 13 | - indent-char: " + +| + +" 14 | -------------------------------------------------------------------------------- /syntax_files/ledger.yaml: -------------------------------------------------------------------------------- 1 | filetype: ledger 2 | 3 | detect: 4 | filename: "(^|\\.|/)ledger|ldgr|beancount|bnct$" 5 | 6 | rules: 7 | - special: "^([0-9]{4}(/|-)[0-9]{2}(/|-)[0-9]{2}|[=~]) .*" 8 | - constant: "^[0-9]{4}(/|-)[0-9]{2}(/|-)[0-9]{2}" 9 | - statement: "^~ .*" 10 | - identifier.var: "^= .*" 11 | - identifier: "^[[:space:]]+(![[:space:]]+)?\\(?[A-Za-z ]+(:[A-Za-z ]+)*\\)?" 12 | - identifier: "^[[:space:]]+(![[:space:]]+)?\\(?[A-Za-z_\\-]+(:[A-Za-z_\\-]+)*\\)?" 13 | - symbol: "[*!]" 14 | - comment: "^[[:space:]]*;.*" 15 | -------------------------------------------------------------------------------- /syntax_files/peg.yaml: -------------------------------------------------------------------------------- 1 | filetype: peg 2 | 3 | detect: 4 | filename: "\\.l?peg$" 5 | 6 | rules: 7 | - identifier: "^[[:space:]]*[A-Za-z][A-Za-z0-9_]*[[:space:]]*<-" 8 | - constant.number: "\\^[+-]?[0-9]+" 9 | - symbol.operator: "[-+*?^/!&]|->|<-|=>" 10 | - identifier.var: "%[A-Za-z][A-Za-z0-9_]*" 11 | - special: "\\[[^]]*\\]" 12 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 13 | - comment: "(^|[[:space:]])\\-\\-.*$" 14 | - todo: "TODO:?" 15 | - indent-char.whitespace: "[[:space:]]+$" 16 | - indent-char: " + +| + +" 17 | -------------------------------------------------------------------------------- /syntax_files/colortest.yaml: -------------------------------------------------------------------------------- 1 | filetype: colortest 2 | 3 | detect: 4 | filename: "ColorTest$" 5 | 6 | rules: 7 | - black: "\\bPLAIN\\b" 8 | - red: "\\bred\\b" 9 | - green: "\\bgreen\\b" 10 | - yellow: "\\byellow\\b" 11 | - blue: "\\bblue\\b" 12 | - magenta: "\\bmagenta\\b" 13 | - cyan: "\\bcyan\\b" 14 | - brightred: "\\bbrightred\\b" 15 | - brightgreen: "\\bbrightgreen\\b" 16 | - brightyellow: "\\bbrightyellow\\b" 17 | - brightblue: "\\bbrightblue\\b" 18 | - brightmagenta: "\\bbrightmagenta\\b" 19 | - brightcyan: "\\bbrightcyan\\b" 20 | -------------------------------------------------------------------------------- /syntax_files/lisp.yaml: -------------------------------------------------------------------------------- 1 | filetype: lisp 2 | 3 | detect: 4 | filename: "(emacs|zile)$|\\.(el|li?sp|scm|ss)$" 5 | 6 | rules: 7 | - default: "\\([a-z-]+" 8 | - symbol: "\\(([\\-+*/<>]|<=|>=)|'" 9 | - constant.number: "\\b[0-9]+b>" 10 | - special: "\\bnil\\b" 11 | - preproc: "\\b[tT]b>" 12 | - constant.string: "\\\"(\\\\.|[^\"])*\\\"" 13 | - constant.specialChar: "'[A-Za-z][A-Za-z0-9_-]+" 14 | - constant.specialChar: "\\\\.?" 15 | - comment: "(^|[[:space:]]);.*" 16 | - indent-char.whitespace: "[[:space:]]+$" 17 | - indent-char: " + +| + +" 18 | -------------------------------------------------------------------------------- /syntax_files/caddyfile.yaml: -------------------------------------------------------------------------------- 1 | filetype: caddyfile 2 | 3 | detect: 4 | filename: "Caddyfile" 5 | 6 | rules: 7 | - identifier: "^\\s*\\S+(\\s|$)" 8 | - type: "^([\\w.:/-]+,? ?)+[,{]$" 9 | - constant.specialChar: "\\s{$" 10 | - constant.specialChar: "^\\s*}$" 11 | - constant.string: 12 | start: "\"" 13 | end: "\"" 14 | skip: "\\\\." 15 | rules: 16 | - constant.specialChar: "\\\\." 17 | 18 | - preproc: "\\{(\\w+|\\$\\w+|%\\w+%)\\}" 19 | - comment: 20 | start: "#" 21 | end: "$" 22 | rules: [] 23 | 24 | -------------------------------------------------------------------------------- /syntax_files/lfe.yaml: -------------------------------------------------------------------------------- 1 | filetype: lfe 2 | 3 | detect: 4 | filename: "lfe$|\\.lfe$" 5 | 6 | rules: 7 | - symbol.brackets: "\\(|\\)" 8 | - type: "defun|define-syntax|define|defmacro|defmodule|export" 9 | - constant: "\\ [A-Za-z][A-Za-z0-9_-]+\\ " 10 | - symbol.operator: "\\(([\\-+*/<>]|<=|>=)|'" 11 | - constant.number: "\\b[0-9]+\\b" 12 | - constant.string: "\\\"(\\\\.|[^\"])*\\\"" 13 | - special: "['|`][A-Za-z][A-Za-z0-9_\\-]+" 14 | - constant.specialChar: "\\\\.?" 15 | - comment: "(^|[[:space:]]);.*" 16 | - indent-char.whitespace: "[[:space:]]+$" 17 | - indent-char: " + +| + +" 18 | -------------------------------------------------------------------------------- /syntax_files/syntax_checker.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "strings" 7 | 8 | "github.com/zyedidia/highlight" 9 | ) 10 | 11 | func main() { 12 | files, _ := ioutil.ReadDir(".") 13 | 14 | hadErr := false 15 | for _, f := range files { 16 | if strings.HasSuffix(f.Name(), ".yaml") { 17 | input, _ := ioutil.ReadFile(f.Name()) 18 | _, err := highlight.ParseDef(input) 19 | if err != nil { 20 | hadErr = true 21 | fmt.Printf("%s:\n", f.Name()) 22 | fmt.Println(err) 23 | continue 24 | } 25 | } 26 | } 27 | if !hadErr { 28 | fmt.Println("No issues!") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /syntax_files/haml.yaml: -------------------------------------------------------------------------------- 1 | filetype: haml 2 | 3 | detect: 4 | filename: "\\.haml$" 5 | 6 | rules: 7 | - symbol: "-|=" 8 | - default: "->|=>" 9 | - constant: "([ ]|^)%[0-9A-Za-z_]+>" 10 | - special: ":[0-9A-Za-z_]+>" 11 | - type: "\\.[A-Za-z_]+>" 12 | - constant.string: "\"([^\"]|(\\\\\"))*\"|%[QW]?\\{[^}]*\\}|%[QW]?\\([^)]*\\)|%[QW]?<[^>]*>|%[QW]?\\$[^$]*\\$|%[QW]?\\^[^^]*\\^|%[QW]?![^!]*!" 13 | - constant.string: "'([^']|(\\\\'))*'|%[qw]\\{[^}]*\\}|%[qw]\\([^)]*\\)|%[qw]<[^>]*>|%[qw]\\[[^]]*\\]|%[qw]\\$[^$]*\\$|%[qw]\\^[^^]*\\^|%[qw]![^!]*!" 14 | - identifier: "#\\{[^}]*\\}" 15 | - identifier.var: "(@|@@)[0-9A-Z_a-z]+" 16 | - comment: "#[^{].*$|#$" 17 | -------------------------------------------------------------------------------- /syntax_files/README.md: -------------------------------------------------------------------------------- 1 | # Syntax Files 2 | 3 | Here are highlights's syntax files. 4 | 5 | Each yaml file specifies how to detect the filetype based on file extension or headers (first line of the file). 6 | Then there are patterns and regions linked to highlight groups which tell micro how to highlight that filetype. 7 | 8 | Making your own syntax files is very simple. I recommend you check the file after you are finished with the 9 | [`syntax_checker.go`](./syntax_checker.go) program (located in this directory). Just place your yaml syntax 10 | file in the current directory and run `go run syntax_checker.go` and it will check every file. If there are no 11 | errors it will print `No issues!`. 12 | -------------------------------------------------------------------------------- /ftdetect.go: -------------------------------------------------------------------------------- 1 | package highlight 2 | 3 | // DetectFiletype will use the list of syntax definitions provided and the filename and first line of the file 4 | // to determine the filetype of the file 5 | // It will return the corresponding syntax definition for the filetype 6 | func DetectFiletype(defs []*Def, filename string, firstLine []byte) *Def { 7 | for _, d := range defs { 8 | if d.ftdetect[0].MatchString(filename) { 9 | return d 10 | } 11 | if len(d.ftdetect) > 1 { 12 | if d.ftdetect[1].MatchString(string(firstLine)) { 13 | return d 14 | } 15 | } 16 | } 17 | 18 | emptyDef := new(Def) 19 | emptyDef.FileType = "Unknown" 20 | emptyDef.rules = new(rules) 21 | return emptyDef 22 | } 23 | -------------------------------------------------------------------------------- /syntax_files/kickstart.yaml: -------------------------------------------------------------------------------- 1 | filetype: kickstart 2 | 3 | detect: 4 | filename: "\\.ks$|\\.kickstart$" 5 | 6 | rules: 7 | - special: "%[a-z]+" 8 | - statement: "^[[:space:]]*(install|cdrom|text|graphical|volgroup|logvol|reboot|timezone|lang|keyboard|authconfig|firstboot|rootpw|user|firewall|selinux|repo|part|partition|clearpart|bootloader)" 9 | - constant: "--(name|mirrorlist|baseurl|utc)(=|\\>)" 10 | - statement: "\\$(releasever|basearch)\\>" 11 | - brightblack: "^@[A-Za-z][A-Za-z-]*" 12 | - brightred: "^-@[a-zA-Z0-9*-]+" 13 | - red: "^-[a-zA-Z0-9*-]+" 14 | - comment: "(^|[[:space:]])#([^{].*)?$" 15 | - indent-char.whitespace: "[[:space:]]+$" 16 | - indent-char: " + +| + +" 17 | -------------------------------------------------------------------------------- /syntax_files/mail.yaml: -------------------------------------------------------------------------------- 1 | filetype: mail 2 | 3 | detect: 4 | filename: "(.*/mutt-.*|\\.eml)$" 5 | header: "^From .* \\d+:\\d+:\\d+ \\d+" 6 | 7 | rules: 8 | - type: "^From .*" 9 | - identifier: "^[^[:space:]]+:" 10 | - preproc: "^List-(Id|Archive|Subscribe|Unsubscribe|Post|Help):" 11 | - constant: "^(To|From):" 12 | - constant.string: 13 | start: "^Subject:.*" 14 | end: "$" 15 | rules: 16 | - constant.specialChar: "\\\\." 17 | - statement: "?" 18 | - default: 19 | start: "^\\n\\n" 20 | end: ".*" 21 | rules: [] 22 | - comment: 23 | start: "^>.*" 24 | end: "$" 25 | rules: [] 26 | -------------------------------------------------------------------------------- /syntax_files/keymap.yaml: -------------------------------------------------------------------------------- 1 | filetype: keymap 2 | 3 | detect: 4 | filename: "\\.(k|key)?map$|Xmodmap$" 5 | 6 | rules: 7 | - statement: "\\b(add|clear|compose|keycode|keymaps|keysym|remove|string)\\b" 8 | - statement: "\\b(control|alt|shift)\\b" 9 | - constant.number: "\\b[0-9]+\\b" 10 | - special: "=" 11 | - constant.string: 12 | start: "\"" 13 | end: "\"" 14 | skip: "\\\\." 15 | rules: 16 | - constant.specialChar: "\\\\." 17 | - constant.string: 18 | start: "'" 19 | end: "'" 20 | skip: "\\\\." 21 | rules: 22 | - constant.specialChar: "\\\\." 23 | - comment: 24 | start: "^!" 25 | end: "$" 26 | rules: [] 27 | 28 | -------------------------------------------------------------------------------- /syntax_files/gentoo-etc-portage.yaml: -------------------------------------------------------------------------------- 1 | filetype: etc-portage 2 | 3 | detect: 4 | filename: "\\.(keywords|mask|unmask|use)$" 5 | 6 | rules: 7 | # Use flags: 8 | - constant.bool.false: "[[:space:]]+\\+?[a-zA-Z0-9_-]+" 9 | - constant.bool.true: "[[:space:]]+-[a-zA-Z0-9_-]+" 10 | # Likely version numbers: 11 | - special: "-[[:digit:]].*([[:space:]]|$)" 12 | # Accepted arches: 13 | - identifier.class: "[~-]?\\b(alpha|amd64|arm|hppa|ia64|mips|ppc|ppc64|s390|sh|sparc|x86|x86-fbsd)\\b" 14 | - identifier.class: "[[:space:]][~-]?\\*" 15 | # Categories: 16 | - statement: "^[[:space:]]*.*/" 17 | # Masking regulators: 18 | - symbol: "^[[:space:]]*(=|~|<|<=|=<|>|>=|=>)" 19 | # Comments: 20 | - comment: 21 | start: "#" 22 | end: "$" 23 | rules: [] 24 | -------------------------------------------------------------------------------- /syntax_files/pov.yaml: -------------------------------------------------------------------------------- 1 | filetype: pov 2 | 3 | detect: 4 | filename: "\\.(pov|POV|povray|POVRAY)$" 5 | 6 | rules: 7 | - preproc: "^[[:space:]]*#[[:space:]]*(declare)" 8 | - statement: "\\b(sphere|cylinder|translate|matrix|rotate|scale)\\b" 9 | - statement: "\\b(orthographic|location|up|right|direction|clipped_by)\\b" 10 | - statement: "\\b(fog_type|fog_offset|fog_alt|rgb|distance|transform)\\b" 11 | - identifier: "^\\b(texture)\\b" 12 | - identifier: "\\b(light_source|background)\\b" 13 | - identifier: "\\b(fog|object|camera)\\b" 14 | - symbol.operator: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" 15 | - special: "\\b(union|group|subgroup)\\b" 16 | - comment: "//.*" 17 | - comment: 18 | start: "/\\*" 19 | end: "\\*/" 20 | rules: [] 21 | 22 | -------------------------------------------------------------------------------- /syntax_files/ocaml.yaml: -------------------------------------------------------------------------------- 1 | filetype: ocaml 2 | 3 | detect: 4 | filename: "\\.mli?$" 5 | 6 | rules: 7 | # Numbers 8 | ## Integers 9 | ### Binary 10 | - constant.number: "-?0[bB][01][01_]*" 11 | ### Octal 12 | - constant.number: "-?0[oO][0-7][0-7_]*" 13 | ### Decimal 14 | - constant.number: "-?\\d[\\d_]*" 15 | ### Hexadecimal 16 | - constant.number: "-?0[xX][0-9a-fA-F][0-9a-fA-F_]*" 17 | ## Real 18 | ### Decimal 19 | - constant.number: "-?\\d[\\d_]*.\\d[\\d_]*([eE][+-]\\d[\\d_]*.\\d[\\d_]*)?" 20 | ### Hexadecimal 21 | - constant.number: "-?0[xX][0-9a-fA-F][0-9a-fA-F_]*.[0-9a-fA-F][0-9a-fA-F_]*([pP][+-][0-9a-fA-F][0-9a-fA-F_]*.[0-9a-fA-F][0-9a-fA-F_]*)?" 22 | # Comments 23 | - comment: 24 | start: "\\(\\*" 25 | end: "\\*\\)" 26 | rules: [] -------------------------------------------------------------------------------- /syntax_files/micro.yaml: -------------------------------------------------------------------------------- 1 | filetype: micro 2 | 3 | detect: 4 | filename: "\\.(micro)$" 5 | 6 | rules: 7 | - statement: "\\b(syntax|color(-link)?)\\b" 8 | - statement: "\\b(start=|end=)\\b" 9 | - identifier: "\\b(default|comment|symbol|identifier|constant(.string(.char)?|.number)?|statement|preproc|type|special|underlined|error|todo|statusline|indent-char|(current-)?line-number|gutter-error|gutter-warning|cursor-line|color-column)\\b" 10 | - constant.number: "\\b(|h|A|0x)+[0-9]+(|h|A)+\\b" 11 | - constant.number: "\\b0x[0-9 a-f A-F]+\\b" 12 | - comment: 13 | start: "#" 14 | end: "$" 15 | rules: [] 16 | - constant.string: 17 | start: "\"" 18 | end: "\"" 19 | skip: "\\\\." 20 | rules: 21 | - constant.specialChar: "\\\\." 22 | - constant.number: "#[0-9 A-F a-f]+" 23 | 24 | -------------------------------------------------------------------------------- /syntax_files/vi.yaml: -------------------------------------------------------------------------------- 1 | filetype: vi 2 | 3 | detect: 4 | filename: "(^|/|\\.)(ex|vim)rc$|\\.vim" 5 | 6 | rules: 7 | - identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[()]" 8 | - statement: "\\b([nvxsoilc]?(nore|un)?map|[nvlx]n|[ico]?no|[cilovx][um]|s?unm)\\b" 9 | - statement: "\\b(snor|nun|nm|set|if|endif|let|unlet)\\b" 10 | - statement: "[!&=]" 11 | - constant.number: "\\b[0-9]+\\b" 12 | 13 | - constant.string: 14 | start: "\"" 15 | end: "\"" 16 | skip: "\\\\." 17 | rules: 18 | - constant.specialChar: "\\\\." 19 | 20 | - constant.string: 21 | start: "'" 22 | end: "'" 23 | skip: "\\\\." 24 | rules: 25 | - constant.specialChar: "\\\\." 26 | 27 | - constant.comment: 28 | start: "\"" 29 | end: "$" 30 | rules: [] 31 | 32 | 33 | -------------------------------------------------------------------------------- /syntax_files/git-rebase-todo.yaml: -------------------------------------------------------------------------------- 1 | filetype: git-rebase-todo 2 | 3 | detect: 4 | filename: "git-rebase-todo" 5 | 6 | rules: 7 | # Comments 8 | - comment: 9 | start: "#" 10 | end: "$" 11 | rules: [] 12 | # Rebase commands 13 | - statement: "^(e|edit) [0-9a-f]{7,40}" 14 | - statement: "^# (e, edit)" 15 | - statement: "^(f|fixup) [0-9a-f]{7,40}" 16 | - statement: "^# (f, fixup)" 17 | - statement: "^(p|pick) [0-9a-f]{7,40}" 18 | - statement: "^# (p, pick)" 19 | - statement: "^(r|reword) [0-9a-f]{7,40}" 20 | - statement: "^# (r, reword)" 21 | - statement: "^(s|squash) [0-9a-f]{7,40}" 22 | - statement: "^# (s, squash)" 23 | - statement: "^(x|exec) [^ ]+ [0-9a-f]{7,40}" 24 | - statement: "^# (x, exec)" 25 | # Recolor hash symbols 26 | - special: "#" 27 | # Commit IDs 28 | - identifier: "[0-9a-f]{7,40}" 29 | -------------------------------------------------------------------------------- /syntax_files/tex.yaml: -------------------------------------------------------------------------------- 1 | filetype: tex 2 | 3 | detect: 4 | filename: "\\.tex$|bib|\\.bib$|cls|\\.cls$" 5 | 6 | rules: 7 | # colorize the identifiers of {} and [] 8 | - identifier: 9 | start: "\\{" 10 | end: "\\}" 11 | rules: [] 12 | - identifier: 13 | start: "\\[" 14 | end: "\\]" 15 | rules: [] 16 | # numbers 17 | - constant.number: "\\b[0-9]+(\\.[0-9]+)?([[:space:]](pt|mm|cm|in|ex|em|bp|pc|dd|cc|nd|nc|sp))?\\b" 18 | # let brackets have the default color again 19 | - default: "[{}\\[\\]]" 20 | - special: "[&\\\\]" 21 | # macros 22 | - statement: "\\\\@?[a-zA-Z_]+" 23 | # comments 24 | - comment: 25 | start: "%" 26 | end: "$" 27 | rules: [] 28 | - comment: 29 | start: "\\\\begin\\{comment\\}" 30 | end: "\\\\end\\{comment\\}" 31 | rules: [] 32 | -------------------------------------------------------------------------------- /syntax_files/groff.yaml: -------------------------------------------------------------------------------- 1 | filetype: groff 2 | 3 | detect: 4 | filename: "\\.m[ems]$|\\.rof|\\.tmac$|^tmac." 5 | 6 | rules: 7 | - statement: "^\\.(ds|nr) [^[[:space:]]]*" 8 | - constant.specialChar: "\\\\." 9 | - constant.specialChar: "\\\\f.|\\\\f\\(..|\\\\s(\\+|\\-)?[0-9]" 10 | - constant: "(\\\\|\\\\\\\\)n(.|\\(..)" 11 | - constant: 12 | start: "(\\\\|\\\\\\\\)n\\[" 13 | end: "]" 14 | rules: [] 15 | 16 | - type: "^\\.[[:space:]]*[^[[:space:]]]*" 17 | - comment: "^\\.\\\\\".*$" 18 | - constant.string: "(\\\\|\\\\\\\\)\\*(.|\\(..)" 19 | - constant.string: 20 | start: "(\\\\|\\\\\\\\)\\*\\[" 21 | end: "]" 22 | rules: [] 23 | 24 | - constant.specialChar: "\\\\\\(.." 25 | - constant.specialChar: 26 | start: "\\\\\\[" 27 | end: "]" 28 | rules: [] 29 | 30 | - identifier.macro: "\\\\\\\\\\$[1-9]" 31 | -------------------------------------------------------------------------------- /syntax_files/privoxy-config.yaml: -------------------------------------------------------------------------------- 1 | filetype: privoxy-config 2 | 3 | detect: 4 | filename: "privoxy/config$" 5 | 6 | rules: 7 | - statement: "(accept-intercepted-requests|actionsfile|admin-address|allow-cgi-request-crunching|buffer-limit|compression-level|confdir|connection-sharing|debug|default-server-timeout|deny-access|enable-compression|enable-edit-actions|enable-remote-http-toggle|enable-remote-toggle|enforce-blocks|filterfile|forward|forwarded-connect-retries|forward-socks4|forward-socks4a|forward-socks5|handle-as-empty-doc-returns-ok|hostname|keep-alive-timeout|listen-address|logdir|logfile|max-client-connections|permit-access|proxy-info-url|single-threaded|socket-timeout|split-large-forms|templdir|toggle|tolerate-pipelining|trustfile|trust-info-url|user-manual)[[:space:]]" 8 | - comment: "(^|[[:space:]])#([^{].*)?$" 9 | - indent-char.whitespace: "[[:space:]]+$" 10 | - indent-char: " + +| + +" 11 | -------------------------------------------------------------------------------- /syntax_files/git-commit.yaml: -------------------------------------------------------------------------------- 1 | filetype: git-commit 2 | 3 | detect: 4 | filename: "COMMIT_EDITMSG|TAG_EDITMSG" 5 | 6 | rules: 7 | # Commit message 8 | - ignore: ".*" 9 | # Comments 10 | - comment: 11 | start: "#" 12 | end: "$" 13 | rules: [] 14 | # File changes 15 | - keyword: "#[[:space:]](deleted|modified|new file|renamed):[[:space:]].*" 16 | - keyword: "#[[:space:]]deleted:" 17 | - keyword: "#[[:space:]]modified:" 18 | - keyword: "#[[:space:]]new file:" 19 | - keyword: "#[[:space:]]renamed:" 20 | # Untracked filenames 21 | - error: "^# [^/?*:;{}\\\\]+\\.[^/?*:;{}\\\\]+$" 22 | - keyword: "^#[[:space:]]Changes.*[:]" 23 | - keyword: "^#[[:space:]]Your branch and '[^']+" 24 | - keyword: "^#[[:space:]]Your branch and '" 25 | - keyword: "^#[[:space:]]On branch [^ ]+" 26 | - keyword: "^#[[:space:]]On branch" 27 | # Recolor hash symbols 28 | - special: "#" 29 | -------------------------------------------------------------------------------- /syntax_files/json.yaml: -------------------------------------------------------------------------------- 1 | filetype: json 2 | 3 | detect: 4 | filename: "\\.json$" 5 | header: "^\\{$" 6 | 7 | rules: 8 | - constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b" 9 | - constant.number: "\\b[-+]?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?" 10 | - constant.number: "\\b[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?" 11 | - constant: "\\b(null)\\b" 12 | - constant: "\\b(true|false)\\b" 13 | - constant.string: 14 | start: "\"" 15 | end: "\"" 16 | skip: "\\\\." 17 | rules: 18 | - constant.specialChar: "\\\\." 19 | - constant.string: 20 | start: "'" 21 | end: "'" 22 | skip: "\\\\." 23 | rules: 24 | - constant.specialChar: "\\\\." 25 | 26 | - statement: "\\\"(\\\\\"|[^\"])*\\\"[[:space:]]*:\" \"'(\\'|[^'])*'[[:space:]]*:" 27 | - constant: "\\\\u[0-9a-fA-F]{4}|\\\\[bfnrt'\"/\\\\]" 28 | -------------------------------------------------------------------------------- /syntax_files/dockerfile.yaml: -------------------------------------------------------------------------------- 1 | filetype: dockerfile 2 | 3 | detect: 4 | filename: "(Dockerfile[^/]*$|\\.dockerfile$)" 5 | 6 | rules: 7 | ## Keywords 8 | - keyword: "(?i)^(FROM|MAINTAINER|RUN|CMD|LABEL|EXPOSE|ENV|ADD|COPY|ENTRYPOINT|VOLUME|USER|WORKDIR|ONBUILD|ARG|HEALTHCHECK|STOPSIGNAL|SHELL)[[:space:]]" 9 | 10 | ## Brackets & parenthesis 11 | - statement: "(\\(|\\)|\\[|\\])" 12 | 13 | ## Double ampersand 14 | - special: "&&" 15 | 16 | ## Comments 17 | - comment: 18 | start: "#" 19 | end: "$" 20 | rules: 21 | - todo: "(TODO|XXX|FIXME):?" 22 | 23 | - constant.string: 24 | start: "\"" 25 | end: "\"" 26 | skip: "\\\\." 27 | rules: 28 | - constant.specialChar: "\\\\." 29 | 30 | - constant.string: 31 | start: "'" 32 | end: "'" 33 | skip: "\\\\." 34 | rules: 35 | - constant.specialChar: "\\\\." 36 | 37 | -------------------------------------------------------------------------------- /syntax_files/yaml.yaml: -------------------------------------------------------------------------------- 1 | filetype: yaml 2 | 3 | detect: 4 | filename: "\\.ya?ml$" 5 | header: "%YAML" 6 | 7 | rules: 8 | - type: "(^| )!!(binary|bool|float|int|map|null|omap|seq|set|str) " 9 | - constant: "\\b(YES|yes|Y|y|ON|on|NO|no|N|n|OFF|off)\\b" 10 | - constant: "\\b(true|false)\\b" 11 | - statement: "(:[[:space:]]|\\[|\\]|:[[:space:]]+[|>]|^[[:space:]]*- )" 12 | - identifier: "[[:space:]][\\*&][A-Za-z0-9]+" 13 | - type: "[-.\\w]+:" 14 | - statement: ":" 15 | - special: "(^---|^\\.\\.\\.|^%YAML|^%TAG)" 16 | 17 | - constant.string: 18 | start: "\"" 19 | end: "\"" 20 | skip: "\\\\." 21 | rules: 22 | - constant.specialChar: "\\\\." 23 | 24 | - constant.string: 25 | start: "'" 26 | end: "'" 27 | skip: "\\\\." 28 | rules: 29 | - constant.specialChar: "\\\\." 30 | 31 | - comment: 32 | start: "#" 33 | end: "$" 34 | rules: [] 35 | 36 | 37 | -------------------------------------------------------------------------------- /syntax_files/coffeescript.yaml: -------------------------------------------------------------------------------- 1 | filetype: coffeescript 2 | 3 | detect: 4 | filename: "\\.coffee$" 5 | 6 | rules: 7 | - symbol.operator: "[!&|=/*+-<>]|\\b(and|or|is|isnt|not)\\b" 8 | - identifier.class: "([A-Za-z_][A-Za-z0-9_]*:[[:space:]]*(->|\\()|->)" 9 | - symbol.brackets: "[()]" 10 | - statement: "\\b(for|of|continue|break|isnt|null|unless|this|else|if|return)\\b" 11 | - statement: "\\b(try|catch|finally|throw|new|delete|typeof|in|instanceof)\\b" 12 | - statement: "\\b(debugger|switch|while|do|class|extends|super)\\b" 13 | - statement: "\\b(undefined|then|unless|until|loop|of|by|when)\\b" 14 | - constant.bool: "\\b(true|false|yes|no|on|off)\\b" 15 | - identifier: "@[A-Za-z0-9_]*" 16 | 17 | - constant.string: 18 | start: "\"" 19 | end: "\"" 20 | skip: "\\\\." 21 | rules: 22 | - constant.specialChar: "\\\\." 23 | 24 | - comment: 25 | start: "#" 26 | end: "$" 27 | rules: 28 | - todo: "(TODO|XXX|FIXME):?" 29 | 30 | -------------------------------------------------------------------------------- /syntax_files/scala.yaml: -------------------------------------------------------------------------------- 1 | filetype: scala 2 | 3 | detect: 4 | filename: "\\.scala$" 5 | 6 | rules: 7 | - type: "\\b(boolean|byte|char|double|float|int|long|new|short|this|transient|void)\\b" 8 | - statement: "\\b(match|val|var|break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\\b" 9 | - statement: "\\b(def|object|case|trait|lazy|implicit|abstract|class|extends|final|implements|import|instanceof|interface|native|package|private|protected|public|static|strictfp|super|synchronized|throws|volatile|sealed)\\b" 10 | - constant.string: 11 | start: "\"" 12 | end: "\"" 13 | skip: "\\\\." 14 | rules: 15 | - constant.specialChar: "\\\\." 16 | - constant: "\\b(true|false|null)\\b" 17 | - comment: 18 | start: "//" 19 | end: "$" 20 | rules: [] 21 | - comment: 22 | start: "/\\*" 23 | end: "\\*/" 24 | rules: [] 25 | - comment: 26 | start: "/\\*\\*" 27 | end: "\\*/" 28 | rules: [] 29 | 30 | -------------------------------------------------------------------------------- /syntax_files/toml.yaml: -------------------------------------------------------------------------------- 1 | filetype: toml 2 | 3 | detect: 4 | filename: "\\.toml" 5 | 6 | rules: 7 | - statement: "(.*)[[:space:]]=" 8 | - special: "=" 9 | 10 | # Bracket thingies 11 | - special: "(\\[|\\])" 12 | 13 | # Numbers and strings 14 | - constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b|'.'" 15 | - constant.number: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" 16 | 17 | - constant.string: 18 | start: "\"" 19 | end: "\"" 20 | skip: "\\\\." 21 | rules: 22 | - constant.specialChar: "\\\\." 23 | 24 | - constant.string: 25 | start: "'" 26 | end: "'" 27 | skip: "\\\\." 28 | rules: 29 | - constant.specialChar: "\\\\." 30 | 31 | - constant.string: 32 | start: "`" 33 | end: "`" 34 | rules: 35 | - constant.specialChar: "\\\\." 36 | 37 | - comment: 38 | start: "#" 39 | end: "$" 40 | rules: 41 | - todo: "(TODO|XXX|FIXME):?" 42 | 43 | -------------------------------------------------------------------------------- /syntax_files/vala.yaml: -------------------------------------------------------------------------------- 1 | filetype: vala 2 | 3 | detect: 4 | filename: "\\.vala$" 5 | 6 | rules: 7 | - type: "\\b(float|double|bool|char|int|uint|short|long|void|(un)?signed)\\b" 8 | - identifier.class: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[()]" 9 | - statement: "\\b(for|if|while|do|else|case|default|switch|try|throw|catch)\\b" 10 | - statement: "\\b(inline|typedef|struct|enum|union|extern|static|const)\\b" 11 | - statement: "\\b(operator|new|delete|return|null)\\b" 12 | - statement: "\\b(class|override|private|public|signal|this|weak)\\b" 13 | - special: "\\b(goto|break|continue)\\b" 14 | - constant.bool: "\\b(true|false)\\b" 15 | - constant.number: "\\b([0-9]+)\\b" 16 | - symbol.operator: "[\\-+/*=<>?:!~%&|]|->" 17 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 18 | - comment: "(^|[[:space:]])//.*" 19 | - comment: 20 | start: "/\\*" 21 | end: "\\*/" 22 | rules: [] 23 | 24 | - todo: "TODO:?" 25 | - indent-char.whitespace: "[[:space:]]+$" 26 | - indent-char: " + +| + +" 27 | -------------------------------------------------------------------------------- /syntax_files/dot.yaml: -------------------------------------------------------------------------------- 1 | filetype: dot 2 | 3 | detect: 4 | filename: "\\.(dot|gv)$" 5 | 6 | rules: 7 | - type: "\\b(digraph|edge|graph|node|subgraph)\\b" 8 | - statement: "\\b(arrow(head|size|tail)|(bg|fill|font)?color|center|constraint|decorateP|dir|distortion|font(name|size)|head(clip|label)|height|label(angle|distance|font(color|name|size))?|layer(s)?|margin|mclimit|minlen|name|nodesep|nslimit|ordering|orientation|page(dir)?|peripheries|port_label_distance|rank(dir|sep)?|ratio|regular|rotate|same(head|tail)|shape(file)?|sides|size|skew|style|tail(clip|label)|URL|weight|width)\\b" 9 | - symbol: "=|->|--" 10 | 11 | - constant.string: 12 | start: "\"" 13 | end: "\"" 14 | skip: "\\\\." 15 | rules: 16 | - constant.specialChar: "\\\\." 17 | 18 | - comment: 19 | start: "//" 20 | end: "$" 21 | rules: 22 | - todo: "(TODO|XXX|FIXME):?" 23 | 24 | - comment: 25 | start: "/\\*" 26 | end: "\\*/" 27 | rules: 28 | - todo: "(TODO|XXX|FIXME):?" 29 | 30 | -------------------------------------------------------------------------------- /syntax_files/glsl.yaml: -------------------------------------------------------------------------------- 1 | filetype: glsl 2 | 3 | detect: 4 | filename: "\\.(frag|vert|fp|vp|glsl)$" 5 | 6 | rules: 7 | - identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[()]" 8 | - type: "\\b(void|bool|bvec2|bvec3|bvec4|int|ivec2|ivec3|ivec4|float|vec2|vec3|vec4|mat2|mat3|mat4|struct|sampler1D|sampler2D|sampler3D|samplerCUBE|sampler1DShadow|sampler2DShadow)\\b" 9 | - identifier: "\\bgl_(DepthRangeParameters|PointParameters|MaterialParameters|LightSourceParameters|LightModelParameters|LightModelProducts|LightProducts|FogParameters)\\b" 10 | - statement: "\\b(const|attribute|varying|uniform|in|out|inout|if|else|return|discard|while|for|do)\\b" 11 | - statement: "\\b(break|continue)\\b" 12 | - constant.bool: "\\b(true|false)\\b" 13 | - symbol.operator: "[-+/*=<>?:!~%&|^]" 14 | - constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b" 15 | 16 | - comment: 17 | start: "//" 18 | end: "$" 19 | rules: 20 | - todo: "TODO:?" 21 | 22 | - comment: 23 | start: "/\\*" 24 | end: "\\*/" 25 | rules: 26 | - todo: "TODO:?" 27 | -------------------------------------------------------------------------------- /syntax_files/clojure.yaml: -------------------------------------------------------------------------------- 1 | filetype: clojure 2 | 3 | detect: 4 | filename: "\\.(clj)$" 5 | 6 | rules: 7 | 8 | # Constants 9 | - constant.bool: "\\b(true|false)\\b" 10 | - constant.macro: "\\b(nil)\\b" 11 | # Valid numbers 12 | - constant.number: "[\\-]?[0-9]+?\\b" 13 | - constant.number: "0x[0-9][A-Fa-f]+?\\b" 14 | - constant.number: "[\\-]?(3[0-6]|2[0-9]|1[0-9]|[2-9])r[0-9A-Z]+?\\b" 15 | # Invalid numbers 16 | - error: "[\\-]?([4-9][0-9]|3[7-9]|1|0)r[0-9A-Z]+?\\b" 17 | 18 | # Symbols 19 | - symbol.operator: "[=>+\\-*/'?]" 20 | 21 | # Types/casting 22 | - type: "\\b(byte|short|(big)?int(eger)?|long|float|num|bigdec|rationalize)\\b" 23 | 24 | # String highlighting 25 | - constant.string: 26 | start: "\"" 27 | end: "\"" 28 | skip: "\\\\." 29 | rules: 30 | - constant.specialChar: "(\\\\u[0-9A-fa-f]{4,4}|\\\\newline|\\\\space|\\\\tab|\\\\formfeed|\\\\backspace|\\\\return|\\\\.)" 31 | 32 | # Comments 33 | - comment: 34 | start: ";" 35 | end: "$" 36 | rules: 37 | - todo: "(TODO|XXX|FIXME):?" 38 | 39 | -------------------------------------------------------------------------------- /syntax_files/java.yaml: -------------------------------------------------------------------------------- 1 | filetype: java 2 | 3 | detect: 4 | filename: "\\.java$" 5 | 6 | rules: 7 | - type: "\\b(boolean|byte|char|double|float|int|long|new|short|this|transient|void)\\b" 8 | - statement: "\\b(break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\\b" 9 | - type: "\\b(abstract|class|extends|final|implements|import|instanceof|interface|native|package|private|protected|public|static|strictfp|super|synchronized|throws|volatile)\\b" 10 | - constant: "\\b(true|false|null)\\b" 11 | - constant.number: "\\b[0-9]+\\b" 12 | 13 | - constant.string: 14 | start: "\"" 15 | end: "\"" 16 | skip: "\\\\." 17 | rules: 18 | - constant.specialChar: "\\\\." 19 | 20 | - constant.string: 21 | start: "'" 22 | end: "'" 23 | skip: "\\\\." 24 | rules: 25 | - preproc: "..+" 26 | - constant.specialChar: "\\\\." 27 | 28 | - comment: 29 | start: "//" 30 | end: "$" 31 | rules: [] 32 | 33 | - comment: 34 | start: "/\\*" 35 | end: "\\*/" 36 | rules: [] 37 | 38 | -------------------------------------------------------------------------------- /syntax_files/nanorc.yaml: -------------------------------------------------------------------------------- 1 | filetype: nanorc 2 | 3 | detect: 4 | filename: "\\.?nanorc$" 5 | 6 | rules: 7 | - default: "(?i)^[[:space:]]*((un)?set|include|syntax|i?color).*$" 8 | - type: "(?i)^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|boldtext|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct)\\>|^[[:space:]]*(set|unset)[[:space:]]+(quickblank|quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|undo|view|whitespace|wordbounds)\\b" 9 | - preproc: "(?i)^[[:space:]]*(set|unset|include|syntax|header)\\b" 10 | - constant.bool.true: "(?i)(set)\\b" 11 | - constant.bool.false: "(?i)(unset)\\b" 12 | - identifier: "(?i)^[[:space:]]*(i)?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\\b" 13 | - special: "(?i)^[[:space:]]*(i)?color\\b|\\b(start|end)=" 14 | - constant.string: "\"(\\\\.|[^\"])*\"" 15 | - comment: "^[[:space:]]*#.*$" 16 | - comment.bright: "^[[:space:]]*##.*$" 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Highlight is licensed under the MIT "Expat" License: 2 | 3 | Copyright (c) 2016: Zachary Yedidia. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------------- /syntax_files/markdown.yaml: -------------------------------------------------------------------------------- 1 | filetype: markdown 2 | 3 | detect: 4 | filename: "\\.(md|mkd|mkdn|markdown)$" 5 | 6 | rules: 7 | # Tables (Github extension) 8 | - type: ".*[ :]\\|[ :].*" 9 | 10 | # quotes 11 | - statement: "^>.*" 12 | 13 | # Emphasis 14 | - type: "(^|[[:space:]])(_[^ ][^_]*_|\\*[^ ][^*]*\\*)" 15 | 16 | # Strong emphasis 17 | - type: "(^|[[:space:]])(__[^ ][^_]*__|\\*\\*[^ ][^*]*\\*\\*)" 18 | 19 | # strike-through 20 | - type: "(^|[[:space:]])~~[^ ][^~]*~~" 21 | 22 | # horizontal rules 23 | - special: "^(---+|===+|___+|\\*\\*\\*+)\\s*$" 24 | 25 | # headlines 26 | - special: "^#{1,6}.*" 27 | 28 | # lists 29 | - identifier: "^[[:space:]]*[\\*+-] |^[[:space:]]*[0-9]+\\. " 30 | 31 | # misc 32 | - preproc: "(\\(([CcRr]|[Tt][Mm])\\)|\\.{3}|(^|[[:space:]])\\-\\-($|[[:space:]]))" 33 | 34 | # links 35 | - constant: "\\[[^]]+\\]" 36 | - constant: "\\[([^][]|\\[[^]]*\\])*\\]\\([^)]+\\)" 37 | 38 | # images 39 | - underlined: "!\\[[^][]*\\](\\([^)]+\\)|\\[[^]]+\\])" 40 | 41 | # urls 42 | - underlined: "https?://[^ )>]+" 43 | 44 | - special: "^```$" 45 | 46 | - special: 47 | start: "`" 48 | end: "`" 49 | rules: [] 50 | -------------------------------------------------------------------------------- /syntax_files/cmake.yaml: -------------------------------------------------------------------------------- 1 | filetype: cmake 2 | 3 | detect: 4 | filename: "(CMakeLists\\.txt|\\.cmake)$" 5 | 6 | rules: 7 | - identifier.var: "^[[:space:]]*[A-Z0-9_]+" 8 | - preproc: "^[[:space:]]*(include|include_directories|include_external_msproject)\\b" 9 | 10 | - statement: "^[[:space:]]*\\b((else|end)?if|else|(end)?while|(end)?foreach|break)\\b" 11 | - statement: "\\b(COPY|NOT|COMMAND|PROPERTY|POLICY|TARGET|EXISTS|IS_(DIRECTORY|ABSOLUTE)|DEFINED)\\b[[:space:]]" 12 | - statement: "[[:space:]]\\b(OR|AND|IS_NEWER_THAN|MATCHES|(STR|VERSION_)?(LESS|GREATER|EQUAL))\\b[[:space:]]" 13 | 14 | - special: "^[[:space:]]*\\b((end)?(function|macro)|return)" 15 | 16 | - constant.string: 17 | start: "\"" 18 | end: "\"" 19 | skip: "\\\\." 20 | rules: 21 | - constant.specialChar: "\\\\." 22 | 23 | - constant.string: 24 | start: "'" 25 | end: "'" 26 | skip: "\\\\." 27 | rules: 28 | - constant.specialChar: "\\\\." 29 | 30 | - preproc: 31 | start: "\\$(\\{|ENV\\{)" 32 | end: "\\}" 33 | rules: [] 34 | 35 | - identifier.macro: "\\b(APPLE|UNIX|WIN32|CYGWIN|BORLAND|MINGW|MSVC(_IDE|60|71|80|90)?)\\b" 36 | 37 | - comment: 38 | start: "#" 39 | end: "$" 40 | rules: 41 | - todo: "(TODO|XXX|FIXME):?" 42 | 43 | -------------------------------------------------------------------------------- /syntax_files/rust.yaml: -------------------------------------------------------------------------------- 1 | filetype: rust 2 | 3 | detect: 4 | filename: "\\.rs$" 5 | 6 | rules: 7 | # function definition 8 | - identifier: "fn [a-z0-9_]+" 9 | # Reserved words 10 | - statement: "\\b(abstract|alignof|as|become|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\\b" 11 | # macros 12 | - special: "[a-z_]+!" 13 | # Constants 14 | - constant: "[A-Z][A-Z_]+" 15 | # Numbers 16 | - constant.number: "\\b[0-9]+\\b" 17 | # Traits/Enums/Structs/Types/etc. 18 | - type: "[A-Z][a-z]+" 19 | 20 | - constant.string: 21 | start: "\"" 22 | end: "\"" 23 | skip: "\\\\." 24 | rules: 25 | - constant.specialChar: "\\\\." 26 | 27 | - constant.string: 28 | start: "r#+\"" 29 | end: "\"#+" 30 | rules: [] 31 | 32 | - comment: 33 | start: "//" 34 | end: "$" 35 | rules: 36 | - todo: "(TODO|XXX|FIXME):?" 37 | 38 | - comment: 39 | start: "/\\*" 40 | end: "\\*/" 41 | rules: 42 | - todo: "(TODO|XXX|FIXME):?" 43 | 44 | - special: 45 | start: "#!\\[" 46 | end: "\\]" 47 | rules: [] 48 | 49 | -------------------------------------------------------------------------------- /syntax_files/html5.yaml: -------------------------------------------------------------------------------- 1 | filetype: html5 2 | 3 | detect: 4 | filename: "\\.htm[l]?5$" 5 | header: "" 6 | 7 | rules: 8 | - error: "<[^!].*?>" 9 | - symbol.tag: "(?i)<[/]?(a|a(bbr|ddress|rea|rticle|side|udio)|b|b(ase|d(i|o)|lockquote|r|utton)|ca(nvas|ption)|center|cite|co(de|l|lgroup)|d(ata|atalist|d|el|etails|fn|ialog|l|t)|em|embed|fieldset|fig(caption|ure)|form|iframe|h[1-6]|hr|i|img|in(put|s)|kbd|keygen|label|legend|li|link|ma(in|p|rk)|menu|menuitem|met(a|er)|nav|noscript|o(bject|l|pt(group|ion)|utput)|p|param|picture|pre|progress|q|r(p|t|uby)|s|samp|se(ction|lect)|small|source|span|strong|su(b|p|mmary)|textarea|time|track|u|ul|var|video|wbr)( .*)*?>" 10 | - symbol.tag.extended: "(?i)<[/]?(body|div|html|head(er)?|footer|title|table|t(body|d|h(ead)?|r|foot))( .*)*?>" 11 | - preproc: "(?i)<[/]?(script|style)( .*)*?>" 12 | - special: "&[^;[[:space:]]]*;" 13 | - symbol: "[:=]" 14 | - identifier: "(alt|bgcolor|height|href|id|label|longdesc|name|on(click|focus|load|mouseover)|size|span|src|style|target|type|value|width)=" 15 | - constant.string: "\"[^\"]*\"" 16 | - constant.number: "(?i)#[0-9A-F]{6,6}" 17 | - default: 18 | start: ">" 19 | end: "<" 20 | rules: [] 21 | 22 | - symbol.tag: "<|>" 23 | - constant.string.url: "(ftp(s)?|http(s)?|git|chrome)://[^ ]+" 24 | - comment: "" 25 | - preproc: "" 26 | -------------------------------------------------------------------------------- /syntax_files/makefile.yaml: -------------------------------------------------------------------------------- 1 | filetype: makefile 2 | 3 | detect: 4 | filename: "([Mm]akefile|\\.ma?k)$" 5 | header: "^#!.*/(env +)?[bg]?make( |$)" 6 | 7 | rules: 8 | - preproc: "\\<(ifeq|ifdef|ifneq|ifndef|else|endif)\\>" 9 | - statement: "^(export|include|override)\\>" 10 | - operator: "^[^:= ]+:" 11 | - operator: "([=,%]|\\+=|\\?=|:=|&&|\\|\\|)" 12 | - statement: "\\$\\((abspath|addprefix|addsuffix|and|basename|call|dir)[[:space:]]" 13 | - statement: "\\$\\((error|eval|filter|filter-out|findstring|firstword)[[:space:]]" 14 | - statement: "\\$\\((flavor|foreach|if|info|join|lastword|notdir|or)[[:space:]]" 15 | - statement: "\\$\\((origin|patsubst|realpath|shell|sort|strip|suffix)[[:space:]]" 16 | - statement: "\\$\\((value|warning|wildcard|word|wordlist|words)[[:space:]]" 17 | - identifier: "^.+:" 18 | - identifier: "[()$]" 19 | - constant.string: 20 | start: "\"" 21 | end: "\"" 22 | skip: "\\\\." 23 | rules: 24 | - constant.specialChar: "\\\\." 25 | - constant.string: 26 | start: "'" 27 | end: "'" 28 | skip: "\\\\." 29 | rules: 30 | - constant.specialChar: "\\\\." 31 | - identifier: "\\$+(\\{[^} ]+\\}|\\([^) ]+\\))" 32 | - identifier: "\\$[@^<*?%|+]|\\$\\([@^<*?%+-][DF]\\)" 33 | - identifier: "\\$\\$|\\\\.?" 34 | - comment: 35 | start: "#" 36 | end: "$" 37 | rules: [] 38 | 39 | -------------------------------------------------------------------------------- /syntax_files/pony.yaml: -------------------------------------------------------------------------------- 1 | filetype: pony 2 | 3 | detect: 4 | filename: "\\.pony$" 5 | 6 | rules: 7 | - statement: "\\b(type|interface|trait|primitive|class|struct|actor)\\b" 8 | - statement: "\\b(compiler_intrinsic)\\b" 9 | - statement: "\\b(use)\\b" 10 | - statement: "\\b(var|let|embed)\\b" 11 | - statement: "\\b(new|be|fun)\\b" 12 | - statement: "\\b(iso|trn|ref|val|box|tag|consume)\\b" 13 | - statement: "\\b(break|continue|return|error)\\b" 14 | - statement: "\\b(if|then|elseif|else|end|match|where|try|with|as|recover|object|lambda|as|digestof|ifdef)\\b" 15 | - statement: "\\b(while|do|repeat|until|for|in)\\b" 16 | - statement: "(\\?|=>)" 17 | - statement: "(\\||\\&|\\,|\\^)" 18 | - symbol.operator: "(\\-|\\+|\\*|/|\\!|%|<<|>>)" 19 | - symbol.operator: "(==|!=|<=|>=|<|>)" 20 | - statement: "\\b(is|isnt|not|and|or|xor)\\b" 21 | - type: "\\b(_*[A-Z][_a-zA-Z0-9\\']*)\\b" 22 | - constant: "\\b(this)\\b" 23 | - constant.bool: "\\b(true|false)\\b" 24 | - constant.number: "\\b((0b[0-1_]*)|(0o[0-7_]*)|(0x[0-9a-fA-F_]*)|([0-9_]+(\\.[0-9_]+)?((e|E)(\\\\+|-)?[0-9_]+)?))\\b" 25 | - constant.string: "\"(\\\\.|[^\"])*\"" 26 | - comment: 27 | start: "\"\"\"[^\"]*" 28 | end: "\"\"\"" 29 | rules: [] 30 | 31 | - comment: "(^|[[:space:]])//.*" 32 | - comment: 33 | start: "/\\*" 34 | end: "\\*/" 35 | rules: [] 36 | 37 | - todo: "TODO:?" 38 | -------------------------------------------------------------------------------- /syntax_files/swift.yaml: -------------------------------------------------------------------------------- 1 | filetype: swift 2 | 3 | detect: 4 | filename: "\\.swift$" 5 | 6 | rules: 7 | # Operators 8 | - statement: "([.:;,+*|=!?\\%]|<|>|/|-|&)" 9 | 10 | # Statements 11 | - statement: "(class|import|let|var|struct|enum|func|if|else|switch|case|default|for|in|internal|external|unowned|private|public|throws)\\ " 12 | - statement: "(prefix|postfix|operator|extension|lazy|get|set|self|willSet|didSet|override|super|convenience|weak|strong|mutating|return|guard)\\ " 13 | 14 | # Keywords 15 | - statement: "(print)" 16 | - statement: "(init)" 17 | 18 | # Numbers 19 | - constant.number: "([0-9]+)" 20 | 21 | # Standard Types 22 | - type: "\\ ((U)?Int(8|16|32|64))" 23 | - constant: "(true|false|nil)" 24 | - type: "\\ (Double|String|Float|Boolean|Dictionary|Array|Int)" 25 | - type: "\\ (AnyObject)" 26 | 27 | - constant.string: 28 | start: "\"" 29 | end: "\"" 30 | skip: "\\\\." 31 | rules: 32 | - constant.specialChar: "\\\\." 33 | 34 | - comment: 35 | start: "//" 36 | end: "$" 37 | rules: 38 | - todo: "(TODO|XXX|FIXME):?" 39 | 40 | - comment: 41 | start: "///" 42 | end: "$" 43 | rules: 44 | - todo: "(TODO|XXX|FIXME):?" 45 | 46 | - comment: 47 | start: "/\\*\\*" 48 | end: "\\*/" 49 | rules: 50 | - todo: "(TODO|XXX|FIXME):?" 51 | 52 | -------------------------------------------------------------------------------- /syntax_files/ruby.yaml: -------------------------------------------------------------------------------- 1 | filetype: ruby 2 | 3 | detect: 4 | filename: "\\.rb$|\\.ru|\\.rbx|\\.rake|\\.gemspec$|Gemfile|Rakefile|Capfile|Vagrantfile" 5 | header: "^#!.*/(env +)?ruby( |$)" 6 | 7 | rules: 8 | - statement: "\\b(BEGIN|END|alias|and|begin|break|case|class|def|defined\\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\\b" 9 | - constant: "(\\$|@|@@)?\\b[A-Z]+[0-9A-Z_a-z]*" 10 | - constant.number: "\\b[0-9]+\\b" 11 | - constant: "(i?)([ ]|^):[0-9A-Z_]+\\b" 12 | - constant: "\\b(__FILE__|__LINE__)\\b" 13 | - constant: "/([^/]|(\\\\/))*/[iomx]*|%r\\{([^}]|(\\\\}))*\\}[iomx]*" 14 | - constant.string: "`[^`]*`|%x\\{[^}]*\\}" 15 | - constant.string: "\"([^\"]|(\\\\\"))*\"|%[QW]?\\{[^}]*\\}|%[QW]?\\([^)]*\\)|%[QW]?<[^>]*>|%[QW]?\\[[^]]*\\]|%[QW]?\\$[^$]*\\$|%[QW]?\\^[^^]*\\^|%[QW]?![^!]*!" 16 | - special: "#\\{[^}]*\\}" 17 | - constant.string: "'([^']|(\\\\'))*'|%[qw]\\{[^}]*\\}|%[qw]\\([^)]*\\)|%[qw]<[^>]*>|%[qw]\\[[^]]*\\]|%[qw]\\$[^$]*\\$|%[qw]\\^[^^]*\\^|%[qw]![^!]*!" 18 | - comment: "#[^{].*$|#$" 19 | - comment: 20 | start: "=begin" 21 | end: "=end" 22 | rules: [] 23 | - comment.bright: "##[^{].*$|##$" 24 | - constant.macro: 25 | start: "<<-?'?EOT'?" 26 | end: "^EOT" 27 | rules: [] 28 | 29 | - todo: "(XXX|TODO|FIXME|\\?\\?\\?)" 30 | - preproc.shebang: "^#!.+?( |$)" 31 | -------------------------------------------------------------------------------- /syntax_files/asciidoc.yaml: -------------------------------------------------------------------------------- 1 | filetype: asciidoc 2 | 3 | detect: 4 | filename: "\\.(asc|asciidoc|adoc)$" 5 | 6 | rules: 7 | # main header 8 | - preproc: "^====+$" 9 | # h1 10 | - statement: "^==[[:space:]].*$" 11 | - statement: "^----+$" 12 | # h2 13 | - symbol: "^===[[:space:]].*$" 14 | - symbol: "^~~~~+$" 15 | # h4 16 | - type: "^====[[:space:]].*$" 17 | - type: "^\\^\\^\\^\\^+$" 18 | # h5 19 | - constant: "^=====[[:space:]].*$" 20 | - constant: "^\\+\\+\\+\\++$" 21 | 22 | # attributes 23 | - type.keyword: ":.*:" 24 | - identifier.macro: "\\{[a-z0-9]*\\}" 25 | - identifier: "\\\\\\{[a-z0-9]*\\}" 26 | - identifier: "\\+\\+\\+\\{[a-z0-9]*\\}\\+\\+\\+" 27 | 28 | # Paragraph Title 29 | - statement: "^\\..*$" 30 | 31 | # source 32 | - identifier: "^\\[(source,.+|NOTE|TIP|IMPORTANT|WARNING|CAUTION)\\]" 33 | 34 | # Other markup 35 | - constant.string: ".*[[:space:]]\\+$" 36 | - constant.string: "_[^_]+_" 37 | - constant.string: "\\*[^\\*]+\\*" 38 | - constant.string: "\\+[^\\+]+\\+" 39 | - constant.string: "`[^`]+`" 40 | - constant.string: "\\^[^\\^]+\\^" 41 | - constant.string: "~[^~]+~" 42 | - constant.string: "'[^']+'" 43 | 44 | - constant: "`{1,2}[^']+'{1,2}" 45 | 46 | # bullets 47 | - symbol: "^[[:space:]]*[\\*\\.-]{1,5}[[:space:]]" 48 | 49 | # anchors 50 | - "bold default": "\\[\\[.*\\]\\]" 51 | - "bold default": "<<.*>>" 52 | -------------------------------------------------------------------------------- /syntax_files/html4.yaml: -------------------------------------------------------------------------------- 1 | filetype: html4 2 | 3 | detect: 4 | filename: "\\.htm[l]?4$" 5 | header: "" 6 | 7 | rules: 8 | - error: "<[^!].*?>" 9 | - symbol.tag: "(?i)<[/]?(a(bbr|cronym|ddress|pplet|rea|rticle|side|udio)?|b(ase(font)?|d(i|o)|ig|lockquote|r)?|ca(nvas|ption)|center|cite|co(de|l|lgroup)|d(ata(list)?|d|el|etails|fn|ialog|ir|l|t)|em(bed)?|fieldset|fig(caption|ure)|font|form|(i)?frame|frameset|h[1-6]|hr|i|img|in(put|s)|kbd|keygen|label|legend|li(nk)?|ma(in|p|rk)|menu(item)?|met(a|er)|nav|no(frames|script)|o(l|pt(group|ion)|utput)|p(aram|icture|re|rogress)?|q|r(p|t|uby)|s(trike)?|samp|se(ction|lect)|small|source|span|strong|su(b|p|mmary)|textarea|time|track|u(l)?|var|video|wbr)( .*|>)*?>" 10 | - symbol.tag.extended: "(?i)<[/]?(body|div|html|head(er)?|footer|title|table|t(body|d|h(ead)?|r|foot))( .*)*?>" 11 | - preproc: "(?i)<[/]?(script|style)( .*)*?>" 12 | - special: "&[^;[[:space:]]]*;" 13 | - symbol: "[:=]" 14 | - identifier: "(alt|bgcolor|height|href|id|label|longdesc|name|on(click|focus|load|mouseover)|size|span|src|style|target|type|value|width)=" 15 | - constant.string: "\"[^\"]*\"" 16 | - constant.number: "(?i)#[0-9A-F]{6,6}" 17 | - default: 18 | start: ">" 19 | end: "<" 20 | rules: [] 21 | 22 | - symbol.tag: "<|>" 23 | - constant.string.url: "(ftp(s)?|http(s)?|git|chrome)://[^ ]+" 24 | - comment: "" 25 | - preproc: "" 26 | -------------------------------------------------------------------------------- /syntax_files/c++.yaml: -------------------------------------------------------------------------------- 1 | filetype: c++ 2 | 3 | detect: 4 | filename: "\\.c(c|pp|xx)$|\\.h(h|pp|xx)$|\\.ii?$|\\.(def)$" 5 | 6 | rules: 7 | - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" 8 | - type: "\\b(auto|float|double|bool|char|int|short|long|sizeof|enum|void|static|const|constexpr|struct|union|typedef|extern|(un)?signed|inline)\\b" 9 | - type: "\\b((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\\b" 10 | - statement: "\\b(class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)\\b" 11 | - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" 12 | - statement: "\\b(try|throw|catch|operator|new|delete)\\b" 13 | - special: "\\b(goto|continue|break|return)\\b" 14 | - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)" 15 | - constant: "'([^'\\\\]|(\\\\[\"'abfnrtv\\\\]))'|'\\\\(([0-3]?[0-7]{1,2}))'|'\\\\x[0-9A-Fa-f]{1,2}'" 16 | - statement: "__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__" 17 | - symbol.operator: "[.:;,+*|=!\\%]|<|>|/|-|&" 18 | - symbol.brackets: "[(){}]|\\[|\\]" 19 | - constant.number: "\\b[0-9]+\\b|\\b0x[0-9A-Fa-f]+\\b" 20 | - constant.bool: "\\b(true|false)\\b|NULL" 21 | - constant.string: "\"(\\\\.|[^\"])*\"" 22 | - comment: "//.*" 23 | - comment: 24 | start: "/\\*" 25 | end: "\\*/" 26 | rules: [] 27 | 28 | - indent-char.whitespace: "[[:space:]]+$" 29 | -------------------------------------------------------------------------------- /syntax_files/cython.yaml: -------------------------------------------------------------------------------- 1 | filetype: cython 2 | 3 | detect: 4 | filename: "\\.pyx$|\\.pxd$|\\.pyi$" 5 | 6 | rules: 7 | # Python Keyword Color 8 | - statement: "\\b(and|as|assert|class|def|DEF|del|elif|ELIF|else|ELSE|except|exec|finally|for|from|global|if|IF|import|in|is|lambda|map|not|or|pass|print|raise|try|while|with|yield)\\b" 9 | - special: "\\b(continue|break|return)\\b" 10 | 11 | # Cython Keyword Color 12 | - identifier.macro: "\\b(cdef|cimport|cpdef|cppclass|ctypedef|extern|include|namespace|property|struct)\\b" 13 | - type: "\\b(bint|char|double|int|public|void|unsigned)\\b" 14 | 15 | # Operator Color 16 | - symbol: "[.:;,+*|=!\\%]|<|>|/|-|&" 17 | 18 | # Parenthetical Color 19 | - symbol.brackets: "[(){}]|\\[|\\]" 20 | 21 | - constant.string: 22 | start: "\"\"\"" 23 | end: "\"\"\"" 24 | rules: 25 | - constant.specialChar: "\\\\." 26 | 27 | - constant.string: 28 | start: "'''" 29 | end: "'''" 30 | rules: 31 | - constant.specialChar: "\\\\." 32 | 33 | - constant.string: 34 | start: "\"" 35 | end: "\"" 36 | skip: "\\\\." 37 | rules: 38 | - constant.specialChar: "\\\\." 39 | 40 | - constant.string: 41 | start: "'" 42 | end: "'" 43 | skip: "\\\\." 44 | rules: 45 | - constant.specialChar: "\\\\." 46 | 47 | - comment: 48 | start: "#" 49 | end: "$" 50 | rules: 51 | - todo: "(TODO|XXX|FIXME):?" 52 | 53 | -------------------------------------------------------------------------------- /syntax_files/dart.yaml: -------------------------------------------------------------------------------- 1 | filetype: dart 2 | 3 | detect: 4 | filename: "\\.dart$" 5 | 6 | rules: 7 | - constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b" 8 | - constant.number: "\\b[-+]?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?" 9 | - constant.number: "\\b[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?" 10 | - identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[(]" 11 | - statement: "\\b(break|case|catch|continue|default|else|finally)\\b" 12 | - statement: "\\b(for|function|get|if|in|as|is|new|return|set|switch|final|await|async|sync)\\b" 13 | - statement: "\\b(switch|this|throw|try|var|void|while|with|import|library|part|const|export)\\b" 14 | - constant: "\\b(true|false|null)\\b" 15 | - type: "\\b(List|String)\\b" 16 | - type: "\\b(int|num|double|bool)\\b" 17 | - statement: "[-+/*=<>!~%?:&|]" 18 | - constant: "/[^*]([^/]|(\\\\/))*[^\\\\]/[gim]*" 19 | - constant: "\\\\[0-7][0-7]?[0-7]?|\\\\x[0-9a-fA-F]+|\\\\[bfnrt'\"\\?\\\\]" 20 | 21 | - comment: 22 | start: "//" 23 | end: "$" 24 | rules: 25 | - todo: "TODO:?" 26 | 27 | - comment: 28 | start: "/\\*" 29 | end: "\\*/" 30 | rules: 31 | - todo: "TODO:?" 32 | 33 | - constant.string: 34 | start: "\"" 35 | end: "\"" 36 | skip: "\\\\." 37 | rules: 38 | - constant.specialChar: "\\\\." 39 | 40 | - constant.string: 41 | start: "'" 42 | end: "'" 43 | skip: "\\\\." 44 | rules: 45 | - constant.specialChar: "\\\\." 46 | 47 | -------------------------------------------------------------------------------- /syntax_files/puppet.yaml: -------------------------------------------------------------------------------- 1 | filetype: puppet 2 | 3 | detect: 4 | filename: "\\.pp$" 5 | 6 | rules: 7 | - default: "^[[:space:]]([a-z][a-z0-9_]+)" 8 | - identifier.var: "\\$[a-z:][a-z0-9_:]+" 9 | - type: "\\b(augeas|computer|cron|exec|file|filebucket|group|host|interface|k5login|macauthorization|mailalias|maillist|mcx|mount|nagios_command|nagios_contact|nagios_contactgroup|nagios_host|nagios_hostdependency|nagios_hostescalation|nagios_hostextinfo|nagios_hostgroup|nagios_service|nagios_servicedependency|nagios_serviceescalation|nagios_serviceextinfo|nagios_servicegroup|nagios_timeperiod|notify|package|resources|router|schedule|scheduled_task|selboolean|selmodule|service|ssh_authorized_key|sshkey|stage|tidy|user|vlan|yumrepo|zfs|zone|zpool|anchor)\\b" 10 | - statement: "\\b(class|define|if|else|undef|inherits)\\b" 11 | - symbol: "(=|-|~|>)" 12 | - identifier.var: "(\\$|@|@@)?\\b[A-Z]+[0-9A-Z_a-z]*" 13 | - symbol: "([ ]|^):[0-9A-Z_]+\\b" 14 | - constant: "/([^/]|(\\\\/))*/[iomx]*|%r\\{([^}]|(\\\\}))*\\}[iomx]*" 15 | - constant.string: "`[^`]*`|%x\\{[^}]*\\}" 16 | - constant.string: "\"([^\"]|(\\\\\"))*\"|%[QW]?\\{[^}]*\\}|%[QW]?\\([^)]*\\)|%[QW]?<[^>]*>|%[QW]?\\[[^]]*\\]|%[QW]?\\$[^$]*\\$|%[QW]?\\^[^^]*\\^|%[QW]?![^!]*!" 17 | - special: "\\$\\{[^}]*\\}" 18 | - constant.string: "'([^']|(\\\\'))*'|%[qw]\\{[^}]*\\}|%[qw]\\([^)]*\\)|%[qw]<[^>]*>|%[qw]\\[[^]]*\\]|%[qw]\\$[^$]*\\$|%[qw]\\^[^^]*\\^|%[qw]![^!]*!" 19 | - comment: "#[^{].*$|#$" 20 | - comment.bright: "##[^{].*$|##$" 21 | - todo: "(XXX|TODO|FIXME|\\?\\?\\?)" 22 | - indent-char.whitespace: "[[:space:]]+$" 23 | -------------------------------------------------------------------------------- /syntax_files/javascript.yaml: -------------------------------------------------------------------------------- 1 | filetype: javascript 2 | 3 | detect: 4 | filename: "\\.js$" 5 | 6 | rules: 7 | - constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b" 8 | - constant.number: "\\b[-+]?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?" 9 | - constant.number: "\\b[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?" 10 | - identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[(]" 11 | - statement: "\\b(break|case|catch|continue|default|delete|do|else|finally)\\b" 12 | - statement: "\\b(for|function|get|if|in|instanceof|new|return|set|switch)\\b" 13 | - statement: "\\b(switch|this|throw|try|typeof|var|void|while|with)\\b" 14 | - constant: "\\b(null|undefined|NaN)\\b" 15 | - constant: "\\b(true|false)\\b" 16 | - type: "\\b(Array|Boolean|Date|Enumerator|Error|Function|Math)\\b" 17 | - type: "\\b(Number|Object|RegExp|String)\\b" 18 | - statement: "[-+/*=<>!~%?:&|]" 19 | - constant: "/[^*]([^/]|(\\\\/))*[^\\\\]/[gim]*" 20 | - constant: "\\\\[0-7][0-7]?[0-7]?|\\\\x[0-9a-fA-F]+|\\\\[bfnrt'\"\\?\\\\]" 21 | 22 | - constant.string: 23 | start: "\"" 24 | end: "\"" 25 | skip: "\\\\." 26 | rules: 27 | - constant.specialChar: "\\\\." 28 | 29 | - constant.string: 30 | start: "'" 31 | end: "'" 32 | skip: "\\\\." 33 | rules: 34 | - constant.specialChar: "\\\\." 35 | 36 | - comment: 37 | start: "//" 38 | end: "$" 39 | rules: [] 40 | 41 | - comment: 42 | start: "/\\*" 43 | end: "\\*/" 44 | rules: [] 45 | 46 | -------------------------------------------------------------------------------- /syntax_files/awk.yaml: -------------------------------------------------------------------------------- 1 | filetype: awk 2 | 3 | detect: 4 | filename: "\\.awk$" 5 | header: "^#!.*bin/(env +)?awk( |$)" 6 | 7 | rules: 8 | - preproc: "\\$[A-Za-z0-9_!@#$*?\\-]+" 9 | - preproc: "\\b(ARGC|ARGIND|ARGV|BINMODE|CONVFMT|ENVIRON|ERRNO|FIELDWIDTHS)\\b" 10 | - preproc: "\\b(FILENAME|FNR|FS|IGNORECASE|LINT|NF|NR|OFMT|OFS|ORS)\\b" 11 | - preproc: "\\b(PROCINFO|RS|RT|RSTART|RLENGTH|SUBSEP|TEXTDOMAIN)\\b" 12 | - identifier.class: "\\b(function|extension|BEGIN|END)\\b" 13 | - symbol.operator: "[\\-+*/%^|!=&<>?;:]|\\\\|\\[|\\]" 14 | - statement: "\\b(for|if|while|do|else|in|delete|exit)\\b" 15 | - special: "\\b(break|continue|return)\\b" 16 | - statement: "\\b(close|getline|next|nextfile|print|printf|system|fflush)\\b" 17 | - statement: "\\b(atan2|cos|exp|int|log|rand|sin|sqrt|srand)\\b" 18 | - statement: "\\b(asort|asorti|gensub|gsub|index|length|match)\\b" 19 | - statement: "\\b(split|sprintf|strtonum|sub|substr|tolower|toupper)\\b" 20 | - statement: "\\b(mktime|strftime|systime)\\b" 21 | - statement: "\\b(and|compl|lshift|or|rshift|xor)\\b" 22 | - statement: "\\b(bindtextdomain|dcgettext|dcngettext)\\b" 23 | - special: "/.*[^\\\\]/" 24 | 25 | - constant.string: 26 | start: "\"" 27 | end: "\"" 28 | skip: "\\\\." 29 | rules: 30 | - constant.specialChar: "\\\\." 31 | 32 | - constant.string: 33 | start: "'" 34 | end: "'" 35 | skip: "\\\\." 36 | rules: 37 | - constant.specialChar: "\\\\." 38 | 39 | - comment: 40 | start: "#" 41 | end: "$" 42 | rules: 43 | - todo: "(TODO|XXX|FIXME):?" 44 | 45 | -------------------------------------------------------------------------------- /syntax_files/privoxy-action.yaml: -------------------------------------------------------------------------------- 1 | filetype: privoxy-action 2 | 3 | detect: 4 | filename: "\\.action$" 5 | 6 | rules: 7 | - constant.bool.false: "[{[:space:]]\\-block([[:space:]{}]|$)" 8 | - constant.bool.true: "[{[:space:]]\\+block([[:space:]{}]|$)" 9 | - constant.bool.false: "-(add-header|change-x-forwarded-for|client-header-filter|client-header-tagger|content-type-overwrite|crunch-client-header|crunch-if-none-match|crunch-incoming-cookies|crunch-outgoing-cookies|crunch-server-header|deanimate-gifs|downgrade-http-version|fast-redirects|filter|force-text-mode|forward-override|handle-as-empty-document|handle-as-image|hide-accept-language|hide-content-disposition|hide-from-header|hide-if-modified-since|hide-referrer|hide-user-agent|limit-connect|overwrite-last-modified|prevent-compression|redirect|server-header-filter|server-header-tagger|session-cookies-only|set-image-blocker)" 10 | - constant.bool.true: "\\+(add-header|change-x-forwarded-for|client-header-filter|client-header-tagger|content-type-overwrite|crunch-client-header|crunch-if-none-match|crunch-incoming-cookies|crunch-outgoing-cookies|crunch-server-header|deanimate-gifs|downgrade-http-version|fast-redirects|filter|force-text-mode|forward-override|handle-as-empty-document|handle-as-image|hide-accept-language|hide-content-disposition|hide-from-header|hide-if-modified-since|hide-referrer|hide-user-agent|limit-connect|overwrite-last-modified|prevent-compression|redirect|server-header-filter|server-header-tagger|session-cookies-only|set-image-blocker)" 11 | - constant.specialChar: "\\\\.?" 12 | - comment: "(^|[[:space:]])#([^{].*)?$" 13 | - indent-char.whitespace: "[[:space:]]+$" 14 | - indent-char: " + +| + +" 15 | -------------------------------------------------------------------------------- /syntax_files/perl.yaml: -------------------------------------------------------------------------------- 1 | filetype: perl 2 | 3 | detect: 4 | filename: "\\.p[lm]$" 5 | header: "^#!.*/(env +)?perl( |$)" 6 | 7 | rules: 8 | - type: "\\b(accept|alarm|atan2|bin(d|mode)|c(aller|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|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" 9 | - statement: "\\b(continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|sub|use|package|can|isa)\\b" 10 | - identifier: 11 | start: "[$@%]" 12 | end: "((?i) |[^0-9A-Z_]|-)" 13 | rules: [] 14 | 15 | - constant.string: "\".*\"|qq\\|.*\\|" 16 | - default: "[sm]/.*/" 17 | - preproc: 18 | start: "(^use| = new)" 19 | end: ";" 20 | rules: [] 21 | 22 | - comment: "#.*" 23 | - identifier.macro: 24 | start: "<< 'STOP'" 25 | end: "STOP" 26 | rules: [] 27 | 28 | -------------------------------------------------------------------------------- /syntax_files/perl6.yaml: -------------------------------------------------------------------------------- 1 | filetype: perl6 2 | 3 | detect: 4 | filename: "\\.p6$" 5 | 6 | rules: 7 | - type: "\\b(accept|alarm|atan2|bin(d|mode)|c(aller|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)|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|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|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|s|scalar|seek|seekdir|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|un(def|link|pack|shift)|utime|values|vec|wait(pid)?|wantarray|warn|write)\\b" 8 | - statement: "\\b(continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|sub|use|package|can|isa)\\b" 9 | - special: "\\b(has|is|class|role|given|when|BUILD|multi|returns|method|submethod|slurp|say|sub)\\b" 10 | - identifier: 11 | start: "[$@%]" 12 | end: "( |\\\\W|-)" 13 | rules: [] 14 | 15 | - constant.string: "\".*\"|qq\\|.*\\|" 16 | - default: "[sm]/.*/" 17 | - preproc: 18 | start: "(^use| = new)" 19 | end: ";" 20 | rules: [] 21 | 22 | - comment: "#.*" 23 | - identifier.macro: 24 | start: "<|<=|>=)" 17 | 18 | # Various symbols 19 | - special: "(->|<-)" 20 | - symbol: "\\.|\\$" 21 | 22 | # Data constructors 23 | - constant.bool: "\\b(True|False)\\b" 24 | - constant: "(Nothing|Just|Left|Right|LT|EQ|GT)" 25 | 26 | # Data classes 27 | - identifier.class: "[ ](Read|Show|Enum|Eq|Ord|Data|Bounded|Typeable|Num|Real|Fractional|Integral|RealFrac|Floating|RealFloat|Monad|MonadPlus|Functor)" 28 | 29 | # Strings 30 | - constant.string: 31 | start: "\"" 32 | end: "\"" 33 | skip: "\\\\." 34 | rules: 35 | - constant.specialChar: "\\\\." 36 | 37 | # Comments 38 | - comment: 39 | start: "--" 40 | end: "$" 41 | rules: 42 | - todo: "(TODO|XXX|FIXME):?" 43 | 44 | - comment: 45 | start: "\\{-" 46 | end: "-\\}" 47 | rules: 48 | - todo: "(TODO|XXX|FIXME):?" 49 | 50 | - identifier.micro: "undefined" 51 | -------------------------------------------------------------------------------- /syntax_files/solidity.yaml: -------------------------------------------------------------------------------- 1 | filetype: solidity 2 | 3 | detect: 4 | filename: "\\.sol$" 5 | 6 | rules: 7 | - preproc: "\\b(contract|library|pragma)\\b" 8 | - constant.number: "\\b[-]?([0-9]+|0x[0-9a-fA-F]+)\\b" 9 | - identifier: "[a-zA-Z][_a-zA-Z0-9]*[[:space:]]*" 10 | - statement: "\\b(assembly|break|continue|do|for|function|if|else|new|return|returns|while)\\b" 11 | - special: "\\b(\\.send|throw)\\b" # make sure they are very visible 12 | - keyword: "\\b(anonymous|constant|indexed|payable|public|private|external|internal)\\b" 13 | - constant: "\\b(block(\\.(blockhash|coinbase|difficulty|gaslimit|number|timestamp))?|msg(\\.(data|gas|sender|value))?|now|tx(\\.(gasprice|origin))?)\\b" 14 | - constant: "\\b(keccak256|sha3|sha256|ripemd160|ecrecover|addmod|mulmod|this|super|selfdestruct|\\.balance)\\b" 15 | - constant: "\\b(true|false)\\b" 16 | - constant: "\\b(wei|szabo|finney|ether|seconds|minutes|hours|days|weeks|years)\\b" 17 | - type: "\\b(address|bool|mapping|string|var|int(\\d*)|uint(\\d*)|byte(\\d*)|fixed(\\d*)|ufixed(\\d*))\\b" 18 | - error: "\\b(abstract|after|case|catch|default|final|in|inline|interface|let|match|null|of|pure|relocatable|static|switch|try|type|typeof|view)\\b" 19 | - operator: "[-+/*=<>!~%?:&|]" 20 | - comment: 21 | start: "//" 22 | end: "$" 23 | rules: [] 24 | - comment: 25 | start: "/\\*" 26 | end: "\\*/" 27 | rules: [] 28 | - todo: "TODO:?" 29 | - constant.string: 30 | start: "\"" 31 | end: "\"" 32 | skip: "\\\\." 33 | rules: 34 | - constant.specialChar: "\\\\." 35 | - constant.string: 36 | start: "'" 37 | end: "'" 38 | skip: "\\\\." 39 | rules: 40 | - constant.specialChar: "\\\\." 41 | 42 | -------------------------------------------------------------------------------- /syntax_files/html.yaml: -------------------------------------------------------------------------------- 1 | filetype: html 2 | 3 | detect: 4 | filename: "\\.htm[l]?$" 5 | 6 | rules: 7 | - error: "<[^!].*?>" 8 | - symbol.tag: "(?i)<[/]?(a(bbr|cronym|ddress|pplet|rea|rticle|side|udio)?|b(ase(font)?|d(i|o)|ig|lockquote|r)?|ca(nvas|ption)|center|cite|co(de|l|lgroup)|d(ata(list)?|d|el|etails|fn|ialog|ir|l|t)|em(bed)?|fieldset|fig(caption|ure)|font|form|(i)?frame|frameset|h[1-6]|hr|i|img|in(put|s)|kbd|keygen|label|legend|li(nk)?|ma(in|p|rk)|menu(item)?|met(a|er)|nav|no(frames|script)|o(l|pt(group|ion)|utput)|p(aram|icture|re|rogress)?|q|r(p|t|uby)|s(trike)?|samp|se(ction|lect)|small|source|span|strong|su(b|p|mmary)|textarea|time|track|u(l)?|var|video|wbr)( .*|>)*?>" 9 | - symbol.tag.extended: "(?i)<[/]?(body|div|html|head(er)?|footer|title|table|t(body|d|h(ead)?|r|foot))( .*)*?>" 10 | - special: "&[^;[[:space:]]]*;" 11 | - symbol: "[:=]" 12 | - identifier: "(alt|bgcolor|height|href|id|label|longdesc|name|on(click|focus|load|mouseover)|size|span|src|target|type|value|width)=" 13 | - constant.number: "(?i)#[0-9A-F]{6,6}" 14 | # - default: 15 | # start: ">" 16 | # end: "<" 17 | # rules: [] 18 | 19 | - symbol.tag: "<|>" 20 | - constant.string.url: "(ftp(s)?|http(s)?|git|chrome)://[^ ]+" 21 | - comment: "" 22 | - preproc: "" 23 | 24 | - constant.string: 25 | start: "\"" 26 | end: "\"" 27 | skip: "\\\\." 28 | rules: 29 | - constant.specialChar: "\\\\." 30 | 31 | - default: 32 | start: "" 33 | end: "" 34 | limit-group: symbol.tag 35 | rules: 36 | - include: "javascript" 37 | 38 | - default: 39 | start: "" 40 | end: "" 41 | limit-group: symbol.tag 42 | rules: 43 | - include: "css" 44 | 45 | -------------------------------------------------------------------------------- /syntax_files/typescript.yaml: -------------------------------------------------------------------------------- 1 | filetype: typescript 2 | 3 | detect: 4 | filename: "\\.ts$" 5 | 6 | rules: 7 | - constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b" 8 | - constant.number: "\\b[-+]?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?" 9 | - constant.number: "\\b[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?" 10 | - identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[(]" 11 | - statement: "\\b(abstract|as|async|await|break|case|catch|class|const|constructor|continue)\\b" 12 | - statement: "\\b(debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from)\\b" 13 | - statement: "\\b(function|get|if|implements|import|in|instanceof|interface|is|let|module|namespace)\\b" 14 | - statement: "\\b(new|of|package|private|protected|public|require|return|set|static|super|switch)\\b" 15 | - statement: "\\b(this|throw|try|type|typeof|var|void|while|with|yield)\\b" 16 | - constant: "\\b(false|true|null|undefined|NaN)\\b" 17 | - type: "\\b(Array|Boolean|Date|Enumerator|Error|Function|Math)\\b" 18 | - type: "\\b(Number|Object|RegExp|String|Symbol)\\b" 19 | - type: "\\b(any|boolean|never|number|string|symbol)\\b" 20 | - statement: "[-+/*=<>!~%?:&|]" 21 | - constant: "/[^*]([^/]|(\\\\/))*[^\\\\]/[gim]*" 22 | - constant: "\\\\[0-7][0-7]?[0-7]?|\\\\x[0-9a-fA-F]+|\\\\[bfnrt'\"\\?\\\\]" 23 | - comment: 24 | start: "//" 25 | end: "$" 26 | rules: [] 27 | - comment: 28 | start: "/\\*" 29 | end: "\\*/" 30 | rules: 31 | - todo: "TODO:?" 32 | - constant.string: 33 | start: "\"" 34 | end: "\"" 35 | skip: "\\\\." 36 | rules: 37 | - constant.specialChar: "\\\\." 38 | - constant.string: 39 | start: "'" 40 | end: "'" 41 | skip: "\\\\." 42 | rules: 43 | - constant.specialChar: "\\\\." 44 | 45 | -------------------------------------------------------------------------------- /syntax_files/rpmspec.yaml: -------------------------------------------------------------------------------- 1 | filetype: rpmspec 2 | 3 | detect: 4 | filename: "\\.spec$|\\.rpmspec$" 5 | 6 | rules: 7 | - preproc: "\\b(Icon|ExclusiveOs|ExcludeOs):" 8 | - preproc: "\\b(BuildArch|BuildArchitectures|ExclusiveArch|ExcludeArch):" 9 | - preproc: "\\b(Conflicts|Obsoletes|Provides|Requires|Requires\\(.*\\)|Enhances|Suggests|BuildConflicts|BuildRequires|Recommends|PreReq|Supplements):" 10 | - preproc: "\\b(Epoch|Serial|Nosource|Nopatch):" 11 | - preproc: "\\b(AutoReq|AutoProv|AutoReqProv):" 12 | - preproc: "\\b(Copyright|License|Summary|Summary\\(.*\\)|Distribution|Vendor|Packager|Group|Source[0-9]*|Patch[0-9]*|BuildRoot|Prefix):" 13 | - preproc: "\\b(Name|Version|Release|Url|URL):" 14 | - preproc: 15 | start: "^(Source|Patch)" 16 | end: ":" 17 | rules: [] 18 | 19 | - preproc: "(i386|i486|i586|i686|athlon|ia64|alpha|alphaev5|alphaev56|alphapca56|alphaev6|alphaev67|sparc|sparcv9|sparc64armv3l|armv4b|armv4lm|ips|mipsel|ppc|ppc|iseries|ppcpseries|ppc64|m68k|m68kmint|Sgi|rs6000|i370|s390x|s390|noarch)" 20 | - preproc: "(ifarch|ifnarch|ifos|ifnos)" 21 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 22 | - statement: "%(if|else|endif|define|global|undefine)" 23 | - statement: "%_?([A-Z_a-z_0-9_]*)" 24 | - statement: 25 | start: "%\\{" 26 | end: "\\}" 27 | rules: [] 28 | 29 | - statement: 30 | start: "%\\{__" 31 | end: "\\}" 32 | rules: [] 33 | 34 | - statement: "\\$(RPM_BUILD_ROOT)\\>" 35 | - special: "^%(build$|changelog|check$|clean$|description)" 36 | - special: "^%(files|install$|package|prep$)" 37 | - special: "^%(pre|preun|pretrans|post|postun|posttrans)" 38 | - special: "^%(trigger|triggerin|triggerpostun|triggerun|verifyscript)" 39 | - comment: "(^|[[:space:]])#([^{].*)?$" 40 | - constant: "^\\*.*$" 41 | - indent-char.whitespace: "[[:space:]]+$" 42 | - indent-char: " + +| + +" 43 | - todo: "TODO:?" 44 | -------------------------------------------------------------------------------- /syntax_files/c.yaml: -------------------------------------------------------------------------------- 1 | filetype: c 2 | 3 | detect: 4 | filename: "(\\.(c|C)$|\\.(h|H)$|\\.ii?$|\\.(def)$)" 5 | 6 | rules: 7 | - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" 8 | - type: "\\b(float|double|char|int|short|long|sizeof|enum|void|static|const|struct|union|typedef|extern|(un)?signed|inline)\\b" 9 | - type: "\\b((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\\b" 10 | - type.extended: "\\b(bool)\\b" 11 | - statement: "\\b(typename|mutable|volatile|register|explicit)\\b" 12 | - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" 13 | - statement: "\\b(try|throw|catch|operator|new|delete)\\b" 14 | - statement: "\\b(goto|continue|break|return)\\b" 15 | - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)" 16 | - constant: "'([^'\\\\]|(\\\\[\"'abfnrtv\\\\]))'" 17 | - constant: "'\\\\(([0-3]?[0-7]{1,2}))'" 18 | - constant: "'\\\\x[0-9A-Fa-f]{1,2}'" 19 | # GCC builtins 20 | - statement: "__attribute__[[:space:]]*\\(\\([^)]*\\)\\)" 21 | - statement: "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__" 22 | # Operator Color 23 | - symbol.operator: "([.:;,+*|=!\\%]|<|>|/|-|&)" 24 | - symbol.brackets: "[(){}]|\\[|\\]" 25 | - constant.number: "(\\b[0-9]+\\b|\\b0x[0-9A-Fa-f]+\\b)" 26 | - constant.number: "NULL" 27 | 28 | - constant.string: 29 | start: "\"" 30 | end: "\"" 31 | skip: "\\\\." 32 | rules: 33 | - constant.specialChar: "\\\\." 34 | 35 | - constant.string: 36 | start: "'" 37 | end: "'" 38 | skip: "\\\\." 39 | rules: 40 | - preproc: "..+" 41 | - constant.specialChar: "\\\\." 42 | 43 | - comment: 44 | start: "//" 45 | end: "$" 46 | rules: 47 | - todo: "(TODO|XXX|FIXME):?" 48 | 49 | - comment: 50 | start: "/\\*" 51 | end: "\\*/" 52 | rules: 53 | - todo: "(TODO|XXX|FIXME):?" 54 | 55 | -------------------------------------------------------------------------------- /syntax_files/pascal.yaml: -------------------------------------------------------------------------------- 1 | filetype: pascal 2 | 3 | detect: 4 | filename: "\\.pas$" 5 | 6 | rules: 7 | - type: "\\b(?i:(string|ansistring|widestring|shortstring|char|ansichar|widechar|boolean|byte|shortint|word|smallint|longword|cardinal|longint|integer|int64|single|currency|double|extended))\\b" 8 | - statement: "\\b(?i:(and|asm|array|begin|break|case|const|constructor|continue|destructor|div|do|downto|else|end|file|for|function|goto|if|implementation|in|inline|interface|label|mod|not|object|of|on|operator|or|packed|procedure|program|record|repeat|resourcestring|set|shl|shr|then|to|type|unit|until|uses|var|while|with|xor))\\b" 9 | - statement: "\\b(?i:(as|class|dispose|except|exit|exports|finalization|finally|inherited|initialization|is|library|new|on|out|property|raise|self|threadvar|try))\\b" 10 | - statement: "\\b(?i:(absolute|abstract|alias|assembler|cdecl|cppdecl|default|export|external|forward|generic|index|local|name|nostackframe|oldfpccall|override|pascal|private|protected|public|published|read|register|reintroduce|safecall|softfloat|specialize|stdcall|virtual|write))\\b" 11 | - constant: "\\b(?i:(false|true|nil))\\b" 12 | - special: 13 | start: "asm" 14 | end: "end" 15 | rules: [] 16 | - constant.number: "\\$[0-9A-Fa-f]+" 17 | - constant.number: "\\b[+-]?[0-9]+([.]?[0-9]+)?(?i:e[+-]?[0-9]+)?" 18 | - constant.string: 19 | start: "#[0-9]{1,}" 20 | end: "$" 21 | rules: 22 | - constant.specialChar: "\\\\." 23 | - constant.string: 24 | start: "'" 25 | end: "'" 26 | skip: "\\\\." 27 | rules: 28 | - constant.specialChar: "\\\\." 29 | - preproc: 30 | start: "{\\$" 31 | end: "}" 32 | rules: [] 33 | - comment: 34 | start: "//" 35 | end: "$" 36 | rules: [] 37 | - comment: 38 | start: "\\(\\*" 39 | end: "\\*\\)" 40 | rules: [] 41 | - comment: 42 | start: "({)(?:[^$])" 43 | end: "}" 44 | rules: [] 45 | 46 | -------------------------------------------------------------------------------- /syntax_files/crystal.yaml: -------------------------------------------------------------------------------- 1 | filetype: crystal 2 | 3 | detect: 4 | filename: "\\.cr$" 5 | 6 | rules: 7 | # Asciibetical list of reserved words 8 | - statement: "\\b(BEGIN|END|abstract|alias|and|begin|break|case|class|def|defined\\?|do|else|elsif|end|ensure|enum|false|for|fun|if|in|include|lib|loop|macro|module|next|nil|not|of|or|pointerof|private|protected|raise|redo|require|rescue|retry|return|self|sizeof|spawn|struct|super|then|true|type|undef|union|uninitialized|unless|until|when|while|yield)\\b" 9 | # Constants 10 | - constant: "(\\$|@|@@)?\\b[A-Z]+[0-9A-Z_a-z]*" 11 | - constant.number: "\\b[0-9]+\\b" 12 | # Crystal "symbols" 13 | - constant: "([ ]|^):[0-9A-Z_]+\\b" 14 | # Some unique things we want to stand out 15 | - constant: "\\b(__FILE__|__LINE__)\\b" 16 | # Regular expressions 17 | - constant: "/([^/]|(\\\\/))*/[iomx]*|%r\\{([^}]|(\\\\}))*\\}[iomx]*" 18 | 19 | # Shell command expansion is in `backticks` or like %x{this}. These are 20 | # "double-quotish" (to use a perlism). 21 | - constant.string: "`[^`]*`|%x\\{[^}]*\\}" 22 | 23 | - constant.string: 24 | start: "`" 25 | end: "`" 26 | rules: [] 27 | 28 | - constant.string: 29 | start: "%x\\{" 30 | end: "\\}" 31 | rules: [] 32 | 33 | - constant.string: 34 | start: "\"" 35 | end: "\"" 36 | skip: "\\\\." 37 | rules: 38 | - constant.specialChar: "\\\\." 39 | - special: "#\\{[^}]*\\}" 40 | 41 | - constant.string: 42 | start: "'" 43 | end: "'" 44 | skip: "\\\\." 45 | rules: 46 | - constant.specialChar: "\\\\." 47 | 48 | - comment: 49 | start: "#" 50 | end: "$" 51 | rules: 52 | - todo: "(TODO|XXX|FIXME):?" 53 | 54 | - comment.bright: 55 | start: "##" 56 | end: "$" 57 | rules: 58 | - todo: "(TODO|XXX|FIXME):?" 59 | 60 | - constant: 61 | start: "<<-?'?EOT'?" 62 | end: "^EOT" 63 | rules: [] 64 | 65 | -------------------------------------------------------------------------------- /syntax_files/sh.yaml: -------------------------------------------------------------------------------- 1 | filetype: shell 2 | 3 | detect: 4 | filename: "(\\.sh$|\\.bash|\\.bashrc|bashrc|\\.bash_aliases|bash_aliases|\\.bash_functions|bash_functions|\\.bash_profile|bash_profile|Pkgfile|pkgmk.conf|profile|rc.conf|PKGBUILD|.ebuild\\$|APKBUILD)" 5 | header: "^#!.*/(env +)?(ba)?sh( |$)" 6 | 7 | rules: 8 | # Numbers 9 | - constant.number: "\\b[0-9]+\\b" 10 | # Conditionals and control flow 11 | - statement: "\\b(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\\b" 12 | - special: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" 13 | # Shell commands 14 | - type: "\\b(cd|echo|export|let|set|umask|unset)\\b" 15 | # Common linux commands 16 | - type: "\\b((g|ig)?awk|bash|dash|find|\\w{0,4}grep|kill|killall|\\w{0,4}less|make|pkill|sed|sh|tar)\\b" 17 | # Coreutils commands 18 | - type: "\\b(base64|basename|cat|chcon|chgrp|chmod|chown|chroot|cksum|comm|cp|csplit|cut|date|dd|df|dir|dircolors|dirname|du|env|expand|expr|factor|false|fmt|fold|head|hostid|id|install|join|link|ln|logname|ls|md5sum|mkdir|mkfifo|mknod|mktemp|mv|nice|nl|nohup|nproc|numfmt|od|paste|pathchk|pinky|pr|printenv|printf|ptx|pwd|readlink|realpath|rm|rmdir|runcon|seq|(sha1|sha224|sha256|sha384|sha512)sum|shred|shuf|sleep|sort|split|stat|stdbuf|stty|sum|sync|tac|tail|tee|test|time|timeout|touch|tr|true|truncate|tsort|tty|uname|unexpand|uniq|unlink|users|vdir|wc|who|whoami|yes)\\b" 19 | # Conditional flags 20 | - statement: "--[a-z-]+" 21 | - statement: "\\ -[a-z]+" 22 | 23 | - identifier: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" 24 | - identifier: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" 25 | 26 | - constant.string: 27 | start: "\"" 28 | end: "\"" 29 | skip: "\\\\." 30 | rules: 31 | - constant.specialChar: "\\\\." 32 | 33 | - constant.string: 34 | start: "'" 35 | end: "'" 36 | rules: [] 37 | 38 | - comment: 39 | start: "#" 40 | end: "$" 41 | rules: 42 | - todo: "(TODO|XXX|FIXME):?" 43 | 44 | -------------------------------------------------------------------------------- /syntax_files/cpp.yaml: -------------------------------------------------------------------------------- 1 | filetype: c++ 2 | 3 | detect: 4 | filename: "(\\.c(c|pp|xx)$|\\.h(h|pp|xx)$|\\.ii?$|\\.(def)$)" 5 | 6 | rules: 7 | 8 | - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" 9 | - type: "\\b(auto|float|double|bool|char|int|short|long|sizeof|enum|void|static|const|constexpr|struct|union|typedef|extern|(un)?signed|inline)\\b" 10 | - type: "\\b((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\\b" 11 | - statement: "\\b(class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)\\b" 12 | - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" 13 | - statement: "\\b(try|throw|catch|operator|new|delete)\\b" 14 | - statement: "\\b(goto|continue|break|return)\\b" 15 | - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)" 16 | - constant: "('([^'\\\\]|(\\\\[\"'abfnrtv\\\\]))'|'\\\\(([0-3]?[0-7]{1,2}))'|'\\\\x[0-9A-Fa-f]{1,2}')" 17 | 18 | # GCC builtins 19 | - statement: "(__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__)" 20 | 21 | # Operator Color 22 | - symbol.operator: "([.:;,+*|=!\\%]|<|>|/|-|&)" 23 | # Parenthetical Color 24 | - symbol.brackets: "[(){}]|\\[|\\]" 25 | 26 | - constant.number: "(\\b[0-9]+\\b|\\b0x[0-9A-Fa-f]+\\b)" 27 | - constant.bool: "(\\b(true|false)\\b|NULL)" 28 | 29 | - constant.string: 30 | start: "\"" 31 | end: "\"" 32 | skip: "\\\\." 33 | rules: 34 | - constant.specialChar: "\\\\." 35 | 36 | - constant.string: 37 | start: "'" 38 | end: "'" 39 | skip: "\\\\." 40 | rules: 41 | - preproc: "..+" 42 | - constant.specialChar: "\\\\." 43 | 44 | - comment: 45 | start: "//" 46 | end: "$" 47 | rules: 48 | - todo: "(TODO|XXX|FIXME):?" 49 | 50 | - comment: 51 | start: "/\\*" 52 | end: "\\*/" 53 | rules: 54 | - todo: "(TODO|XXX|FIXME):?" 55 | 56 | -------------------------------------------------------------------------------- /syntax_files/go.yaml: -------------------------------------------------------------------------------- 1 | filetype: go 2 | 3 | detect: 4 | filename: "\\.go$" 5 | 6 | rules: 7 | # Conditionals and control flow 8 | - special: "\\b(break|case|continue|default|go|goto|range|return)\\b" 9 | - statement: "\\b(else|for|if|switch)\\b" 10 | - preproc: "\\b(package|import|const|var|type|struct|func|go|defer|iota)\\b" 11 | - symbol.operator: "[-+/*=<>!~%&|^]|:=" 12 | 13 | # Types 14 | - special: "[a-zA-Z0-9]*\\(" 15 | - symbol: "(,|\\.)" 16 | - type: "\\b(u?int(8|16|32|64)?|float(32|64)|complex(64|128))\\b" 17 | - type: "\\b(uintptr|byte|rune|string|interface|bool|map|chan|error)\\b" 18 | ##I'm... not sure, but aren't structs a type? 19 | - type.keyword: "\\b(struct)\\b" 20 | - constant.bool: "\\b(true|false|nil)\\b" 21 | 22 | # Brackets 23 | - symbol.brackets: "(\\{|\\})" 24 | - symbol.brackets: "(\\(|\\))" 25 | - symbol.brackets: "(\\[|\\])" 26 | 27 | # Numbers and strings 28 | - constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b|'.'" 29 | 30 | - constant.string: 31 | start: "\"" 32 | end: "\"" 33 | skip: "\\\\." 34 | rules: 35 | - constant.specialChar: "%." 36 | - constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]" 37 | - constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" 38 | 39 | - constant.string: 40 | start: "'" 41 | end: "'" 42 | skip: "\\\\." 43 | rules: 44 | - error: "..+" 45 | - constant.specialChar: "%." 46 | - constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]" 47 | - constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" 48 | 49 | - constant.string: 50 | start: "`" 51 | end: "`" 52 | rules: [] 53 | 54 | - comment: 55 | start: "//" 56 | end: "$" 57 | rules: 58 | - todo: "(TODO|XXX|FIXME):?" 59 | 60 | - comment: 61 | start: "/\\*" 62 | end: "\\*/" 63 | rules: 64 | - todo: "(TODO|XXX|FIXME):?" 65 | -------------------------------------------------------------------------------- /syntax_files/csharp.yaml: -------------------------------------------------------------------------------- 1 | filetype: csharp 2 | 3 | detect: 4 | filename: "\\.cs$" 5 | 6 | rules: 7 | # Class 8 | - identifier.class: "class +[A-Za-z0-9]+ *((:) +[A-Za-z0-9.]+)?" 9 | 10 | # Annotation 11 | - identifier.var: "@[A-Za-z]+" 12 | 13 | - identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[()]" 14 | - type: "\\b(bool|byte|sbyte|char|decimal|double|float|IntPtr|int|uint|long|ulong|object|short|ushort|string|base|this|var|void)\\b" 15 | - statement: "\\b(alias|as|case|catch|checked|default|do|dynamic|else|finally|fixed|for|foreach|goto|if|is|lock|new|null|return|switch|throw|try|unchecked|while)\\b" 16 | - statement: "\\b(abstract|async|class|const|delegate|enum|event|explicit|extern|get|implicit|in|internal|interface|namespace|operator|out|override|params|partial|private|protected|public|readonly|ref|sealed|set|sizeof|stackalloc|static|struct|typeof|unsafe|using|value|virtual|volatile|yield)\\b" 17 | # LINQ-only keywords (ones that cannot be used outside of a LINQ query - lots others can) 18 | - statement: "\\b(from|where|select|group|info|orderby|join|let|in|on|equals|by|ascending|descending)\\b" 19 | - special: "\\b(break|continue)\\b" 20 | - constant.bool: "\\b(true|false)\\b" 21 | - symbol.operator: "[\\-+/*=<>?:!~%&|]" 22 | - constant.number: "\\b([0-9._]+|0x[A-Fa-f0-9_]+|0b[0-1_]+)[FL]?\\b" 23 | 24 | - constant.string: 25 | start: "\"" 26 | end: "\"" 27 | skip: "\\\\." 28 | rules: 29 | - constant.specialChar: "\\\\([btnfr]|'|\\\"|\\\\)" 30 | - constant.specialChar: "\\\\u[A-Fa-f0-9]{4}" 31 | 32 | - constant.string: 33 | start: "'" 34 | end: "'" 35 | skip: "\\\\." 36 | rules: 37 | - constant.specialChar: "\\\\([btnfr]|'|\\\"|\\\\)" 38 | - constant.specialChar: "\\\\u[A-Fa-f0-9]{4}" 39 | 40 | - comment: 41 | start: "//" 42 | end: "$" 43 | rules: 44 | - todo: "(TODO|XXX|FIXME):?" 45 | 46 | - comment: 47 | start: "/\\*" 48 | end: "\\*/" 49 | rules: 50 | - todo: "(TODO|XXX|FIXME):?" 51 | 52 | -------------------------------------------------------------------------------- /syntax_files/fish.yaml: -------------------------------------------------------------------------------- 1 | filetype: fish 2 | 3 | detect: 4 | filename: "\\.fish$" 5 | header: "^#!.*/(env +)?fish( |$)" 6 | 7 | rules: 8 | # Numbers 9 | - constant: "\\b[0-9]+\\b" 10 | 11 | # Conditionals and control flow 12 | - statement: "\\b(and|begin|break|case|continue|else|end|for|function|if|in|not|or|return|select|shift|switch|while)\\b" 13 | - special: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|^|!|=|&|\\|)" 14 | 15 | # Fish commands 16 | - type: "\\b(bg|bind|block|breakpoint|builtin|cd|count|command|commandline|complete|dirh|dirs|echo|emit|eval|exec|exit|fg|fish|fish_config|fish_ident|fish_pager|fish_prompt|fish_right_prompt|fish_update_completions|fishd|funced|funcsave|functions|help|history|jobs|math|mimedb|nextd|open|popd|prevd|psub|pushd|pwd|random|read|set|set_color|source|status|string|trap|type|ulimit|umask|vared)\\b" 17 | 18 | # Common linux commands 19 | - type: "\\b((g|ig)?awk|bash|dash|find|\\w{0,4}grep|kill|killall|\\w{0,4}less|make|pkill|sed|sh|tar)\\b" 20 | 21 | # Coreutils commands 22 | - type: "\\b(base64|basename|cat|chcon|chgrp|chmod|chown|chroot|cksum|comm|cp|csplit|cut|date|dd|df|dir|dircolors|dirname|du|env|expand|expr|factor|false|fmt|fold|head|hostid|id|install|join|link|ln|logname|ls|md5sum|mkdir|mkfifo|mknod|mktemp|mv|nice|nl|nohup|nproc|numfmt|od|paste|pathchk|pinky|pr|printenv|printf|ptx|pwd|readlink|realpath|rm|rmdir|runcon|seq|(sha1|sha224|sha256|sha384|sha512)sum|shred|shuf|sleep|sort|split|stat|stdbuf|stty|sum|sync|tac|tail|tee|test|time|timeout|touch|tr|true|truncate|tsort|tty|uname|unexpand|uniq|unlink|users|vdir|wc|who|whoami|yes)\\b" 23 | 24 | # Conditional flags 25 | - statement: "--[a-z-]+" 26 | - statement: "\\ -[a-z]+" 27 | 28 | - identifier: "(?i)\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" 29 | 30 | - constant.string: 31 | start: "\"" 32 | end: "\"" 33 | skip: "\\\\." 34 | rules: 35 | - constant.specialChar: "\\\\." 36 | 37 | - constant.string: 38 | start: "'" 39 | end: "'" 40 | skip: "\\\\." 41 | rules: [] 42 | 43 | - comment: 44 | start: "#" 45 | end: "$" 46 | rules: 47 | - todo: "(TODO|XXX|FIXME):?" 48 | 49 | -------------------------------------------------------------------------------- /syntax_files/tcl.yaml: -------------------------------------------------------------------------------- 1 | filetype: tcl 2 | 3 | detect: 4 | filename: "\\.tcl$" 5 | header: "^#!.*/(env +)?tclsh( |$)" 6 | 7 | rules: 8 | - 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|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" 9 | - statement: "\\b(array anymore|array donesearch|array exists|array get|array names|array nextelement|array set|array size|array startsearch|array statistics|array unset)\\b" 10 | - statement: "\\b(string bytelength|string compare|string equal|string first|string index|string is|string last|string length|string map|string match|string range|string repeat|string replace|string to|string tolower|string totitle|string toupper|string trim|string trimleft|string trimright|string will|string wordend|string wordstart)\\b" 11 | - statement: "\\b(alarm|auto_load_pkg|bsearch|catclose|catgets|catopen|ccollate|cconcat|cequal|chgrp|chmod|chown|chroot|cindex|clength|cmdtrace|commandloop|crange|csubstr|ctoken|ctype|dup|echo|execl|fcntl|flock|fork|fstat|ftruncate|funlock|host_info|id|infox|keyldel|keylget|keylkeys|keylset|kill|lassign|lcontain|lempty|lgets|link|lmatch|loadlibindex|loop|lvarcat|lvarpop|lvarpush|max|min|nice|pipe|profile|random|readdir|replicate|scancontext|scanfile|scanmatch|select|server_accept|server_create|signal|sleep|sync|system|tclx_findinit|tclx_fork|tclx_load_tndxs|tclx_sleep|tclx_system|tclx_wait|times|translit|try_eval|umask|wait)\\b" 12 | - identifier.class: "proc[[:space:]]|(\\{|\\})" 13 | - symbol.operator: "(\\(|\\)|\\;|`|\\\\|\\$|<|>|!|=|&|\\|)" 14 | - constant.number: "\\b[0-9]+(\\.[0-9]+)?\\b" 15 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 16 | - identifier.var: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" 17 | - comment: "(^|;)[[:space:]]*#.*" 18 | - indent-char.whitespace: "[[:space:]]+$" 19 | -------------------------------------------------------------------------------- /syntax_files/zsh.yaml: -------------------------------------------------------------------------------- 1 | filetype: zsh 2 | 3 | detect: 4 | filename: "(\\.zsh$|\\.?(zshenv|zprofile|zshrc|zlogin|zlogout)$)" 5 | header: "^#!.*/(env +)?zsh( |$)" 6 | 7 | rules: 8 | ## Numbers 9 | - constant.number: "\\b[0-9]+\\b" 10 | 11 | ## Conditionals and control flow 12 | - statement: "\\b(always|break|bye|case|continue|disown|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\\b" 13 | 14 | - statement: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" 15 | ## Conditional flags 16 | - special: "-[Ldefgruwx]\\b" 17 | - special: "-(eq|ne|gt|lt|ge|le|s|n|z)\\b" 18 | 19 | ## Bash-inherited 20 | - statement: "\\b((un)?alias|bindkey|builtin|cd|declare|eval|exec|export|jobs|let|popd|pushd|set|source|typeset|umask|unset)\\b" 21 | ## ZSH-specific 22 | - type: "\\b(add-zsh-hook|autoload|chdir|compinit|dirs|(dis|en)able|echotc|emulate|print|prompt(init)?|(un)?setopt|zle|zmodload|zstyle|whence)\\b" 23 | 24 | ## Common linux commands 25 | - statement: "\\b((g|ig)?awk|find|\\w{0,4}grep|kill|killall|\\w{0,4}less|make|pkill|sed|tar)\\b" 26 | 27 | ## Coreutils commands 28 | - statement: "\\b(base64|basename|cat|chcon|chgrp|chmod|chown|chroot|cksum|comm|cp|csplit|cut|date|dd|df|dir|dircolors|dirname|du|echo|env|expand|expr|factor|false|fmt|fold|head|hostid|id|install|join|link|ln|logname|ls|md5sum|mkdir|mkfifo|mknod|mktemp|mv|nice|nl|nohup|nproc|numfmt|od|paste|pathchk|pinky|pr|printenv|printf|ptx|pwd|readlink|realpath|rm|rmdir|runcon|seq|(sha1|sha224|sha256|sha384|sha512)sum|shred|shuf|sleep|sort|split|stat|stdbuf|stty|sum|sync|tac|tail|tee|test|timeout|touch|tr|true|truncate|tsort|tty|uname|unexpand|uniq|unlink|users|vdir|wc|who|whoami|yes)\\b" 29 | 30 | ## Function definition 31 | - identifier: "^\\s+(function\\s+)[0-9A-Z_]+\\s+\\(\\)" # (i) 32 | 33 | ## Variables 34 | - identifier: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" #(i) 35 | 36 | - constant.string: 37 | start: "\"" 38 | end: "\"" 39 | skip: "\\\\." 40 | rules: 41 | - constant.specialChar: "\\\\." 42 | 43 | - constant.string: 44 | start: "'" 45 | end: "'" 46 | rules: [] 47 | 48 | - comment: 49 | start: "#" 50 | end: "$" 51 | rules: [] 52 | 53 | -------------------------------------------------------------------------------- /syntax_files/sql.yaml: -------------------------------------------------------------------------------- 1 | filetype: sql 2 | 3 | detect: 4 | filename: "\\.sql$|sqliterc$" 5 | 6 | rules: 7 | - statement: "(?i)\\b(ALL|ASC|AS|ALTER|AND|ADD|AUTO_INCREMENT)\\b" 8 | - statement: "(?i)\\b(BETWEEN|BINARY|BOTH|BY|BOOLEAN)\\b" 9 | - statement: "(?i)\\b(CHANGE|CHECK|COLUMNS|COLUMN|CROSS|CREATE)\\b" 10 | - statement: "(?i)\\b(DATABASES|DATABASE|DATA|DELAYED|DESCRIBE|DESC|DISTINCT|DELETE|DROP|DEFAULT)\\b" 11 | - statement: "(?i)\\b(ENCLOSED|ESCAPED|EXISTS|EXPLAIN)\\b" 12 | - statement: "(?i)\\b(FIELDS|FIELD|FLUSH|FOR|FOREIGN|FUNCTION|FROM)\\b" 13 | - statement: "(?i)\\b(GROUP|GRANT|HAVING)\\b" 14 | - statement: "(?i)\\b(IGNORE|INDEX|INFILE|INSERT|INNER|INTO|IDENTIFIED|IN|IS|IF)\\b" 15 | - statement: "(?i)\\b(JOIN|KEYS|KILL|KEY)\\b" 16 | - statement: "(?i)\\b(LEADING|LIKE|LIMIT|LINES|LOAD|LOCAL|LOCK|LOW_PRIORITY|LEFT|LANGUAGE)\\b" 17 | - statement: "(?i)\\b(MODIFY|NATURAL|NOT|NULL|NEXTVAL)\\b" 18 | - statement: "(?i)\\b(OPTIMIZE|OPTION|OPTIONALLY|ORDER|OUTFILE|OR|OUTER|ON)\\b" 19 | - statement: "(?i)\\b(PROCEDURE|PROCEDURAL|PRIMARY)\\b" 20 | - statement: "(?i)\\b(READ|REFERENCES|REGEXP|RENAME|REPLACE|RETURN|REVOKE|RLIKE|RIGHT)\\b" 21 | - statement: "(?i)\\b(SHOW|SONAME|STATUS|STRAIGHT_JOIN|SELECT|SETVAL|SET)\\b" 22 | - statement: "(?i)\\b(TABLES|TERMINATED|TO|TRAILING|TRUNCATE|TABLE|TEMPORARY|TRIGGER|TRUSTED)\\b" 23 | - statement: "(?i)\\b(UNIQUE|UNLOCK|USE|USING|UPDATE|VALUES|VARIABLES|VIEW)\\b" 24 | - statement: "(?i)\\b(WITH|WRITE|WHERE|ZEROFILL|TYPE|XOR)\\b" 25 | - type: "(?i)\\b(VARCHAR|TINYINT|TEXT|DATE|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT|FLOAT|DOUBLE|DECIMAL|DATETIME|TIMESTAMP|TIME|YEAR|UNSIGNED|CHAR|TINYBLOB|TINYTEXT|BLOB|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT|ENUM|BOOL|BINARY|VARBINARY)\\b" 26 | - preproc: "(?i)\\.\\b(databases|dump|echo|exit|explain|header(s)?|help)\\b" 27 | - preproc: "(?i)\\.\\b(import|indices|mode|nullvalue|output|prompt|quit|read)\\b" 28 | - preproc: "(?i)\\.\\b(schema|separator|show|tables|timeout|width)\\b" 29 | - constant.bool: "\\b(ON|OFF)\\b" 30 | - constant.number: "\\b([0-9]+)\\b" 31 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 32 | - constant.string: "`(\\\\.|[^\\\\`])*`" 33 | - comment: "\\-\\-.*$" 34 | - indent-char.whitespace: "[[:space:]]+$" 35 | - indent-char: " + +| + +" 36 | -------------------------------------------------------------------------------- /syntax_files/gentoo-ebuild.yaml: -------------------------------------------------------------------------------- 1 | filetype: ebuild 2 | 3 | detect: 4 | filename: "\\.e(build|class)$" 5 | 6 | rules: 7 | # All the standard portage functions 8 | - identifier: "^src_(unpack|compile|install|test)|^pkg_(config|nofetch|setup|(pre|post)(inst|rm))" 9 | # Highlight bash related syntax 10 | - statement: "\\b(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while|continue|break)\\b" 11 | - statement: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" 12 | - statement: "-(e|d|f|r|g|u|w|x|L)\\b" 13 | - statement: "-(eq|ne|gt|lt|ge|le|s|n|z)\\b" 14 | # Highlight variables ... official portage ones in red, all others in bright red 15 | - preproc: "\\$\\{?[a-zA-Z_0-9]+\\}?" 16 | - special: "\\b(ARCH|HOMEPAGE|DESCRIPTION|IUSE|SRC_URI|LICENSE|SLOT|KEYWORDS|FILESDIR|WORKDIR|(P|R)?DEPEND|PROVIDE|DISTDIR|RESTRICT|USERLAND)\\b" 17 | - special: "\\b(S|D|T|PV|PF|P|PN|A)\\b|\\bC(XX)?FLAGS\\b|\\bLDFLAGS\\b|\\bC(HOST|TARGET|BUILD)\\b" 18 | # Highlight portage commands 19 | - identifier: "\\buse(_(with|enable))?\\b [!a-zA-Z0-9_+ -]*|inherit.*" 20 | - statement: "\\be(begin|end|conf|install|make|warn|infon?|error|log|patch|new(group|user))\\b" 21 | - statement: "\\bdie\\b|\\buse(_(with|enable))?\\b|\\binherit\\b|\\bhas\\b|\\b(has|best)_version\\b|\\bunpack\\b" 22 | - statement: "\\b(do|new)(ins|s?bin|doc|lib(\\.so|\\.a)|man|info|exe|initd|confd|envd|pam|menu|icon)\\b" 23 | - statement: "\\bdo(python|sed|dir|hard|sym|html|jar|mo)\\b|\\bkeepdir\\b" 24 | - statement: "prepall(docs|info|man|strip)|prep(info|lib|lib\\.(so|a)|man|strip)" 25 | - statement: "\\b(doc|ins|exe)into\\b|\\bf(owners|perms)\\b|\\b(exe|ins|dir)opts\\b" 26 | # Highlight common commands used in ebuilds 27 | - type: "\\bmake\\b|\\b(cat|cd|chmod|chown|cp|echo|env|export|grep|let|ln|mkdir|mv|rm|sed|set|tar|touch|unset)\\b" 28 | 29 | - constant.string: 30 | start: "\"" 31 | end: "\"" 32 | skip: "\\\\." 33 | rules: 34 | - constant.specialChar: "\\\\." 35 | 36 | - constant.string: 37 | start: "'" 38 | end: "'" 39 | skip: "\\\\." 40 | rules: 41 | - constant.specialChar: "\\\\." 42 | 43 | - comment: 44 | start: "#" 45 | end: "$" 46 | rules: 47 | - todo: "(TODO|XXX|FIXME):?" 48 | 49 | -------------------------------------------------------------------------------- /syntax_files/nim.yaml: -------------------------------------------------------------------------------- 1 | filetype: nim 2 | 3 | detect: 4 | filename: "\\.nim$" 5 | 6 | rules: 7 | - preproc: "[\\{\\|]\\b(atom|lit|sym|ident|call|lvalue|sideeffect|nosideeffect|param|genericparam|module|type|let|var|const|result|proc|method|iterator|converter|macro|template|field|enumfield|forvar|label|nk[a-zA-Z]+|alias|noalias)\\b[\\}\\|]" 8 | - statement: "\\b(addr|and|as|asm|atomic|bind|block|break|case|cast|concept|const|continue|converter|defer|discard|distinct|div|do|elif|else|end|enum|except|export|finally|for|from|func|generic|if|import|in|include|interface|is|isnot|iterator|let|macro|method|mixin|mod|nil|not|notin|object|of|or|out|proc|ptr|raise|ref|return|shl|shr|static|template|try|tuple|type|using|var|when|while|with|without|xor|yield)\\b" 9 | - statement: "\\b(deprecated|noSideEffect|constructor|destructor|override|procvar|compileTime|noReturn|acyclic|final|shallow|pure|asmNoStackFrame|error|fatal|warning|hint|line|linearScanEnd|computedGoto|unroll|immediate|checks|boundsChecks|overflowChecks|nilChecks|assertations|warnings|hints|optimization|patterns|callconv|push|pop|global|pragma|experimental|bitsize|volatile|noDecl|header|incompleteStruct|compile|link|passC|passL|emit|importc|importcpp|importobjc|codegenDecl|injectStmt|intdefine|strdefine|varargs|exportc|extern|bycopy|byref|union|packed|unchecked|dynlib|cdecl|thread|gcsafe|threadvar|guard|locks|compileTime)\\b" 10 | - symbol.operator: "[=\\+\\-\\*/<>@\\$~&%\\|!\\?\\^\\.:\\\\]+" 11 | - special: "\\{\\.|\\.\\}|\\[\\.|\\.\\]|\\(\\.|\\.\\)|;|,|`" 12 | - statement: "\\.\\." 13 | - type: "\\b(int|cint|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float|float32|float64|bool|char|enum|string|cstring|array|openarray|seq|varargs|tuple|object|set|void|auto|cshort|range|nil|T|untyped|typedesc)\\b" 14 | - type: "'[iI](8|16|32|64)?\\b|'[uU](8|16|32|64)?\\b|'[fF](32|64|128)?\\b|'[dD]\\b" 15 | - constant.number: "\\b[0-9]+\\b" 16 | - constant.number: "\\b0[xX][0-9A-Fa-f][0-9_A-Fa-f]+\\b" 17 | - constant.number: "\\b0[ocC][0-7][0-7_]+\\b" 18 | - constant.number: "\\b0[bB][01][01_]+\\b" 19 | - constant.number: "\\b[0-9_]((\\.?)[0-9_]+)?[eE][+\\-][0-9][0-9_]+\\b" 20 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 21 | - comment: "[[:space:]]*#.*$" 22 | - comment: 23 | start: "\\#\\[" 24 | end: "\\]\\#" 25 | rules: [] 26 | 27 | - todo: "(TODO|FIXME|XXX):?" 28 | -------------------------------------------------------------------------------- /syntax_files/gdscript.yaml: -------------------------------------------------------------------------------- 1 | filetype: gdscript 2 | 3 | detect: 4 | filename: "\\.gd$" 5 | 6 | rules: 7 | # built-in objects 8 | - constant: "\\b(null|self|true|false)\\b" 9 | # built-in attributes 10 | # color constant "\\b()\\b" 11 | # built-in functions 12 | - identifier: "\\b(abs|acos|asin|atan|atan2|ceil|clamp|convert|cos|cosh|db2linear|decimals|deg2rad|ease|exp|float|floor|fmod|fposmod|hash|int|isinf|isnan|lerp|linear2db|load|log|max|min|nearest_po2|pow|preload|print|printerr|printraw|prints|printt|rad2deg|rand_range|rand_seed|randomize|randi|randf|range|round|seed|sin|slerp|sqrt|str|str2var|tan|typeof|var2str|weakref)\\b" 13 | # special method names 14 | - identifier: "\\b(AnimationPlayer|AnimationTreePlayer|Button|Control|HTTPClient|HTTPRequest|Input|InputEvent|MainLoop|Node|Node2D|SceneTree|Spatial|SteamPeer|PacketPeer|PacketPeerUDP|Timer|Tween)\\b" 15 | # types 16 | - type: "\\b(Vector2|Vector3)\\b" 17 | # definitions 18 | - identifier: "func [a-zA-Z_0-9]+" 19 | # keywords 20 | - statement: "\\b(and|as|assert|break|breakpoint|class|const|continue|elif|else|export|extends|for|func|if|in|map|not|onready|or|pass|return|signal|var|while|yield)\\b" 21 | 22 | # decorators 23 | - special: "@.*[(]" 24 | 25 | # operators 26 | - statement: "[.:;,+*|=!\\%@]|<|>|/|-|&" 27 | 28 | # parentheses 29 | - statement: "[(){}]|\\[|\\]" 30 | 31 | # numbers 32 | - constant: "\\b[0-9]+\\b" 33 | - constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b|'.'" 34 | 35 | - comment: 36 | start: "\"\"\"" 37 | end: "\"\"\"" 38 | rules: 39 | - todo: "(TODO|XXX|FIXME):?" 40 | 41 | - comment: 42 | start: "'''" 43 | end: "'''" 44 | rules: 45 | - todo: "(TODO|XXX|FIXME):?" 46 | 47 | - constant.string: 48 | start: "\"" 49 | end: "\"" 50 | skip: "\\\\." 51 | rules: 52 | - constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" 53 | 54 | - constant.string: 55 | start: "'" 56 | end: "'" 57 | skip: "\\\\." 58 | rules: 59 | - constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" 60 | 61 | - constant.string: 62 | start: "`" 63 | end: "`" 64 | rules: [] 65 | 66 | - comment: 67 | start: "#" 68 | end: "$" 69 | rules: 70 | - todo: "(TODO|XXX|FIXME):?" 71 | 72 | -------------------------------------------------------------------------------- /syntax_files/vhdl.yaml: -------------------------------------------------------------------------------- 1 | filetype: vhdl 2 | 3 | detect: 4 | filename: "\\.vhdl?$" 5 | 6 | rules: 7 | - type: "(i)\\b(string|integer|natural|positive|(un)?signed|std_u?logic(_vector)?|bit(_vector)?|boolean|u?x01z?|array|range)\\b" 8 | - identifier: "(?i)library[[:space:]]+[a-zA-Z_0-9]+" 9 | - identifier: "(?i)use[[:space:]]+[a-zA-Z_0-9\\.]+" 10 | - identifier: "(?i)component[[:space:]]+[a-zA-Z_0-9]+" 11 | - identifier: "(?i)(architecture|configuration)[[:space:]]+[a-zA-Z_0-9]+[[:space:]]+of[[:space:]]+[a-zA-Z_0-9]+" 12 | - identifier: "(?i)(entity|package)[[:space:]]+[a-zA-Z_0-9]+[[:space:]]+is" 13 | - identifier: "(?i)end[[:space:]]+((architecture|entity|component|process|package|generate)[[:space:]]+)?[a-zA-Z_0-9]+" 14 | - statement: "(?i)\\b(abs|access|after|alias|all|and|architecture|assert|attribute)\\b" 15 | - statement: "(?i)\\b(begin|block|body|buffer|bus|case|component|configuration|constant)\\b" 16 | - statement: "(?i)\\b(disconnect|downto|else|elsif|end|entity|exit)\\b" 17 | - statement: "(?i)\\b(file|for|function|generate|generic|guarded)\\b" 18 | - statement: "(?i)\\b(if|impure|in|inertial|inout|is)\\b" 19 | - statement: "(?i)\\b(label|library|linkage|literal|loop|map|mod)\\b" 20 | - statement: "(?i)\\b(nand|new|next|nor|not|null|of|on|open|or|others|out)\\b" 21 | - statement: "(?i)\\b(package|port|postponed|procedure|process|pure)\\b" 22 | - statement: "(?i)\\b(range|record|register|reject|rem|report|return|rol|ror)\\b" 23 | - statement: "(?i)\\b(select|severity|shared|signal|sla|sll|sra|srl|subtype)\\b" 24 | - statement: "(?i)\\b(then|to|transport|type|unaffected|units|until|use)\\b" 25 | - statement: "(?i)\\b(variable|wait|when|while|with|xnor|xor)\\b" 26 | - statement: "(?i)'(base|left|right|high|low|pos|val|succ|pred|leftof|rightof|image|(last_)?value)" 27 | - statement: "(?i)'((reverse_)?range|length|ascending|event|stable)" 28 | - statement: "(?i)'(simple|path|instance)_name" 29 | - statement: "(?i)\\b(std_match|(rising|falling)_edge|is_x)\\b" 30 | - statement: "(?i)\\bto_(unsigned|signed|integer|u?x01z?|stdu?logic(vector)?)\\b" 31 | - symbol.operator: "(\\+|-|\\*|/|&|<|>|=|\\.|:)" 32 | - constant.number: "(?i)'([0-1]|u|x|z|w|l|h|-)'|[box]?\"([0-1a-fA-F]|u|x|z|w|l|h|-)+\"" 33 | - constant.number: "(?i)\\b[0-9\\._]+(e[\\-]?[0-9]+)?( ?[fpnum]?s)?\\b" 34 | - constant.bool: "(?i)\\b(true|false)\\b" 35 | - constant: "(?i)\\b(note|warning|error|failure)\\b" 36 | - constant.string: "\"[^\"]*\"" 37 | - comment: "--.*" 38 | -------------------------------------------------------------------------------- /syntax_files/erb.yaml: -------------------------------------------------------------------------------- 1 | filetype: erb 2 | 3 | detect: 4 | filename: "\\.erb$|\\.rhtml$" 5 | 6 | rules: 7 | - error: "<[^!].*?>" 8 | - symbol.tag: "(?i)<[/]?(a(bbr|cronym|ddress|pplet|rea|rticle|side|udio)?|b(ase(font)?|d(i|o)|ig|lockquote|r)?|ca(nvas|ption)|center|cite|co(de|l|lgroup)|d(ata(list)?|d|el|etails|fn|ialog|ir|l|t)|em(bed)?|fieldset|fig(caption|ure)|font|form|(i)?frame|frameset|h[1-6]|hr|i|img|in(put|s)|kbd|keygen|label|legend|li(nk)?|ma(in|p|rk)|menu(item)?|met(a|er)|nav|no(frames|script)|o(l|pt(group|ion)|utput)|p(aram|icture|re|rogress)?|q|r(p|t|uby)|s(trike)?|samp|se(ction|lect)|small|source|span|strong|su(b|p|mmary)|textarea|time|track|u(l)?|var|video|wbr)( .*|>)*?>" 9 | - symbol.tag.extended: "(?i)<[/]?(body|div|html|head(er)?|footer|title|table|t(body|d|h(ead)?|r|foot))( .*|>)*?>" 10 | - preproc: "(?i)<[/]?(script|style)( .*|>)*?>" 11 | - special: "&[^;[[:space:]]]*;" 12 | - symbol: "[:=]" 13 | - identifier: "(alt|bgcolor|height|href|id|label|longdesc|name|onclick|onfocus|onload|onmouseover|size|span|src|style|target|type|value|width)=" 14 | - constant.string: "\"[^\"]*\"" 15 | - constant.number: "(?i)#[0-9A-F]{6,6}" 16 | - constant.string.url: "(ftp(s)?|http(s)?|git|chrome)://[^ ]+" 17 | - comment: "" 18 | - preproc: "" 19 | - default: 20 | start: "<%" 21 | end: "%>" 22 | rules: [] 23 | 24 | - preproc: "<%|%>" 25 | - red: "&[^;[[:space:]]]*;" 26 | - statement: "\\b(BEGIN|END|alias|and|begin|break|case|class|def|defined\\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\\b" 27 | - identifier.var: "(\\$|@|@@)?\\b[A-Z]+[0-9A-Z_a-z]*" 28 | - magenta: "(?i)([ ]|^):[0-9A-Z_]+\\b" 29 | - identifier.macro: "\\b(__FILE__|__LINE__)\\b" 30 | - brightmagenta: "!/([^/]|(\\\\/))*/[iomx]*|%r\\{([^}]|(\\\\}))*\\}[iomx]*" 31 | - brightblue: "`[^`]*`|%x\\{[^}]*\\}" 32 | - constant.string: "\"([^\"]|(\\\\\"))*\"|%[QW]?\\{[^}]*\\}|%[QW]?\\([^)]*\\)|%[QW]?<[^>]*>|%[QW]?\\[[^]]*\\]|%[QW]?\\$[^$]*\\$|%[QW]?\\^[^^]*\\^|%[QW]?![^!]*!" 33 | - brightgreen: "#\\{[^}]*\\}" 34 | - green: "'([^']|(\\\\'))*'|%[qw]\\{[^}]*\\}|%[qw]\\([^)]*\\)|%[qw]<[^>]*>|%[qw]\\[[^]]*\\]|%[qw]\\$[^$]*\\$|%[qw]\\^[^^]*\\^|%[qw]![^!]*!" 35 | - comment: "#[^{].*$|#$" 36 | - comment.bright: "##[^{].*$|##$" 37 | - identifier.macro: 38 | start: "<<-?'?EOT'?" 39 | end: "^EOT" 40 | rules: [] 41 | 42 | - todo: "(XXX|TODO|FIXME|\\?\\?\\?)" 43 | -------------------------------------------------------------------------------- /syntax_files/objc.yaml: -------------------------------------------------------------------------------- 1 | filetype: objective-c 2 | 3 | detect: 4 | filename: "\\.(m|mm|h)$" 5 | 6 | rules: 7 | - type: "\\b(float|double|CGFloat|id|bool|BOOL|Boolean|char|int|short|long|sizeof|enum|void|static|const|struct|union|typedef|extern|(un)?signed|inline|Class|SEL|IMP|NS(U)?Integer)\\b" 8 | - type: "\\b((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\\b" 9 | - type: "\\b[A-Z][A-Z][[:alnum:]]*\\b" 10 | - type: "\\b[A-Za-z0-9_]*_t\\b" 11 | - type: "\\bdispatch_[a-zA-Z0-9_]*_t\\b" 12 | 13 | - statement: "(__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__|__unused|_Nonnull|_Nullable|__block|__builtin.*)" 14 | - statement: "\\b(class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)\\b" 15 | - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" 16 | - statement: "\\b(try|throw|catch|operator|new|delete)\\b" 17 | - statement: "\\b(goto|continue|break|return)\\b" 18 | - statement: "\\b(nonatomic|atomic|readonly|readwrite|strong|weak|assign)\\b" 19 | - statement: "@(encode|end|interface|implementation|class|selector|protocol|synchronized|try|catch|finally|property|optional|required|import|autoreleasepool)" 20 | 21 | - preproc: "^[[:space:]]*#[[:space:]]*(define|include|import|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma).*$" 22 | - preproc: "__[A-Z0-9_]*__" 23 | 24 | - special: "^[[:space:]]*[#|@][[:space:]]*(import|include)[[:space:]]*[\"|<].*\\/?[>|\"][[:space:]]*$" 25 | 26 | - statement: "([.:;,+*|=!\\%\\[\\]]|<|>|/|-|&)" 27 | 28 | - constant.number: "(\\b(-?)?[0-9]+\\b|\\b\\[0-9]+\\.[0-9]+\\b|\\b0x[0-9A-F]+\\b)" 29 | - constant: "(@\\[(\\\\.|[^\\]])*\\]|@\\{(\\\\.|[^\\}])*\\}|@\\((\\\\.|[^\\)])*\\))" 30 | - constant: "\\b<(\\\\.[^\\>])*\\>\\b" 31 | - constant: "\\b(nil|NULL|YES|NO|TRUE|true|FALSE|false|self)\\b" 32 | - constant: "\\bk[[:alnum]]*\\b" 33 | - constant.string: "'.'" 34 | 35 | - constant.string: 36 | start: "@\"" 37 | end: "\"" 38 | skip: "\\\\." 39 | rules: 40 | - constant.specialChar: "\\\\." 41 | 42 | - constant.string: 43 | start: "\"" 44 | end: "\"" 45 | skip: "\\\\." 46 | rules: 47 | - constant.specialChar: "\\\\." 48 | 49 | - comment: 50 | start: "//" 51 | end: "$" 52 | rules: 53 | - todo: "(TODO|XXX|FIXME):?" 54 | 55 | - comment: 56 | start: "/\\*" 57 | end: "\\*/" 58 | rules: 59 | - todo: "(TODO|XXX|FIXME):?" 60 | 61 | -------------------------------------------------------------------------------- /examples/syncat.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | "strings" 9 | 10 | "github.com/fatih/color" 11 | "github.com/zyedidia/highlight" 12 | ) 13 | 14 | func main() { 15 | if len(os.Args) <= 1 { 16 | fmt.Println("No input file") 17 | return 18 | } 19 | 20 | var defs []*highlight.Def 21 | gopath := os.Getenv("GOPATH") 22 | files, _ := ioutil.ReadDir(gopath + "/src/github.com/zyedidia/highlight/syntax_files") 23 | 24 | for _, f := range files { 25 | if strings.HasSuffix(f.Name(), ".yaml") { 26 | input, _ := ioutil.ReadFile(gopath + "/src/github.com/zyedidia/highlight/syntax_files/" + f.Name()) 27 | d, err := highlight.ParseDef(input) 28 | if err != nil { 29 | fmt.Println(err) 30 | continue 31 | } 32 | defs = append(defs, d) 33 | } 34 | } 35 | 36 | highlight.ResolveIncludes(defs) 37 | 38 | fileSrc, _ := ioutil.ReadFile(os.Args[1]) 39 | def := highlight.DetectFiletype(defs, os.Args[1], bytes.Split(fileSrc, []byte("\n"))[0]) 40 | 41 | if def == nil { 42 | fmt.Println(string(fileSrc)) 43 | return 44 | } 45 | 46 | h := highlight.NewHighlighter(def) 47 | 48 | matches := h.HighlightString(string(fileSrc)) 49 | 50 | lines := strings.Split(string(fileSrc), "\n") 51 | for lineN, l := range lines { 52 | colN := 0 53 | for _, c := range l { 54 | if group, ok := matches[lineN][colN]; ok { 55 | // There are more possible groups available than just these ones 56 | if group == highlight.Groups["statement"] { 57 | color.Set(color.FgGreen) 58 | } else if group == highlight.Groups["identifier"] { 59 | color.Set(color.FgBlue) 60 | } else if group == highlight.Groups["preproc"] { 61 | color.Set(color.FgHiRed) 62 | } else if group == highlight.Groups["special"] { 63 | color.Set(color.FgRed) 64 | } else if group == highlight.Groups["constant.string"] { 65 | color.Set(color.FgCyan) 66 | } else if group == highlight.Groups["constant"] { 67 | color.Set(color.FgCyan) 68 | } else if group == highlight.Groups["constant.specialChar"] { 69 | color.Set(color.FgHiMagenta) 70 | } else if group == highlight.Groups["type"] { 71 | color.Set(color.FgYellow) 72 | } else if group == highlight.Groups["constant.number"] { 73 | color.Set(color.FgCyan) 74 | } else if group == highlight.Groups["comment"] { 75 | color.Set(color.FgHiGreen) 76 | } else { 77 | color.Unset() 78 | } 79 | } 80 | fmt.Print(string(c)) 81 | colN++ 82 | } 83 | if group, ok := matches[lineN][colN]; ok { 84 | if group == highlight.Groups["default"] || group == highlight.Groups[""] { 85 | color.Unset() 86 | } 87 | } 88 | 89 | fmt.Print("\n") 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /syntax_files/python3.yaml: -------------------------------------------------------------------------------- 1 | filename: python3 2 | 3 | detect: 4 | filename: "\\.py3$" 5 | header: "^#!.*/(env +)?python3$" 6 | 7 | rules: 8 | # built-in objects 9 | - constant: "\\b(None|self|True|False)\\b" 10 | # built-in attributes 11 | - constant: "\\b(__bases__|__builtin__|__class__|__debug__|__dict__|__doc__|__file__|__members__|__methods__|__name__|__self__)\\b" 12 | # built-in functions 13 | - identifier: "\\b(abs|all|any|ascii|bin|callable|chr|compile|delattr|dir|divmod|eval|exec|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|max|min|next|oct|open|ord|pow|print|repr|round|setattr|sorted|sum|vars|__import__)\\b" 14 | # special method names 15 | - identifier: "\\b(__abs__|__add__|__and__|__call__|__cmp__|__coerce__|__complex__|__concat__|__contains__|__del__|__delattr__|__delitem__|__delslice__|__div__|__divmod__|__float__|__getattr__|__getitem__|__getslice__|__hash__|__hex__|__init__|__int__|__inv__|__invert__|__len__|__dict__|__long__|__lshift__|__mod__|__mul__|__neg__|__next__|__nonzero__|__oct__|__or__|__pos__|__pow__|__radd__|__rand__|__rcmp__|__rdiv__|__rdivmod__|__repeat__|__repr__|__rlshift__|__rmod__|__rmul__|__ror__|__rpow__|__rrshift__|__rshift__|__rsub__|__rxor__|__setattr__|__setitem__|__setslice__|__str__|__sub__|__xor__)\\b" 16 | # types 17 | - type: "\\b(bool|bytearray|bytes|classmethod|complex|dict|enumerate|filter|float|frozenset|int|list|map|memoryview|object|property|range|reversed|set|slice|staticmethod|str|super|tuple|type|zip)\\b" 18 | # definitions 19 | - identifier: "def [a-zA-Z_0-9]+" 20 | # keywords 21 | - statement: "\\b(and|as|assert|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\\b" 22 | # decorators 23 | - brightgreen: "@.*[(]" 24 | # operators 25 | - statement: "([.:;,+*|=!\\%@]|<|>|/|-|&)" 26 | # parentheses 27 | - statement: "([(){}]|\\[|\\])" 28 | # numbers 29 | - constant.number: "\\b[0-9]+\\b" 30 | 31 | - comment: 32 | start: "\"\"\"" 33 | end: "\"\"\"" 34 | rules: [] 35 | 36 | - comment: 37 | start: "'''" 38 | end: "'''" 39 | rules: [] 40 | 41 | - constant.string: 42 | start: "\"" 43 | end: "\"" 44 | skip: "\\\\." 45 | rules: 46 | - constant.specialChar: "\\\\." 47 | 48 | - constant.string: 49 | start: "'" 50 | end: "'" 51 | skip: "\\\\." 52 | rules: 53 | - constant.specialChar: "\\\\." 54 | 55 | - comment: 56 | start: "#" 57 | end: "$" 58 | rules: [] 59 | 60 | -------------------------------------------------------------------------------- /syntax_files/python2.yaml: -------------------------------------------------------------------------------- 1 | filetype: python 2 | 3 | detect: 4 | filename: "\\.py$" 5 | header: "^#!.*/(env +)?python( |$)" 6 | 7 | rules: 8 | 9 | # built-in objects 10 | - constant: "\\b(None|self|True|False)\\b" 11 | # built-in attributes 12 | - constant: "\\b(__bases__|__builtin__|__class__|__debug__|__dict__|__doc__|__file__|__members__|__methods__|__name__|__self__)\\b" 13 | # built-in functions 14 | - identifier: "\\b(abs|apply|callable|chr|cmp|compile|delattr|dir|divmod|eval|exec|execfile|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|intern|isinstance|issubclass|len|locals|max|min|next|oct|open|ord|pow|range|raw_input|reduce|reload|repr|round|setattr|unichr|vars|zip|__import__)\\b" 15 | # special method names 16 | - identifier: "\\b(__abs__|__add__|__and__|__call__|__cmp__|__coerce__|__complex__|__concat__|__contains__|__del__|__delattr__|__delitem__|__dict__|__delslice__|__div__|__divmod__|__float__|__getattr__|__getitem__|__getslice__|__hash__|__hex__|__init__|__int__|__inv__|__invert__|__len__|__long__|__lshift__|__mod__|__mul__|__neg__|__nonzero__|__oct__|__or__|__pos__|__pow__|__radd__|__rand__|__rcmp__|__rdiv__|__rdivmod__|__repeat__|__repr__|__rlshift__|__rmod__|__rmul__|__ror__|__rpow__|__rrshift__|__rshift__|__rsub__|__rxor__|__setattr__|__setitem__|__setslice__|__str__|__sub__|__xor__)\\b" 17 | # types 18 | - type: "\\b(basestring|bool|buffer|bytearray|bytes|classmethod|complex|dict|enumerate|file|float|frozenset|int|list|long|map|memoryview|object|property|reversed|set|slice|staticmethod|str|super|tuple|type|unicode|xrange)\\b" 19 | # definitions 20 | - identifier: "def [a-zA-Z_0-9]+" 21 | # keywords 22 | - statement: "\\b(and|as|assert|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield)\\b" 23 | # decorators 24 | - brightgreen: "@.*[(]" 25 | # operators 26 | - statement: "([.:;,+*|=!\\%@]|<|>|/|-|&)" 27 | # parentheses 28 | - statement: "([(){}]|\\[|\\])" 29 | # numbers 30 | - constant.number: "\\b[0-9]+\\b" 31 | 32 | - comment: 33 | start: "\"\"\"" 34 | end: "\"\"\"" 35 | rules: [] 36 | 37 | - comment: 38 | start: "'''" 39 | end: "'''" 40 | rules: [] 41 | 42 | - constant.string: 43 | start: "\"" 44 | end: "\"" 45 | skip: "\\\\." 46 | rules: 47 | - constant.specialChar: "\\\\." 48 | 49 | - constant.string: 50 | start: "'" 51 | end: "'" 52 | skip: "\\\\." 53 | rules: 54 | - constant.specialChar: "\\\\." 55 | 56 | - comment: 57 | start: "#" 58 | end: "$" 59 | rules: [] 60 | 61 | -------------------------------------------------------------------------------- /syntax_files/php.yaml: -------------------------------------------------------------------------------- 1 | filetype: php 2 | 3 | detect: 4 | filename: "\\.php[2345s~]?$" 5 | 6 | rules: 7 | - symbol.operator: "<|>" 8 | - error: "<[^!].*?>" 9 | - symbol.tag: "(?i)<[/]?(a(bbr|cronym|ddress|pplet|rea|rticle|side|udio)?|b(ase(font)?|d(i|o)|ig|lockquote|r)?|ca(nvas|ption)|center|cite|co(de|l|lgroup)|d(ata(list)?|d|el|etails|fn|ialog|ir|l|t)|em(bed)?|fieldset|fig(caption|ure)|font|form|(i)?frame|frameset|h[1-6]|hr|i|img|in(put|s)|kbd|keygen|label|legend|li(nk)?|ma(in|p|rk)|menu(item)?|met(a|er)|nav|no(frames|script)|o(l|pt(group|ion)|utput)|p(aram|icture|re|rogress)?|q|r(p|t|uby)|s(trike)?|samp|se(ction|lect)|small|source|span|strong|su(b|p|mmary)|textarea|time|track|u(l)?|var|video|wbr)( .*|>)*?>" 10 | - symbol.tag.extended: "(?i)<[/]?(body|div|html|head(er)?|footer|title|table|t(body|d|h(ead)?|r|foot))( .*|>)*?>" 11 | - preproc: "(?i)<[/]?(script|style)( .*|>)*?>" 12 | - special: "&[^;[[:space:]]]*;" 13 | - symbol: "[:=]" 14 | - identifier: "(alt|bgcolor|height|href|label|longdesc|name|onclick|onfocus|onload|onmouseover|size|span|src|style|target|type|value|width)=" 15 | - constant.string: "\"[^\"]*\"" 16 | - constant.number: "(?i)#[0-9A-F]{6,6}" 17 | - constant.string.url: "(ftp(s)?|http(s)?|git|chrome)://[^ ]+" 18 | - comment: "" 19 | - default: "<\\?(php|=)\" end=\"\\?>" 20 | - identifier.class: "([a-zA-Z0-9_-]+)\\(" 21 | - preproc: "(require|include|require_once|include_once)" 22 | - type: "\\b(var|class|extends|function|echo|case|default|exit|switch|extends|as|define|do|declare|in|trait|interface|[E|e]xception|array|int|string|bool|iterable|void)\\b" 23 | - identifier.class: "[a-zA-Z\\\\]+::" 24 | - identifier: "([A-Z][a-zA-Z0-9_]+)\\s" 25 | - identifier: "([A-Z0-9_]+)[;|\\s|\\)|,]" 26 | - type.keyword: "(global|public|private|protected|static|const)" 27 | - statement: "(implements|abstract|instanceof|if|else(if)?|endif|namespace|use|as|new|throw|catch|try|while|print|(end)?(foreach)?)\\b" 28 | - identifier: "new\\s([a-zA-Z0-9\\\\]+)" 29 | - special: "(break|continue|goto|return)" 30 | - constant.bool: "(true|false|null|TRUE|FALSE|NULL)" 31 | - constant: "[\\s|=|\\s|\\(|/|+|-|\\*|\\[]" 32 | - constant.number: "[0-9]" 33 | - identifier: "(\\$this|parent|self|\\$this->)" 34 | - symbol.operator: "(=>|===|!==|==|!=|&&|\\|\\||::|=|->|\\!)" 35 | - identifier.var: "(\\$[a-zA-Z0-9\\-_]+)" 36 | - symbol.operator: "[\\(|\\)|/|+|\\-|\\*|\\[|.|,|;]" 37 | - constant.string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 38 | - constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]" 39 | - symbol.brackets: "(\\[|\\]|\\{|\\}|[()])" 40 | - comment: "(^|[[:space:]])//.*" 41 | - comment: "(^|[[:space:]])#.*" 42 | - comment: 43 | start: "/\\*" 44 | end: "\\*/" 45 | rules: [] 46 | 47 | - preproc: "<\\?(php|=)?" 48 | - preproc: "\\?>" 49 | - preproc: "" 50 | -------------------------------------------------------------------------------- /syntax_files/fortran.yaml: -------------------------------------------------------------------------------- 1 | filetype: fortran 2 | 3 | detect: 4 | filename: "\\.([Ff]|[Ff]90|[Ff]95|[Ff][Oo][Rr])$" 5 | 6 | rules: 7 | - type: "(?i)\\b(action|advance|all|allocatable|allocated|any|apostrophe)\\b" 8 | - type: "(?i)\\b(append|asis|assign|assignment|associated|character|common)\\b" 9 | - type: "(?i)\\b(complex|data|default|delim|dimension|double precision)\\b" 10 | - type: "(?i)\\b(elemental|epsilon|external|file|fmt|form|format|huge)\\b" 11 | - type: "(?i)\\b(implicit|include|index|inquire|integer|intent|interface)\\b" 12 | - type: "(?i)\\b(intrinsic|iostat|kind|logical|module|none|null|only)\\\\b" 13 | - type: "(?i)\\b(operator|optional|pack|parameter|pointer|position|private)\\b" 14 | - type: "(?i)\\b(program|public|real|recl|recursive|selected_int_kind)\\b" 15 | - type: "(?i)\\b(selected_real_kind|subroutine|status)\\b" 16 | 17 | - constant: "(?i)\\b(abs|achar|adjustl|adjustr|allocate|bit_size|call|char)\\b" 18 | - constant: "(?i)\\b(close|contains|count|cpu_time|cshift|date_and_time)\\b" 19 | - constant: "(?i)\\b(deallocate|digits|dot_product|eor|eoshift|function|iachar)\\b" 20 | - constant: "(?i)\\b(iand|ibclr|ibits|ibset|ichar|ieor|iolength|ior|ishft|ishftc)\\b" 21 | - constant: "(?i)\\b(lbound|len|len_trim|matmul|maxexponent|maxloc|maxval|merge)\\b" 22 | - constant: "(?i)\\b(minexponent|minloc|minval|mvbits|namelist|nearest|nullify)\\b" 23 | - constant: "(?i)\\b(open|pad|present|print|product|pure|quote|radix)\\b" 24 | - constant: "(?i)\\b(random_number|random_seed|range|read|readwrite|replace)\\b" 25 | - constant: "(?i)\\b(reshape|rewind|save|scan|sequence|shape|sign|size|spacing)\\b" 26 | - constant: "(?i)\\b(spread|sum|system_clock|target|transfer|transpose|trim)\\b" 27 | - constant: "(?i)\\b(ubound|unpack|verify|write|tiny|type|use|yes)\\b" 28 | 29 | - statement: "(?i)\\b(.and.|case|do|else|else?if|else?where|end|end?do|end?if)\\b" 30 | - statement: "(?i)\\b(end?select|.eqv.|forall|if|lge|lgt|lle|llt|.neqv.|.not.)\\b" 31 | - statement: "(?i)\\b(.or.|repeat|select case|then|where|while)\\b" 32 | 33 | - special: "(?i)\\b(continue|cycle|exit|go?to|result|return)\\b" 34 | 35 | #Operator Color 36 | - symbol.operator: "[.:;,+*|=!\\%]|/|-|&" 37 | 38 | #Parenthetical Color 39 | - symbol.bracket: "[(){}]|\\[|\\]" 40 | 41 | # Add preprocessor commands. 42 | - preproc: "^[[:space:]]*#[[:space:]]*(define|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)" 43 | 44 | - constant.string: 45 | start: "\"" 46 | end: "\"" 47 | skip: "\\\\." 48 | rules: 49 | - constant.specialChar: "\\\\." 50 | 51 | - constant.string: 52 | start: "'" 53 | end: "'" 54 | skip: "\\\\." 55 | rules: 56 | - constant.specialChar: "\\\\." 57 | 58 | - comment: 59 | start: "!" 60 | end: "$" 61 | rules: 62 | - todo: "(TODO|XXX|FIXME):?" 63 | 64 | -------------------------------------------------------------------------------- /syntax_files/lua.yaml: -------------------------------------------------------------------------------- 1 | filetype: lua 2 | 3 | detect: 4 | filename: "\\.lua$" 5 | 6 | rules: 7 | - statement: "\\b(do|end|while|repeat|until|if|elseif|then|else|for|in|function|local|return)\\b" 8 | - statement: "\\b(not|and|or)\\b" 9 | - statement: "\\b(debug|string|math|table|io|coroutine|os|utf8|bit32)\\b\\." 10 | - statement: "\\b(_ENV|_G|_VERSION|assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|load|loadfile|module|next|pairs|pcall|print|rawequal|rawget|rawlen|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall)\\s*\\(" 11 | - identifier: "io\\.\\b(close|flush|input|lines|open|output|popen|read|tmpfile|type|write)\\b" 12 | - identifier: "math\\.\\b(abs|acos|asin|atan2|atan|ceil|cosh|cos|deg|exp|floor|fmod|frexp|huge|ldexp|log10|log|max|maxinteger|min|mininteger|modf|pi|pow|rad|random|randomseed|sinh|sqrt|tan|tointeger|type|ult)\\b" 13 | - identifier: "os\\.\\b(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)\\b" 14 | - identifier: "package\\.\\b(config|cpath|loaded|loadlib|path|preload|seeall|searchers|searchpath)\\b" 15 | - identifier: "string\\.\\b(byte|char|dump|find|format|gmatch|gsub|len|lower|match|pack|packsize|rep|reverse|sub|unpack|upper)\\b" 16 | - identifier: "table\\.\\b(concat|insert|maxn|move|pack|remove|sort|unpack)\\b" 17 | - identifier: "utf8\\.\\b(char|charpattern|codes|codepoint|len|offset)\\b" 18 | - identifier: "coroutine\\.\\b(create|isyieldable|resume|running|status|wrap|yield)\\b" 19 | - identifier: "debug\\.\\b(debug|getfenv|gethook|getinfo|getlocal|getmetatable|getregistry|getupvalue|getuservalue|setfenv|sethook|setlocal|setmetatable|setupvalue|setuservalue|traceback|upvalueid|upvaluejoin)\\b" 20 | - identifier: "bit32\\.\\b(arshift|band|bnot|bor|btest|bxor|extract|replace|lrotate|lshift|rrotate|rshift)\\b" 21 | - identifier: "\\:\\b(close|flush|lines|read|seek|setvbuf|write)\\b" 22 | - constant: "\\b(false|nil|true)\\b" 23 | - statement: "(\\b(dofile|require|include)|%q|%!|%Q|%r|%x)\\b" 24 | - constant.number: "\\b([0-9]+)\\b" 25 | - symbol: "(\\(|\\)|\\[|\\]|\\{|\\}|\\*\\*|\\*|/|%|\\+|-|\\^|>|>=|<|<=|~=|=|\\.\\.)" 26 | 27 | - constant.string: 28 | start: "\"" 29 | end: "\"" 30 | skip: "\\\\." 31 | rules: 32 | - constant.specialChar: "\\\\." 33 | 34 | - constant.string: 35 | start: "'" 36 | end: "'" 37 | skip: "\\\\." 38 | rules: 39 | - constant.specialChar: "\\\\." 40 | 41 | - constant.string: 42 | start: "\\[\\[" 43 | end: "\\]\\]" 44 | rules: 45 | - constant.specialChar: "\\\\." 46 | 47 | - special: "\\\\[0-7][0-7][0-7]|\\\\x[0-9a-fA-F][0-9a-fA-F]|\\\\[abefnrs]|(\\\\c|\\\\C-|\\\\M-|\\\\M-\\\\C-)." 48 | 49 | - comment: 50 | start: "#" 51 | end: "$" 52 | rules: [] 53 | 54 | - comment: 55 | start: "\\-\\-" 56 | end: "$" 57 | rules: [] 58 | 59 | - comment: 60 | start: "\\-\\-\\[\\[" 61 | end: "\\]\\]" 62 | rules: [] 63 | 64 | -------------------------------------------------------------------------------- /syntax_files/arduino.yaml: -------------------------------------------------------------------------------- 1 | filetype: ino 2 | 3 | detect: 4 | filename: "\\.?ino$" 5 | 6 | rules: 7 | - identifier: "\\b[A-Z_][0-9A-Z_]+\\b" 8 | 9 | ## 10 | - type: "\\b((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\\b" 11 | 12 | ## Constants 13 | - constant: "(?i)\\b(HIGH|LOW|INPUT|OUTPUT)\\b" 14 | 15 | ## Serial Print 16 | - constant: "(?i)\\b(DEC|BIN|HEX|OCT|BYTE)\\b" 17 | 18 | ## PI Constants 19 | - constant: "(?i)\\b(PI|HALF_PI|TWO_PI)\\b" 20 | 21 | ## ShiftOut 22 | - constant: "(?i)\\b(LSBFIRST|MSBFIRST)\\b" 23 | 24 | ## Attach Interrupt 25 | - constant: "(?i)\\b(CHANGE|FALLING|RISING)\\b" 26 | 27 | ## Analog Reference 28 | - constant: "(?i)\\b(DEFAULT|EXTERNAL|INTERNAL|INTERNAL1V1|INTERNAL2V56)\\b" 29 | 30 | ## === FUNCTIONS === ## 31 | 32 | ## Data Types 33 | - type: "\\b(boolean|byte|char|float|int|long|word)\\b" 34 | 35 | ## Control Structions 36 | - statement: "\\b(case|class|default|do|double|else|false|for|if|new|null|private|protected|public|short|signed|static|String|switch|this|throw|try|true|unsigned|void|while)\\b" 37 | - statement: "\\b(goto|continue|break|return)\\b" 38 | 39 | ## Math 40 | - identifier: "\\b(abs|acos|asin|atan|atan2|ceil|constrain|cos|degrees|exp|floor|log|map|max|min|radians|random|randomSeed|round|sin|sq|sqrt|tan)\\b" 41 | 42 | ## Bits & Bytes 43 | - identifier: "\\b(bitRead|bitWrite|bitSet|bitClear|bit|highByte|lowByte)\\b" 44 | 45 | ## Analog I/O 46 | - identifier: "\\b(analogReference|analogRead|analogWrite)\\b" 47 | 48 | ## External Interrupts 49 | - identifier: "\\b(attachInterrupt|detachInterrupt)\\b" 50 | 51 | ## Time 52 | - identifier: "\\b(delay|delayMicroseconds|millis|micros)\\b" 53 | 54 | ## Digital I/O 55 | - identifier: "\\b(pinMode|digitalWrite|digitalRead)\\b" 56 | 57 | ## Interrupts 58 | - identifier: "\\b(interrupts|noInterrupts)\\b" 59 | 60 | ## Advanced I/O 61 | - identifier: "\\b(noTone|pulseIn|shiftIn|shiftOut|tone)\\b" 62 | 63 | ## Serial 64 | - identifier: "\\b(Serial|Serial1|Serial2|Serial3|begin|end|peek|read|print|println|available|flush)\\b" 65 | 66 | ## Structure 67 | - identifier: "\\b(setup|loop)\\b" 68 | 69 | ## 70 | - statement: "^[[:space:]]*#[[:space:]]*(define|include(_next)?|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma)" 71 | 72 | ## GCC builtins 73 | - constant: "(__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__)" 74 | 75 | - constant.string: 76 | start: "\"" 77 | end: "\"" 78 | skip: "\\\\." 79 | rules: 80 | - constant.specialChar: "\\\\." 81 | 82 | - constant.string: 83 | start: "'" 84 | end: "'" 85 | skip: "\\\\." 86 | rules: 87 | - preproc: "..+" 88 | - constant.specialChar: "\\\\." 89 | 90 | - comment: 91 | start: "//" 92 | end: "$" 93 | rules: 94 | - todo: "(TODO|XXX|FIXME):?" 95 | 96 | - comment: 97 | start: "/\\*" 98 | end: "\\*/" 99 | rules: 100 | - todo: "(TODO|XXX|FIXME):?" 101 | 102 | -------------------------------------------------------------------------------- /syntax_files/lilypond.yaml: -------------------------------------------------------------------------------- 1 | filetype: lilypond 2 | 3 | detect: 4 | filename: "\\.ly$|\\.ily$|\\.lly$" 5 | 6 | rules: 7 | - constant.number: "\\d+" 8 | - identifier: "\\b(staff|spacing|signature|routine|notes|handler|corrected|beams|arpeggios|Volta_engraver|Voice|Vertical_align_engraver|Vaticana_ligature_engraver|VaticanaVoice|VaticanaStaff|Tweak_engraver|Tuplet_engraver|Trill_spanner_engraver|Timing_translator|Time_signature_performer|Time_signature_engraver|Tie_performer|Tie_engraver|Text_spanner_engraver|Text_engraver|Tempo_performer|Tab_tie_follow_engraver|Tab_staff_symbol_engraver|Tab_note_heads_engraver|TabVoice|TabStaff|System_start_delimiter_engraver|Stem_engraver|Stanza_number_engraver|Stanza_number_align_engraver|Staff_symbol_engraver|Staff_performer|Staff_collecting_engraver|StaffGroup|Staff|Spanner_break_forbid_engraver|Span_bar_stub_engraver|Span_bar_engraver|Span_arpeggio_engraver|Spacing_engraver|Slur_performer|Slur_engraver|Slash_repeat_engraver|Separating_line_group_engraver|Script_row_engraver|Script_engraver|Script_column_engraver|Score|Rhythmic_column_engraver|RhythmicStaff|Rest_engraver|Rest_collision_engraver|Repeat_tie_engraver|Repeat_acknowledge_engraver|Pure_from_neighbor_engraver|Pitched_trill_engraver|Pitch_squash_engraver|Piano_pedal_performer|Piano_pedal_engraver|Piano_pedal_align_engraver|PianoStaff|Phrasing_slur_engraver|PetrucciVoice|PetrucciStaff|Percent_repeat_engraver|Part_combine_engraver|Parenthesis_engraver|Paper_column_engraver|Output_property_engraver|Ottava_spanner_engraver|OneStaff|NullVoice|Note_spacing_engraver|Note_performer|Note_name_engraver|Note_heads_engraver|Note_head_line_engraver|NoteName\\|NoteHead|New_fingering_engraver|Multi_measure_rest_engraver|Midi_control_function_performer|Metronome_mark_engraver|Mensural_ligature_engraver|MensuralVoice|MensuralStaff|Mark_engraver|Lyrics|Lyric_performer|Lyric_engraver|Ligature_bracket_engraver|Ledger_line_engraver|Laissez_vibrer_engraver|Kievan_ligature_engraver|KievanVoice|KievanStaff|Key_performer|Key_engraver|Keep_alive_together_engraver|Instrument_switch_engraver|Instrument_name_engraver|Hyphen_engraver|Grob_pq_engraver|GregorianTranscriptionVoice|GregorianTranscriptionStaff|GrandStaff|Grace_spacing_engraver|Grace_engraver|Grace_beam_engraver|Grace_auto_beam_engraver|Global|Glissando_engraver|Fretboard_engraver|FretBoards|Forbid_line_break_engraver|Footnote_engraver|Font_size_engraver|Fingering_engraver|Fingering_column_engraver|Figured_bass_position_engraver|Figured_bass_engraver|FiguredBass|Extender_engraver|Episema_engraver|Dynamics|Dynamic_performer|Dynamic_engraver|Dynamic_align_engraver|Drum_notes_engraver|Drum_note_performer|DrumVoice|DrumStaff|Double_percent_repeat_engraver|Dots_engraver|Dot_column_engraver|Devnull|Default_bar_line_engraver|Custos_engraver|Cue_clef_engraver|CueVoice|Control_track_performer|Concurrent_hairpin_engraver|Collision_engraver|Cluster_spanner_engraver|Clef_engraver|Chord_tremolo_engraver|Chord_name_engraver|ChordNames|ChoirStaff|Breathing_sign_engraver|Break_align_engraver|Bend_engraver|Beam_performer|Beam_engraver|Beam_collision_engraver|Bar_number_engraver|Bar_engraver|Axis_group_engraver|Auto_beam_engraver|Arpeggio_engraver|Accidental_engraver|Score)\\b" 9 | - statement: "[-_^]?\\\\[-A-Za-z_]+" 10 | - preproc: "\\b(((gisis|gis|geses|ges|g|fisis|fis|feses|fes|f|eisis|eis|eeses|ees|e|disis|dis|deses|des|d|cisis|cis|ceses|ces|c|bisis|bis|beses|bes|b|aisis|ais|aeses|aes|a)[,']*[?!]?)|s|r|R|q)(128|64|32|16|8|4|2|1|\\\\breve|\\\\longa|\\\\maxima)?([^\\\\\\w]|_|\\b)" 11 | - special: "[(){}<>]|\\[|\\]" 12 | - constant.string: 13 | start: "\"" 14 | end: "\"" 15 | skip: "\\\\." 16 | rules: 17 | - constant.specialChar: "\\\\." 18 | - comment: 19 | start: "%\\{" 20 | end: "%\\}" 21 | rules: [] 22 | - comment: 23 | start: "%" 24 | end: "$" 25 | rules: [] 26 | 27 | -------------------------------------------------------------------------------- /syntax_files/golo.yaml: -------------------------------------------------------------------------------- 1 | filetype: golo 2 | 3 | detect: 4 | filename: "\\.golo$" 5 | 6 | rules: 7 | - type: "\\b(function|fun|)\\b" 8 | - type: "\\b(struct|DynamicObject|union|AdapterFabric|Adapter|DynamicVariable|Observable)\\b" 9 | - type: "\\b(list|set|array|vector|tuple|map)\\b" 10 | - type: "\\b(Ok|Error|Empty|None|Some|Option|Result|Result.ok|Result.fail|Result.error|Result.empty|Optional.empty|Optional.of)\\b" 11 | 12 | - identifier.class: "\\b(augment|pimp)\\b" 13 | - identifier.class: "\\b(interfaces|implements|extends|overrides|maker|newInstance)\\b" 14 | - identifier.class: "\\b(isEmpty|isNone|isPresent|isSome|iterator|flattened|toList|flatMap|`and|orElseGet|`or|toResult|apply|either)\\b" 15 | - identifier.class: "\\b(result|option|trying|raising|nullify|catching)\\b" 16 | - identifier.class: "\\b(promise|setFuture|failedFuture|all|any)\\b" 17 | - identifier.class: "\\b(initialize|initializeWithinThread|start|future|fallbackTo|onSet|onFail|cancel|enqueue)\\b" 18 | - identifier.class: "\\b(println|print|raise|readln|readPassword|secureReadPassword|requireNotNull|require|newTypedArray|range|reversedRange|mapEntry|asInterfaceInstance|asFunctionalInterface|isClosure|fileToText|textToFile|fileExists|currentDir|sleep|uuid|isArray|arrayTypeOf|charValue|intValue|longValue|doubleValue|floatValue|removeByIndex|box)\\b" 19 | - identifier.class: "\\b(likelySupported|reset|bold|underscore|blink|reverse_video|concealed|fg_black|fg_red|fg_green|fg_yellow|fg_blue|fg_magenta|fg_cyan|fg_white|bg_black|bg_red|bg_green|bg_yellow|bg_blue|bg_magenta|bg_cyan|bg_white|cursor_position|cursor_save_position|cursor_restore_position|cursor_up|cursor_down|cursor_forward|cursor_backward|erase_display|erase_line)\\b" 20 | - identifier.class: "\\b(emptyList|cons|lazyList|fromIter|generator|repeat|iterate)\\b" 21 | - identifier.class: "\\b(asLazyList|foldl|foldr|take|takeWhile|drop|dropWhile|subList)\\b" 22 | - identifier.class: "\\b(import)\\b" 23 | - identifier.class: "\\b(module)\\b" 24 | - identifier.class: "\\b(JSON)\\b" 25 | - identifier.class: "\\b(stringify|parse|toJSON|toDynamicObject|updateFromJSON)\\b" 26 | - identifier.class: "\\b(newInstance|define|getKey|getValue|properties|fallback)\\b" 27 | - identifier.class: "\\b(times|upTo|downTo)\\b" 28 | - identifier.class: "\\b(format|toInt|toInteger|toDouble|toFloat|toLong)\\b" 29 | - identifier.class: "\\b(head|tail|isEmpty|reduce|each|count|exists)\\b" 30 | - identifier.class: "\\b(newWithSameType|destruct|append|add|addIfAbsent|prepend|insert|last|unmodifiableView|find|filter|map|join|reverse|reversed|order|ordered|removeAt|include|exclude|remove|delete|has|contains|getOrElse|toArray)\\b" 31 | - identifier.class: "\\b(add|addTo|succ|pred|mul|neg|sub|rsub|div|rdiv|mod|rmod|pow|rpow|str|lt|gt|eq|ne|ge|le|`and|`or|`not|xor|even|odd|contains|isEmpty|`is|`isnt|`oftype|`orIfNull|fst|snd|getitem|setitem|getter|id|const|False|True|Null|curry|uncurry|unary|spreader|varargs|swapArgs|swapCurry|swapCouple|swap|invokeWith|pipe|compose|io|andThen|until|recur|cond)\\b" 32 | - identifier.class: "\\b(toUpperCase|equals|startsWith)\\b" 33 | 34 | - statement: "\\b(if|else|then|when|case|match|otherwise)\\b" 35 | - special: "\\b(with|break|continue|return)\\b" 36 | - error: "\\b(try|catch|finally|throw)\\b" 37 | - identifier: "\\b(super|this|let|var|local)\\b" 38 | - symbol.brackets: "[(){}]|\\[|\\]" 39 | - statement: "\\b(for|while|foreach|in)\\b" 40 | - constant: "\\b(and|in|is|not|or|isnt|orIfNull)\\b" 41 | 42 | - constant.bool: "\\b(true|false)\\b" 43 | - constant: "\\b(null|undefined)\\b" 44 | 45 | - symbol.operator: "[\\-+/*=<>!~%&|^]|:=" 46 | - constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b|'.'" 47 | 48 | - constant.string: 49 | start: "\"" 50 | end: "\"" 51 | skip: "\\\\." 52 | rules: 53 | - constant.specialChar: "\\\\." 54 | 55 | - constant.string: 56 | start: "'" 57 | end: "'" 58 | skip: "\\\\." 59 | rules: 60 | - constant.specialChar: "\\\\." 61 | 62 | - comment: 63 | start: "#" 64 | end: "$" 65 | rules: 66 | - todo: "(TODO|XXX|FIXME):?" 67 | 68 | - comment: 69 | start: "----" 70 | end: "----" 71 | rules: 72 | - todo: "(TODO|XXX|FIXME):?" 73 | 74 | -------------------------------------------------------------------------------- /syntax_files/d.yaml: -------------------------------------------------------------------------------- 1 | filetype: d 2 | 3 | detect: 4 | filename: "\\.(d(i|d)?)$" 5 | 6 | rules: 7 | # Operators and punctuation 8 | - statement: "(\\*|/|%|\\+|-|>>|<<|>>>|&|\\^(\\^)?|\\||~)?=" 9 | - statement: "\\.\\.(\\.)?|!|\\*|&|~|\\(|\\)|\\[|\\]|\\\\|/|\\+|-|%|<|>|\\?|:|;" 10 | # Octal integer literals are deprecated 11 | - error: "(0[0-7_]*)(L[uU]?|[uU]L?)?" 12 | # Decimal integer literals 13 | - constant.number: "([0-9]|[1-9][0-9_]*)(L[uU]?|[uU]L?)?" 14 | # Binary integer literals 15 | - constant: "(0[bB][01_]*)(L[uU]?|[uU]L?)?" 16 | # Decimal float literals 17 | - constant.number: "[0-9][0-9_]*\\.([0-9][0-9_]*)([eE][+-]?([0-9][0-9_]*))?[fFL]?i?" 18 | - constant.number: "[0-9][0-9_]*([eE][+-]?([0-9][0-9_]*))[fFL]?i?" 19 | - constant.number: "[^.]\\.([0-9][0-9_]*)([eE][+-]?([0-9][0-9_]*))?[fFL]?i?" 20 | - constant.number: "[0-9][0-9_]*([fFL]?i|[fF])" 21 | # Hexadecimal integer literals 22 | - constant.number: "(0[xX]([0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F]))(L[uU]?|[uU]L?)?" 23 | # Hexadecimal float literals 24 | - constant.number: "0[xX]([0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F])(\\.[0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F])?[pP][+-]?([0-9][0-9_]*)[fFL]?i?" 25 | - constant.number: "0[xX]\\.([0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F])[pP][+-]?([0-9][0-9_]*)[fFL]?i?" 26 | # Character literals 27 | - constant.string: 28 | start: "'" 29 | end: "'" 30 | rules: 31 | - constant.specialChar: "\\\\." 32 | # Keywords 33 | # a-e 34 | - statement: "\\b(abstract|alias|align|asm|assert|auto|body|break|case|cast|catch|class|const|continue|debug|default|delegate|do|else|enum|export|extern)\\b" 35 | # f-l 36 | - statement: "\\b(false|final|finally|for|foreach|foreach_reverse|function|goto|if|immutable|import|in|inout|interface|invariant|is|lazy)\\b" 37 | # m-r 38 | - statement: "\\b(macro|mixin|module|new|nothrow|null|out|override|package|pragma|private|protected|public|pure|ref|return)\\b" 39 | # s-w 40 | - statement: "\\b(scope|shared|static|struct|super|switch|synchronized|template|this|throw|true|try|typeid|typeof|union|unittest|version|while|with)\\b" 41 | # __ 42 | - statement: "\\b(__FILE__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__gshared|__traits|__vector|__parameters)\\b" 43 | # Deprecated keywords 44 | - error: "\\b(delete|deprecated|typedef|volatile)\\b" 45 | # Primitive types 46 | - type: "\\b(bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|float|idouble|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong|ushort|void|wchar)\\b" 47 | # Globally defined symbols 48 | - type: "\\b(string|wstring|dstring|size_t|ptrdiff_t)\\b" 49 | # Special tokens 50 | - constant: "\\b(__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__)\\b" 51 | # String literals 52 | # DoubleQuotedString 53 | - constant.string: 54 | start: "\"" 55 | end: "\"" 56 | skip: "\\\\." 57 | rules: 58 | - constant.specialChar: "\\\\." 59 | # WysiwygString 60 | - constant.string: 61 | start: "r\"" 62 | end: "\"" 63 | rules: 64 | - constant.specialChar: "\\\\." 65 | - constant.string: 66 | start: "`" 67 | end: "`" 68 | rules: 69 | - constant.specialChar: "\\\\." 70 | # HexString 71 | - constant.string: 72 | start: "x\"" 73 | end: "\"" 74 | rules: 75 | - constant.specialChar: "\\\\." 76 | # DelimitedString 77 | - constant.string: 78 | start: "q\"\\(" 79 | end: "\\)\"" 80 | rules: 81 | - constant.specialChar: "\\\\." 82 | - constant.string: 83 | start: "q\"\\{" 84 | end: "q\"\\}" 85 | rules: 86 | - constant.specialChar: "\\\\." 87 | - constant.string: 88 | start: "q\"\\[" 89 | end: "q\"\\]" 90 | rules: 91 | - constant.specialChar: "\\\\." 92 | - constant.string: 93 | start: "q\"<" 94 | end: "q\">" 95 | rules: 96 | - constant.specialChar: "\\\\." 97 | - constant.string: 98 | start: "q\"[^({[<\"][^\"]*$" 99 | end: "^[^\"]+\"" 100 | rules: 101 | - constant.specialChar: "\\\\." 102 | - constant.string: 103 | start: "q\"([^({[<\"])" 104 | end: "\"" 105 | rules: 106 | - constant.specialChar: "\\\\." 107 | # Comments 108 | - comment: 109 | start: "//" 110 | end: "$" 111 | rules: [] 112 | - comment: 113 | start: "/\\*" 114 | end: "\\*/" 115 | rules: [] 116 | - comment: 117 | start: "/\\+" 118 | end: "\\+/" 119 | rules: [] 120 | 121 | -------------------------------------------------------------------------------- /syntax_files/nginx.yaml: -------------------------------------------------------------------------------- 1 | filetype: nginx 2 | 3 | detect: 4 | filename: "nginx.*\\.conf$|\\.nginx$" 5 | header: "^(server|upstream)[a-z ]*\\{$" 6 | 7 | rules: 8 | - preproc: "\\b(events|server|http|location|upstream)[[:space:]]*\\{" 9 | - statement: "(^|[[:space:]{;])(access_log|add_after_body|add_before_body|add_header|addition_types|aio|alias|allow|ancient_browser|ancient_browser_value|auth_basic|auth_basic_user_file|autoindex|autoindex_exact_size|autoindex_localtime|break|charset|charset_map|charset_types|chunked_transfer_encoding|client_body_buffer_size|client_body_in_file_only|client_body_in_single_buffer|client_body_temp_path|client_body_timeout|client_header_buffer_size|client_header_timeout|client_max_body_size|connection_pool_size|create_full_put_path|daemon|dav_access|dav_methods|default_type|deny|directio|directio_alignment|disable_symlinks|empty_gif|env|error_log|error_page|expires|fastcgi_buffer_size|fastcgi_buffers|fastcgi_busy_buffers_size|fastcgi_cache|fastcgi_cache_bypass|fastcgi_cache_key|fastcgi_cache_lock|fastcgi_cache_lock_timeout|fastcgi_cache_min_uses|fastcgi_cache_path|fastcgi_cache_use_stale|fastcgi_cache_valid|fastcgi_connect_timeout|fastcgi_hide_header|fastcgi_ignore_client_abort|fastcgi_ignore_headers|fastcgi_index|fastcgi_intercept_errors|fastcgi_keep_conn|fastcgi_max_temp_file_size|fastcgi_next_upstream|fastcgi_no_cache|fastcgi_param|fastcgi_pass|fastcgi_pass_header|fastcgi_read_timeout|fastcgi_send_timeout|fastcgi_split_path_info|fastcgi_store|fastcgi_store_access|fastcgi_temp_file_write_size|fastcgi_temp_path|flv|geo|geoip_city|geoip_country|gzip|gzip_buffers|gzip_comp_level|gzip_disable|gzip_http_version|gzip_min_length|gzip_proxied|gzip_static|gzip_types|gzip_vary|if|if_modified_since|ignore_invalid_headers|image_filter|image_filter_buffer|image_filter_jpeg_quality|image_filter_sharpen|image_filter_transparency|include|index|internal|ip_hash|keepalive|keepalive_disable|keepalive_requests|keepalive_timeout|large_client_header_buffers|limit_conn|limit_conn_log_level|limit_conn_zone|limit_except|limit_rate|limit_rate_after|limit_req|limit_req_log_level|limit_req_zone|limit_zone|lingering_close|lingering_time|lingering_timeout|listen|location|log_format|log_not_found|log_subrequest|map|map_hash_bucket_size|map_hash_max_size|master_process|max_ranges|memcached_buffer_size|memcached_connect_timeout|memcached_next_upstream|memcached_pass|memcached_read_timeout|memcached_send_timeout|merge_slashes|min_delete_depth|modern_browser|modern_browser_value|mp4|mp4_buffer_size|mp4_max_buffer_size|msie_padding|msie_refresh|open_file_cache|open_file_cache_errors|open_file_cache_min_uses|open_file_cache_valid|open_log_file_cache|optimize_server_names|override_charset|pcre_jit|perl|perl_modules|perl_require|perl_set|pid|port_in_redirect|postpone_output|proxy_buffer_size|proxy_buffering|proxy_buffers|proxy_busy_buffers_size|proxy_cache|proxy_cache_bypass|proxy_cache_key|proxy_cache_lock|proxy_cache_lock_timeout|proxy_cache_min_uses|proxy_cache_path|proxy_cache_use_stale|proxy_cache_valid|proxy_connect_timeout|proxy_cookie_domain|proxy_cookie_path|proxy_hide_header|proxy_http_version|proxy_ignore_client_abort|proxy_ignore_headers|proxy_intercept_errors|proxy_max_temp_file_size|proxy_next_upstream|proxy_no_cache|proxy_pass|proxy_pass_header|proxy_read_timeout|proxy_redirect|proxy_send_timeout|proxy_set_header|proxy_ssl_session_reuse|proxy_store|proxy_store_access|proxy_temp_file_write_size|proxy_temp_path|random_index|read_ahead|real_ip_header|recursive_error_pages|request_pool_size|reset_timedout_connection|resolver|resolver_timeout|return|rewrite|root|satisfy|satisfy_any|secure_link_secret|send_lowat|send_timeout|sendfile|sendfile_max_chunk|server|server|server_name|server_name_in_redirect|server_names_hash_bucket_size|server_names_hash_max_size|server_tokens|set|set_real_ip_from|source_charset|split_clients|ssi|ssi_silent_errors|ssi_types|ssl|ssl_certificate|ssl_certificate_key|ssl_ciphers|ssl_client_certificate|ssl_crl|ssl_dhparam|ssl_engine|ssl_prefer_server_ciphers|ssl_protocols|ssl_session_cache|ssl_session_timeout|ssl_verify_client|ssl_verify_depth|sub_filter|sub_filter_once|sub_filter_types|tcp_nodelay|tcp_nopush|timer_resolution|try_files|types|types_hash_bucket_size|types_hash_max_size|underscores_in_headers|uninitialized_variable_warn|upstream|user|userid|userid_domain|userid_expires|userid_name|userid_p3p|userid_path|userid_service|valid_referers|variables_hash_bucket_size|variables_hash_max_size|worker_priority|worker_processes|worker_rlimit_core|worker_rlimit_nofile|working_directory|xml_entities|xslt_stylesheet|xslt_types)([[:space:]]|$)" 10 | - constant.bool.true: "\\b(on)\\b" 11 | - constant.bool.false: "\\b(off)\\b" 12 | - identifier: "\\$[A-Za-z][A-Za-z0-9_]*" 13 | - symbol: "[*]" 14 | - constant-string: "\"(\\\\.|[^\"])*\"|'(\\\\.|[^'])*'" 15 | - constant.string: 16 | start: "'$" 17 | end: "';$" 18 | rules: [] 19 | 20 | - comment: "(^|[[:space:]])#([^{].*)?$" 21 | - indent-char.whitespace: "[[:space:]]+$" 22 | - indent-char: " + +| + +" 23 | -------------------------------------------------------------------------------- /syntax_files/systemd.yaml: -------------------------------------------------------------------------------- 1 | filetype: systemd 2 | 3 | detect: 4 | filename: "\\.(service|socket)$" 5 | header: "^\\[Unit\\]$" 6 | 7 | rules: 8 | - 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)=" 9 | - preproc: "^\\.include\\>" 10 | - symbol: "=" 11 | - special: "^\\[(Unit|Install|Service|Socket)\\]" 12 | - identifier.class: "\\$MAINPID" 13 | - constant.bool: "\\b(true|false)\\b" 14 | - comment: "(^|[[:space:]])#([^{].*)?$" 15 | - indent-char.whitespace: "[[:space:]]+$" 16 | - indent-char: " + +| + +" 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Highlight 2 | [![Go Report Card](https://goreportcard.com/badge/github.com/zyedidia/highlight)](https://goreportcard.com/report/github.com/zyedidia/highlight) 3 | [![GoDoc](https://godoc.org/github.com/zyedidia/highlight?status.svg)](http://godoc.org/github.com/zyedidia/highlight) 4 | [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/zyedidia/highlight/blob/master/LICENSE) 5 | 6 | This is a package for syntax highlighting a large number of different languages. To see the list of 7 | languages currently supported, see the [`syntax_files`](./syntax_files) directory. 8 | 9 | Highlight allows you to pass in a string and get back all the information you need to syntax highlight 10 | that string well. 11 | 12 | This project is still a work in progress and more features and documentation will be coming later. 13 | 14 | # Installation 15 | 16 | ``` 17 | go get github.com/zyedidia/highlight 18 | ``` 19 | 20 | # Usage 21 | 22 | Here is how to use this package to highlight a string. We will also be using `github.com/fatih/color` to actually 23 | colorize the output to the console. 24 | 25 | ```go 26 | package main 27 | 28 | import ( 29 | "fmt" 30 | "io/ioutil" 31 | "strings" 32 | 33 | "github.com/fatih/color" 34 | "github.com/zyedidia/highlight" 35 | ) 36 | 37 | func main() { 38 | // Here is the go code we will highlight 39 | inputString := `package main 40 | 41 | import "fmt" 42 | 43 | // A hello world program 44 | func main() { 45 | fmt.Println("Hello world") 46 | }` 47 | 48 | // Load the go syntax file 49 | // Make sure that the syntax_files directory is in the current directory 50 | syntaxFile, _ := ioutil.ReadFile("highlight/syntax_files/go.yaml") 51 | 52 | // Parse it into a `*highlight.Def` 53 | syntaxDef, err := highlight.ParseDef(syntaxFile) 54 | if err != nil { 55 | fmt.Println(err) 56 | return 57 | } 58 | 59 | // Make a new highlighter from the definition 60 | h := highlight.NewHighlighter(syntaxDef) 61 | // Highlight the string 62 | // Matches is an array of maps which point to groups 63 | // matches[lineNum][colNum] will give you the change in group at that line and column number 64 | // Note that there is only a group at a line and column number if the syntax highlighting changed at that position 65 | matches := h.HighlightString(inputString) 66 | 67 | // We split the string into a bunch of lines 68 | // Now we will print the string 69 | lines := strings.Split(inputString, "\n") 70 | for lineN, l := range lines { 71 | for colN, c := range l { 72 | // Check if the group changed at the current position 73 | if group, ok := matches[lineN][colN]; ok { 74 | // Check the group name and set the color accordingly (the colors chosen are arbitrary) 75 | if group == highlight.Groups["statement"] { 76 | color.Set(color.FgGreen) 77 | } else if group == highlight.Groups["preproc"] { 78 | color.Set(color.FgHiRed) 79 | } else if group == highlight.Groups["special"] { 80 | color.Set(color.FgBlue) 81 | } else if group == highlight.Groups["constant.string"] { 82 | color.Set(color.FgCyan) 83 | } else if group == highlight.Groups["constant.specialChar"] { 84 | color.Set(color.FgHiMagenta) 85 | } else if group == highlight.Groups["type"] { 86 | color.Set(color.FgYellow) 87 | } else if group == highlight.Groups["constant.number"] { 88 | color.Set(color.FgCyan) 89 | } else if group == highlight.Groups["comment"] { 90 | color.Set(color.FgHiGreen) 91 | } else { 92 | color.Unset() 93 | } 94 | } 95 | // Print the character 96 | fmt.Print(string(c)) 97 | } 98 | // This is at a newline, but highlighting might have been turned off at the very end of the line so we should check that. 99 | if group, ok := matches[lineN][len(l)]; ok { 100 | if group == highlight.Groups["default"] || group == highlight.Groups[""] { 101 | color.Unset() 102 | } 103 | } 104 | 105 | fmt.Print("\n") 106 | } 107 | } 108 | ``` 109 | 110 | If you would like to automatically detect the filetype of a file based on the filename, and have the appropriate definition returned, 111 | you can use the `DetectFiletype` function: 112 | 113 | ```go 114 | // Name of the file 115 | filename := ... 116 | // The first line of the file (needed to check the filetype by header: e.g. `#!/bin/bash` means shell) 117 | firstLine := ... 118 | 119 | // Parse all the syntax files in an array with type []*highlight.Def 120 | var defs []*highlight.Def 121 | ... 122 | 123 | def := highlight.DetectFiletype(defs, filename, firstLine) 124 | fmt.Println("Filetype is", def.FileType) 125 | ``` 126 | 127 | For a full example, see the [`syncat`](./examples) example which acts like cat but will syntax highlight the output (if highlight recognizes the filetype). 128 | -------------------------------------------------------------------------------- /syntax_files/conky.yaml: -------------------------------------------------------------------------------- 1 | filetype: conky 2 | 3 | detect: 4 | filename: "(\\.*conkyrc.*$|conky.conf)" 5 | 6 | rules: 7 | - type: "\\b(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_height|default_bar_width|default_color|default_gauge_height|default_gauge_width|default_graph_height|default_graph_width|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|http_refresh|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|lua_startup_hook|mail_spool|max_port_monitor_connections|max_text_width|max_user_text|maximum_width|minimum_height|minimum_width|mpd_host|mpd_password|mpd_port|music_player_interval|mysql_host|mysql_port|mysql_user|mysql_password|mysql_db|net_avg_samples|no_buffers|nvidia_display|out_to_console|out_to_http|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|times_in_seconds|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\\b" 8 | 9 | # Configuration item constants 10 | - statement: "\\b(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\\b" 11 | 12 | # Variables 13 | - preproc: "\\b(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|ical|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|irc|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|mysql|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|stock|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_ping|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\\b" 14 | 15 | - identifier.var: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" 16 | - symbol.operator: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" 17 | - constant.macro: "^TEXT$" 18 | -------------------------------------------------------------------------------- /syntax_files/apacheconf.yaml: -------------------------------------------------------------------------------- 1 | filetype: apacheconf 2 | 3 | detect: 4 | filename: "httpd\\.conf|mime\\.types|vhosts\\.d\\\\*|\\.htaccess" 5 | 6 | rules: 7 | - identifier: "(AcceptMutex|AcceptPathInfo|AccessFileName|Action|AddAlt|AddAltByEncoding|AddAltByType|AddCharset|AddDefaultCharset|AddDescription|AddEncoding)" 8 | - identifier: "(AddHandler|AddIcon|AddIconByEncoding|AddIconByType|AddInputFilter|AddLanguage|AddModuleInfo|AddOutputFilter|AddOutputFilterByType|AddType|Alias|AliasMatch)" 9 | - identifier: "(Allow|AllowCONNECT|AllowEncodedSlashes|AllowOverride|Anonymous|Anonymous_Authoritative|Anonymous_LogEmail|Anonymous_MustGiveEmail|Anonymous_NoUserID)" 10 | - identifier: "(Anonymous_VerifyEmail|AssignUserID|AuthAuthoritative|AuthDBMAuthoritative|AuthDBMGroupFile|AuthDBMType|AuthDBMUserFile|AuthDigestAlgorithm)" 11 | - identifier: "(AuthDigestDomain|AuthDigestFile|AuthDigestGroupFile|AuthDigestNcCheck|AuthDigestNonceFormat|AuthDigestNonceLifetime|AuthDigestQop|AuthDigestShmemSize)" 12 | - identifier: "(AuthGroupFile|AuthLDAPAuthoritative|AuthLDAPBindDN|AuthLDAPBindPassword|AuthLDAPCharsetConfig|AuthLDAPCompareDNOnServer|AuthLDAPDereferenceAliases)" 13 | - identifier: "(AuthLDAPEnabled|AuthLDAPFrontPageHack|AuthLDAPGroupAttribute|AuthLDAPGroupAttributeIsDN|AuthLDAPRemoteUserIsDN|AuthLDAPUrl|AuthName|AuthType|AuthUserFile)" 14 | - identifier: "(BrowserMatch|BrowserMatchNoCase|BS2000Account|BufferedLogs|CacheDefaultExpire|CacheDirLength|CacheDirLevels|CacheDisable|CacheEnable|CacheExpiryCheck)" 15 | - identifier: "(CacheFile|CacheForceCompletion|CacheGcClean|CacheGcDaily|CacheGcInterval|CacheGcMemUsage|CacheGcUnused|CacheIgnoreCacheControl|CacheIgnoreHeaders)" 16 | - identifier: "(CacheIgnoreNoLastMod|CacheLastModifiedFactor|CacheMaxExpire|CacheMaxFileSize|CacheMinFileSize|CacheNegotiatedDocs|CacheRoot|CacheSize|CacheTimeMargin)" 17 | - identifier: "(CGIMapExtension|CharsetDefault|CharsetOptions|CharsetSourceEnc|CheckSpelling|ChildPerUserID|ContentDigest|CookieDomain|CookieExpires|CookieLog|CookieName)" 18 | - identifier: "(CookieStyle|CookieTracking|CoreDumpDirectory|CustomLog|Dav|DavDepthInfinity|DavLockDB|DavMinTimeout|DefaultIcon|DefaultLanguage|DefaultType)" 19 | - identifier: "(DeflateBufferSize|DeflateCompressionLevel|DeflateFilterNote|DeflateMemLevel|DeflateWindowSize|Deny|Directory|DirectoryIndex|DirectoryMatch|DirectorySlash)" 20 | - identifier: "(DocumentRoot|DumpIOInput|DumpIOOutput|EnableExceptionHook|EnableMMAP|EnableSendfile|ErrorDocument|ErrorLog|Example|ExpiresActive|ExpiresByType)" 21 | - identifier: "(ExpiresDefault|ExtendedStatus|ExtFilterDefine|ExtFilterOptions|FileETag|Files|FilesMatch|ForceLanguagePriority|ForceType|ForensicLog|Group|Header)" 22 | - identifier: "(HeaderName|HostnameLookups|IdentityCheck|IfDefine|IfModule|IfVersion|ImapBase|ImapDefault|ImapMenu|Include|IndexIgnore|IndexOptions|IndexOrderDefault)" 23 | - identifier: "(ISAPIAppendLogToErrors|ISAPIAppendLogToQuery|ISAPICacheFile|ISAPIFakeAsync|ISAPILogNotSupported|ISAPIReadAheadBuffer|KeepAlive|KeepAliveTimeout)" 24 | - identifier: "(LanguagePriority|LDAPCacheEntries|LDAPCacheTTL|LDAPConnectionTimeout|LDAPOpCacheEntries|LDAPOpCacheTTL|LDAPSharedCacheFile|LDAPSharedCacheSize)" 25 | - identifier: "(LDAPTrustedCA|LDAPTrustedCAType|Limit|LimitExcept|LimitInternalRecursion|LimitRequestBody|LimitRequestFields|LimitRequestFieldSize|LimitRequestLine)" 26 | - identifier: "(LimitXMLRequestBody|Listen|ListenBackLog|LoadFile|LoadModule|Location|LocationMatch|LockFile|LogFormat|LogLevel|MaxClients|MaxKeepAliveRequests)" 27 | - identifier: "(MaxMemFree|MaxRequestsPerChild|MaxRequestsPerThread|MaxSpareServers|MaxSpareThreads|MaxThreads|MaxThreadsPerChild|MCacheMaxObjectCount|MCacheMaxObjectSize)" 28 | - identifier: "(MCacheMaxStreamingBuffer|MCacheMinObjectSize|MCacheRemovalAlgorithm|MCacheSize|MetaDir|MetaFiles|MetaSuffix|MimeMagicFile|MinSpareServers|MinSpareThreads)" 29 | - identifier: "(MMapFile|ModMimeUsePathInfo|MultiviewsMatch|NameVirtualHost|NoProxy|NumServers|NWSSLTrustedCerts|NWSSLUpgradeable|Options|Order|PassEnv|PidFile)" 30 | - identifier: "(ProtocolEcho|Proxy|ProxyBadHeader|ProxyBlock|ProxyDomain|ProxyErrorOverride|ProxyIOBufferSize|ProxyMatch|ProxyMaxForwards|ProxyPass|ProxyPassReverse)" 31 | - identifier: "(ProxyPreserveHost|ProxyReceiveBufferSize|ProxyRemote|ProxyRemoteMatch|ProxyRequests|ProxyTimeout|ProxyVia|ReadmeName|Redirect|RedirectMatch)" 32 | - identifier: "(RedirectPermanent|RedirectTemp|RemoveCharset|RemoveEncoding|RemoveHandler|RemoveInputFilter|RemoveLanguage|RemoveOutputFilter|RemoveType|RequestHeader)" 33 | - identifier: "(Require|RewriteBase|RewriteCond|RewriteEngine|RewriteLock|RewriteLog|RewriteLogLevel|RewriteMap|RewriteOptions|RewriteRule|RLimitCPU|RLimitMEM|RLimitNPROC)" 34 | - identifier: "(Satisfy|ScoreBoardFile|Script|ScriptAlias|ScriptAliasMatch|ScriptInterpreterSource|ScriptLog|ScriptLogBuffer|ScriptLogLength|ScriptSock|SecureListen)" 35 | - identifier: "(SendBufferSize|ServerAdmin|ServerAlias|ServerLimit|ServerName|ServerPath|ServerRoot|ServerSignature|ServerTokens|SetEnv|SetEnvIf|SetEnvIfNoCase|SetHandler)" 36 | - identifier: "(SetInputFilter|SetOutputFilter|SSIEndTag|SSIErrorMsg|SSIStartTag|SSITimeFormat|SSIUndefinedEcho|SSLCACertificateFile|SSLCACertificatePath)" 37 | - identifier: "(SSLCARevocationFile|SSLCARevocationPath|SSLCertificateChainFile|SSLCertificateFile|SSLCertificateKeyFile|SSLCipherSuite|SSLEngine|SSLMutex|SSLOptions)" 38 | - identifier: "(SSLPassPhraseDialog|SSLProtocol|SSLProxyCACertificateFile|SSLProxyCACertificatePath|SSLProxyCARevocationFile|SSLProxyCARevocationPath|SSLProxyCipherSuite)" 39 | - identifier: "(SSLProxyEngine|SSLProxyMachineCertificateFile|SSLProxyMachineCertificatePath|SSLProxyProtocol|SSLProxyVerify|SSLProxyVerifyDepth|SSLRandomSeed|SSLRequire)" 40 | - identifier: "(SSLRequireSSL|SSLSessionCache|SSLSessionCacheTimeout|SSLUserName|SSLVerifyClient|SSLVerifyDepth|StartServers|StartThreads|SuexecUserGroup|ThreadLimit)" 41 | - identifier: "(ThreadsPerChild|ThreadStackSize|TimeOut|TraceEnable|TransferLog|TypesConfig|UnsetEnv|UseCanonicalName|User|UserDir|VirtualDocumentRoot)" 42 | - identifier: "(VirtualDocumentRootIP|VirtualHost|VirtualScriptAlias|VirtualScriptAliasIP|Win32DisableAcceptEx|XBitHack)" 43 | - symbol.tag: "<[^>]+>" 44 | - identifier: ")" 46 | 47 | - constant.string: 48 | start: "\"" 49 | end: "\"" 50 | skip: "\\\\." 51 | rules: 52 | - constant.specialChar: "\\\\." 53 | 54 | - comment: 55 | start: "#" 56 | end: "$" 57 | rules: 58 | - todo: "(TODO|XXX|FIXME):?" 59 | 60 | -------------------------------------------------------------------------------- /syntax_files/css.yaml: -------------------------------------------------------------------------------- 1 | filetype: css 2 | 3 | detect: 4 | filename: "\\.(css|scss)$" 5 | 6 | rules: 7 | # Classes and IDs 8 | - statement: "(?i)." 9 | # - normal: 10 | # start: "\\{" 11 | # end: "\\}" 12 | # rules: [] 13 | # css commands 14 | - type: "(align-content|align-items|alignment-baseline|align-self|all|animation|animation-delay|animation-direction|animation-duration|animation-fill-mode|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|appearance|azimuth|backface-visibility|background|background-attachment|background-blend-mode|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|baseline-shift|bookmark-label|bookmark-level|bookmark-state|border|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-boundary|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|bottom|box-decoration-break|box-shadow|box-sizing|box-snap|box-suppress|break-after|break-before|break-inside|caption-side|caret|caret-animation|caret-color|caret-shape|chains|clear|clip|clip-path|clip-rule|color|color-interpolation-filters|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|columns|column-span|column-width|content|continue|counter-increment|counter-reset|counter-set|cue|cue-after|cue-before|cursor|direction|display|dominant-baseline|elevation|empty-cells|filter|flex|flex-basis|flex-direction|flex-flow|flex-grow|flex-shrink|flex-wrap|float|float-defer|float-offset|float-reference|flood-color|flood-opacity|flow|flow-from|flow-into|font|font-family|font-feature-settings|font-kerning|font-language-override|font-size|font-size-adjust|font-stretch|font-style|font-synthesis|font-variant|font-variant-alternates|font-variant-caps|font-variant-east-asian|font-variant-ligatures|font-variant-numeric|font-variant-position|font-weight|footnote-display|footnote-policy|glyph-orientation-vertical|grid|grid-area|grid-auto-columns|grid-auto-flow|grid-auto-rows|grid-column|grid-column-end|grid-column-gap|grid-column-start|grid-gap|grid-row|grid-row-end|grid-row-gap|grid-row-start|grid-template|grid-template-areas|grid-template-columns|grid-template-rows|hanging-punctuation|height|hyphenate-character|hyphenate-limit-chars|hyphenate-limit-last|hyphenate-limit-lines|hyphenate-limit-zone|hyphens|image-orientation|image-rendering|image-resolution|initial-letter|initial-letter-align|initial-letter-wrap|isolation|justify-content|justify-items|justify-self|left|letter-spacing|lighting-color|line-break|line-grid|line-height|line-snap|list-style|list-style-image|list-style-position|list-style-type|margin|margin-bottom|margin-left|margin-right|margin-top|marker|marker-end|marker-knockout-left|marker-knockout-right|marker-mid|marker-pattern|marker-segment|marker-side|marker-start|marquee-direction|marquee-loop|marquee-speed|marquee-style|mask|mask-border|mask-border-mode|mask-border-outset|mask-border-repeat|mask-border-slice|mask-border-source|mask-border-width|mask-clip|mask-composite|mask-image|mask-mode|mask-origin|mask-position|mask-repeat|mask-size|mask-type|max-height|max-lines|max-width|min-height|min-width|mix-blend-mode|motion|motion-offset|motion-path|motion-rotation|nav-down|nav-left|nav-right|nav-up|object-fit|object-position|offset-after|offset-before|offset-end|offset-start|opacity|order|orphans|outline|outline-color|outline-offset|outline-style|outline-width|overflow|overflow-style|overflow-wrap|overflow-x|overflow-y|padding|padding-bottom|padding-left|padding-right|padding-top|page|page-break-after|page-break-before|page-break-inside|pause|pause-after|pause-before|perspective|perspective-origin|pitch|pitch-range|play-during|polar-anchor|polar-angle|polar-distance|polar-origin|position|presentation-level|quotes|region-fragment|resize|rest|rest-after|rest-before|richness|right|rotation|rotation-point|ruby-align|ruby-merge|ruby-position|running|scroll-behavior|scroll-snap-align|scroll-snap-margin|scroll-snap-margin-block|scroll-snap-margin-block-end|scroll-snap-margin-block-start|scroll-snap-margin-bottom|scroll-snap-margin-inline|scroll-snap-margin-inline-end|scroll-snap-margin-inline-start|scroll-snap-margin-left|scroll-snap-margin-right|scroll-snap-margin-top|scroll-snap-padding|scroll-snap-padding-block|scroll-snap-padding-block-end|scroll-snap-padding-block-start|scroll-snap-padding-bottom|scroll-snap-padding-inline|scroll-snap-padding-inline-end|scroll-snap-padding-inline-start|scroll-snap-padding-left|scroll-snap-padding-right|scroll-snap-padding-top|scroll-snap-type|shape-image-threshold|shape-inside|shape-margin|shape-outside|size|speak|speak-as|speak-header|speak-numeral|speak-punctuation|speech-rate|stress|string-set|stroke|stroke-alignment|stroke-dashadjust|stroke-dasharray|stroke-dashcorner|stroke-dashoffset|stroke-linecap|stroke-linejoin|stroke-miterlimit|stroke-opacity|stroke-width|table-layout|tab-size|text-align|text-align-all|text-align-last|text-combine-upright|text-decoration|text-decoration-color|text-decoration-line|text-decoration-skip|text-decoration-style|text-emphasis|text-emphasis-color|text-emphasis-position|text-emphasis-style|text-indent|text-justify|text-orientation|text-overflow|text-shadow|text-space-collapse|text-space-trim|text-spacing|text-transform|text-underline-position|text-wrap|top|transform|transform-box|transform-origin|transform-style|transition|transition-delay|transition-duration|transition-property|transition-timing-function|unicode-bidi|user-select|vertical-align|visibility|voice-balance|voice-duration|voice-family|voice-pitch|voice-range|voice-rate|voice-stress|voice-volume|volume|white-space|widows|width|will-change|word-break|word-spacing|word-wrap|wrap-after|wrap-before|wrap-flow|wrap-inside|wrap-through|writing-mode|z-index):" 15 | # - default: 16 | # start: ":" 17 | # end: "[;^\\{]" 18 | # rules: [] 19 | - special: "!important" 20 | - identifier: ":active|:focus|:hover|:link|:visited|:link|:after|:before|$" 21 | - special: "(\\{|\\}|\\(|\\)|\\;|:|\\]|~|<|>|,)" 22 | # SCSS Varaibles 23 | - statement: "@import|@mixin|@extend" 24 | # Strings 25 | - constant.string: 26 | start: "\"" 27 | end: "\"" 28 | skip: "\\\\." 29 | rules: 30 | - constant.specialChar: "\\\\." 31 | - constant.string: 32 | start: "'" 33 | end: "'" 34 | skip: "\\\\." 35 | rules: 36 | - constant.specialChar: "\\\\." 37 | - special: "\"|'" 38 | # Comments & TODOs 39 | - comment: 40 | start: "\\/\\*" 41 | end: "\\*\\/" 42 | rules: 43 | - todo: "(TODO|XXX|FIXME):?" 44 | 45 | -------------------------------------------------------------------------------- /parser.go: -------------------------------------------------------------------------------- 1 | package highlight 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | 7 | "gopkg.in/yaml.v2" 8 | ) 9 | 10 | // A Group represents a syntax group 11 | type Group uint8 12 | 13 | // Groups contains all of the groups that are defined 14 | // You can access them in the map via their string name 15 | var Groups map[string]Group 16 | var numGroups Group 17 | 18 | // String returns the group name attached to the specific group 19 | func (g Group) String() string { 20 | for k, v := range Groups { 21 | if v == g { 22 | return k 23 | } 24 | } 25 | return "" 26 | } 27 | 28 | // A Def is a full syntax definition for a language 29 | // It has a filetype, information about how to detect the filetype based 30 | // on filename or header (the first line of the file) 31 | // Then it has the rules which define how to highlight the file 32 | type Def struct { 33 | FileType string 34 | ftdetect []*regexp.Regexp 35 | rules *rules 36 | } 37 | 38 | // A Pattern is one simple syntax rule 39 | // It has a group that the rule belongs to, as well as 40 | // the regular expression to match the pattern 41 | type pattern struct { 42 | group Group 43 | regex *regexp.Regexp 44 | } 45 | 46 | // rules defines which patterns and regions can be used to highlight 47 | // a filetype 48 | type rules struct { 49 | regions []*region 50 | patterns []*pattern 51 | includes []string 52 | } 53 | 54 | // A region is a highlighted region (such as a multiline comment, or a string) 55 | // It belongs to a group, and has start and end regular expressions 56 | // A region also has rules of its own that only apply when matching inside the 57 | // region and also rules from the above region do not match inside this region 58 | // Note that a region may contain more regions 59 | type region struct { 60 | group Group 61 | limitGroup Group 62 | parent *region 63 | start *regexp.Regexp 64 | end *regexp.Regexp 65 | skip *regexp.Regexp 66 | rules *rules 67 | } 68 | 69 | func init() { 70 | Groups = make(map[string]Group) 71 | } 72 | 73 | // ParseDef parses an input syntax file into a highlight Def 74 | func ParseDef(input []byte) (s *Def, err error) { 75 | // This is just so if we have an error, we can exit cleanly and return the parse error to the user 76 | defer func() { 77 | if e := recover(); e != nil { 78 | err = e.(error) 79 | } 80 | }() 81 | 82 | var rules map[interface{}]interface{} 83 | if err = yaml.Unmarshal(input, &rules); err != nil { 84 | return nil, err 85 | } 86 | 87 | s = new(Def) 88 | 89 | for k, v := range rules { 90 | if k == "filetype" { 91 | filetype := v.(string) 92 | 93 | s.FileType = filetype 94 | } else if k == "detect" { 95 | ftdetect := v.(map[interface{}]interface{}) 96 | if len(ftdetect) >= 1 { 97 | syntax, err := regexp.Compile(ftdetect["filename"].(string)) 98 | if err != nil { 99 | return nil, err 100 | } 101 | 102 | s.ftdetect = append(s.ftdetect, syntax) 103 | } 104 | if len(ftdetect) >= 2 { 105 | header, err := regexp.Compile(ftdetect["header"].(string)) 106 | if err != nil { 107 | return nil, err 108 | } 109 | 110 | s.ftdetect = append(s.ftdetect, header) 111 | } 112 | } else if k == "rules" { 113 | inputRules := v.([]interface{}) 114 | 115 | rules, err := parseRules(inputRules, nil) 116 | if err != nil { 117 | return nil, err 118 | } 119 | 120 | s.rules = rules 121 | } 122 | } 123 | 124 | return s, err 125 | } 126 | 127 | // ResolveIncludes will sort out the rules for including other filetypes 128 | // You should call this after parsing all the Defs 129 | func ResolveIncludes(defs []*Def) { 130 | for _, d := range defs { 131 | resolveIncludesInDef(defs, d) 132 | } 133 | } 134 | 135 | func resolveIncludesInDef(defs []*Def, d *Def) { 136 | for _, lang := range d.rules.includes { 137 | for _, searchDef := range defs { 138 | if lang == searchDef.FileType { 139 | d.rules.patterns = append(d.rules.patterns, searchDef.rules.patterns...) 140 | d.rules.regions = append(d.rules.regions, searchDef.rules.regions...) 141 | } 142 | } 143 | } 144 | for _, r := range d.rules.regions { 145 | resolveIncludesInRegion(defs, r) 146 | r.parent = nil 147 | } 148 | } 149 | 150 | func resolveIncludesInRegion(defs []*Def, region *region) { 151 | for _, lang := range region.rules.includes { 152 | for _, searchDef := range defs { 153 | if lang == searchDef.FileType { 154 | region.rules.patterns = append(region.rules.patterns, searchDef.rules.patterns...) 155 | region.rules.regions = append(region.rules.regions, searchDef.rules.regions...) 156 | } 157 | } 158 | } 159 | for _, r := range region.rules.regions { 160 | resolveIncludesInRegion(defs, r) 161 | r.parent = region 162 | } 163 | } 164 | 165 | func parseRules(input []interface{}, curRegion *region) (*rules, error) { 166 | rules := new(rules) 167 | 168 | for _, v := range input { 169 | rule := v.(map[interface{}]interface{}) 170 | for k, val := range rule { 171 | group := k 172 | 173 | switch object := val.(type) { 174 | case string: 175 | if k == "include" { 176 | rules.includes = append(rules.includes, object) 177 | } else { 178 | // Pattern 179 | r, err := regexp.Compile(object) 180 | if err != nil { 181 | return nil, err 182 | } 183 | 184 | groupStr := group.(string) 185 | if _, ok := Groups[groupStr]; !ok { 186 | numGroups++ 187 | Groups[groupStr] = numGroups 188 | } 189 | groupNum := Groups[groupStr] 190 | rules.patterns = append(rules.patterns, &pattern{groupNum, r}) 191 | } 192 | case map[interface{}]interface{}: 193 | // region 194 | region, err := parseRegion(group.(string), object, curRegion) 195 | if err != nil { 196 | return nil, err 197 | } 198 | rules.regions = append(rules.regions, region) 199 | default: 200 | return nil, fmt.Errorf("Bad type %T", object) 201 | } 202 | } 203 | } 204 | 205 | return rules, nil 206 | } 207 | 208 | func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegion *region) (*region, error) { 209 | var err error 210 | 211 | region := new(region) 212 | if _, ok := Groups[group]; !ok { 213 | numGroups++ 214 | Groups[group] = numGroups 215 | } 216 | groupNum := Groups[group] 217 | region.group = groupNum 218 | region.parent = prevRegion 219 | 220 | region.start, err = regexp.Compile(regionInfo["start"].(string)) 221 | 222 | if err != nil { 223 | return nil, err 224 | } 225 | 226 | region.end, err = regexp.Compile(regionInfo["end"].(string)) 227 | 228 | if err != nil { 229 | return nil, err 230 | } 231 | 232 | // skip is optional 233 | if _, ok := regionInfo["skip"]; ok { 234 | region.skip, err = regexp.Compile(regionInfo["skip"].(string)) 235 | 236 | if err != nil { 237 | return nil, err 238 | } 239 | } 240 | 241 | // limit-color is optional 242 | if _, ok := regionInfo["limit-group"]; ok { 243 | groupStr := regionInfo["limit-group"].(string) 244 | if _, ok := Groups[groupStr]; !ok { 245 | numGroups++ 246 | Groups[groupStr] = numGroups 247 | } 248 | groupNum := Groups[groupStr] 249 | region.limitGroup = groupNum 250 | 251 | if err != nil { 252 | return nil, err 253 | } 254 | } else { 255 | region.limitGroup = region.group 256 | } 257 | 258 | region.rules, err = parseRules(regionInfo["rules"].([]interface{}), region) 259 | 260 | if err != nil { 261 | return nil, err 262 | } 263 | 264 | return region, nil 265 | } 266 | -------------------------------------------------------------------------------- /syntax_files/asm.yaml: -------------------------------------------------------------------------------- 1 | filetype: asm 2 | 3 | detect: 4 | filename: "\\.(S|s|asm)$" 5 | 6 | rules: 7 | # This file is made for NASM assembly 8 | 9 | ## Instructions 10 | # x86 11 | - statement: "\\b(?i)(mov|aaa|aad|aam|aas|adc|add|and|call|cbw|clc|cld|cli|cmc|cmp|cmpsb|cmpsw|cwd|daa|das|dec|div|esc|hlt|idiv|imul|in|inc|int|into|iret|ja|jae|jb|jbe|jc|je|jg|jge|jl|jle|jna|jnae|jnb|jnbe|jnc|jne|jng|jnge|jnl|jnle|jno|jnp|jns|jnz|jo|jp|jpe|jpo|js|jz|jcxz|jmp|lahf|lds|lea|les|lock|lodsb|lodsw|loop|loope|loopne|loopnz|loopz|movsb|movsw|mul|neg|nop|or|pop|popf|push|pushf|rcl|rcr|rep|repe|repne|repnz|repz|ret|retn|retf|rol|ror|sahf|sal|sar|sbb|scasb|scasw|shl|shr|stc|std|sti|stosb|stosw|sub|test|wait|xchg|xlat|xor)(?-i)\\b" 12 | - statement: "\\b(?i)(bound|enter|ins|leave|outs|popa|pusha)(?-i)\\b" 13 | - statement: "\\b(?i)(arpl|clts|lar|lgdt|lidt|lldt|lmsw|loadall|lsl|ltr|sgdt|sidt|sldt|smsw|str|verr|verw)(?-i)\\b" 14 | - statement: "\\b(?i)(bsf|bsr|bt|btc|btr|bts|cdq|cmpsd|cwde|insd|iret|iretd|iretf|jecxz|lfs|lgs|lss|lodsd|loopw|loopew|loopnew|loopnzw|loopzw|loopd|looped|loopned|loopnzd|loopzd|cr|tr|dr|movsd|movsx|movzx|outsd|popad|popfd|pushad|pushfd|scasd|seta|setae|setb|setbe|setc|sete|setg|setge|setl|setle|setna|setnae|setnb|setnbe|setnc|setne|setng|setnge|setnl|setnle|setno|setnp|setns|setnz|seto|setp|setpe|setpo|sets|setz|shdl|shrd|stosd)(?-i)\\b" 15 | - statement: "\\b(?i)(bswap|cmpxcgh|invd|invlpg|wbinvd|xadd)(?-i)\\b" 16 | - statement: "\\b(?i)(cpuid|cmpxchg8b|rdmsr|rdtsc|wrmsr|rsm)(?-i)\\b" 17 | - statement: "\\b(?i)(rdpmc)(?-i)\\b" 18 | - statement: "\\b(?i)(syscall|sysret)(?-i)\\b" 19 | - statement: "\\b(?i)(cmova|cmovae|cmovb|cmovbe|cmovc|cmove|cmovg|cmovge|cmovl|cmovle|cmovna|cmovnae|cmovnb|cmovnbe|cmovnc|cmovne|cmovng|cmovnge|cmovnle|cmovno|cmovpn|cmovns|cmovnz|cmovo|cmovp|cmovpe|cmovpo|cmovs|cmovz|sysenter|sysexit|ud2)(?-i)\\b" 20 | - statement: "\\b(?i)(maskmovq|movntps|movntq|prefetch0|prefetch1|prefetch2|prefetchnta|sfence)(?-i)\\b" 21 | - statement: "\\b(?i)(clflush|lfence|maskmovdqu|mfence|movntdq|movnti|movntpd|pause)(?-i)\\b" 22 | - statement: "\\b(?i)(monitor|mwait)(?-i)\\b" 23 | - statement: "\\b(?i)(cdqe|cqo|cmpsq|cmpxchg16b|iretq|jrcxz|lodsq|movsdx|popfq|pushfq|rdtscp|scasq|stosq|swapgs)(?-i)\\b" 24 | - statement: "\\b(?i)(clgi|invlpga|skinit|stgi|vmload|vmmcall|vmrun|vmsave)(?-i)\\b" 25 | - statement: "\\b(?i)(vmptrdl|vmptrst|vmclear|vmread|vmwrite|vmcall|vmlaunch|vmresume|vmxoff|vmxon)(?-i)\\b" 26 | - statement: "\\b(?i)(lzcnt|popcnt)(?-i)\\b" 27 | - statement: "\\b(?i)(bextr|blcfill|blci|blcic|blcmask|blcs|blsfill|blsic|t1mskc|tzmsk)(?-i)\\b" 28 | 29 | # x87 30 | - statement: "\\b(?i)(f2xm1|fabs|fadd|faddp|fbld|fbstp|fchs|fclex|fcom|fcomp|fcompp|fdecstp|fdisi|fdiv|fvidp|fdivr|fdivrp|feni|ffree|fiadd|ficom|ficomp|fidiv|fidivr|fild|fimul|fincstp|finit|fist|fistp|fisub|fisubr|fld|fld1|fldcw|fldenv|fldenvw|fldl2e|fldl2t|fldlg2|fldln2|fldpi|fldz|fmul|fmulp|fnclex|fndisi|fneni|fninit|fnop|fnsave|fnsavenew|fnstcw|fnstenv|fnstenvw|fnstsw|fpatan|fprem|fptan|frndint|frstor|frstorw|fsave|fsavew|fscale|fsqrt|fst|fstcw|fstenv|fstenvw|fstp|fstpsw|fsub|fsubp|fsubr|fsubrp|ftst|fwait|fxam|fxch|fxtract|fyl2x|fyl2xp1)(?-i)\\b" 31 | - statement: "\\b(?i)(fsetpm)(?-i)\\b" 32 | - statement: "\\b(?i)(fcos|fldenvd|fsaved|fstenvd|fprem1|frstord|fsin|fsincos|fstenvd|fucom|fucomp|fucompp)(?-i)\\b" 33 | - statement: "\\b(?i)(fcmovb|fcmovbe|fcmove|fcmove|fcmovnb|fcmovnbe|fcmovne|fcmovnu|fcmovu)(?-i)\\b" 34 | - statement: "\\b(?i)(fcomi|fcomip|fucomi|fucomip)(?-i)\\b" 35 | - statement: "\\b(?i)(fxrstor|fxsave)(?-i)\\b" 36 | - statement: "\\b(?i)(fisttp)(?-i)\\b" 37 | - statement: "\\b(?i)(ffreep)(?-i)\\b" 38 | 39 | # SIMD 40 | - statement: "\\b(?i)(emms|movd|movq|packssdw|packsswb|packuswb|paddb|paddw|paddd|paddsb|paddsw|paddusb|paddusw|pand|pandn|por|pxor|pcmpeqb|pcmpeqw|pcmpeqd|pcmpgtb|pcmpgtw|pcmpgtd|pmaddwd|pmulhw|pmullw|psllw|pslld|psllq|psrad|psraw|psrlw|psrld|psrlq|psubb|psubw|psubd|psubsb|psubsw|psubusb|punpckhbw|punpckhwd|punpckhdq|punkcklbw|punpckldq|punpcklwd)(?-i)\\b" 41 | - statement: "\\b(?i)(paveb|paddsiw|pmagw|pdistib|psubsiw|pmwzb|pmulhrw|pmvnzb|pmvlzb|pmvgezb|pmulhriw|pmachriw)(?-i)\\b" 42 | - statement: "\\b(?i)(femms|pavgusb|pf2id|pfacc|pfadd|pfcmpeq|pfcmpge|pfcmpgt|pfmax|pfmin|pfmul|pfrcp|pfrcpit1|pfrcpit2|pfrsqit1|pfrsqrt|pfsub|pfsubr|pi2fd|pmulhrw|prefetch|prefetchw)(?-i)\\b" 43 | - statement: "\\b(?i)(pf2iw|pfnacc|pfpnacc|pi2fw|pswapd)(?-i)\\b" 44 | - statement: "\\b(?i)(pfrsqrtv|pfrcpv)(?-i)\\b" 45 | - statement: "\\b(?i)(addps|addss|cmpps|cmpss|comiss|cvtpi2ps|cvtps2pi|cvtsi2ss|cvtss2si|cvttps2pi|cvttss2si|divps|divss|ldmxcsr|maxps|maxss|minps|minss|movaps|movhlps|movhps|movlhps|movlps|movmskps|movntps|movss|movups|mulps|mulss|rcpps|rcpss|rsqrtps|rsqrtss|shufps|sqrtps|sqrtss|stmxcsr|subps|subss|ucomiss|unpckhps|unpcklps)(?-i)\\b" 46 | - statement: "\\b(?i)(andnps|andps|orps|pavgb|pavgw|pextrw|pinsrw|pmaxsw|pmaxub|pminsw|pminub|pmovmskb|pmulhuw|psadbw|pshufw|xorps)(?-i)\\b" 47 | - statement: "\\b(?i)(movups|movss|movlps|movhlps|movlps|unpcklps|unpckhps|movhps|movlhps|prefetchnta|prefetch0|prefetch1|prefetch2|nop|movaps|cvtpi2ps|cvtsi2ss|cvtps2pi|cvttss2si|cvtps2pi|cvtss2si|ucomiss|comiss|sqrtps|sqrtss|rsqrtps|rsqrtss|rcpps|andps|orps|xorps|addps|addss|mulps|mulss|subps|subss|minps|minss|divps|divss|maxps|maxss|pshufw|ldmxcsr|stmxcsr|sfence|cmpps|cmpss|pinsrw|pextrw|shufps|pmovmskb|pminub|pmaxub|pavgb|pavgw|pmulhuw|movntq|pminsw|pmaxsw|psadbw|maskmovq)(?-i)\\b" 48 | - statement: "\\b(?i)(addpd|addsd|addnpd|cmppd|cmpsd)(?-i)\\b" 49 | - statement: "\\b(?i)(addpd|addsd|andnpd|andpd|cmppd|cmpsd|comisd|cvtdq2pd|cvtdq2ps|cvtpd2dq|cvtpd2pi|cvtpd2ps|cvtpi2pd|cvtps2dq|cvtps2pd|cvtsd2si|cvtsd2ss|cvtsi2sd|cvtss2sd|cvttpd2dq|cvttpd2pi|cvttps2dq|cvttsd2si|divpd|divsd|maxpd|maxsd|minpd|minsd|movapd|movhpd|movlpd|movmskpd|movsd|movupd|mulpd|mulsd|orpd|shufpd|sqrtpd|sqrtsd|subpd|subsd|ucomisd|unpckhpd|unpcklpd|xorpd)(?-i)\\b" 50 | - statement: "\\b(?i)(movdq2q|movdqa|movdqu|movq2dq|paddq|psubq|pmuludq|pshufhw|pshuflw|pshufd|pslldq|psrldq|punpckhqdq|punpcklqdq)(?-i)\\b" 51 | - statement: "\\b(?i)(addsubpd|addsubps|haddpd|haddps|hsubpd|hsubps|movddup|movshdup|movsldu)(?-i)\\b" 52 | - statement: "\\b(?i)(lddqu)(?-i)\\b" 53 | - statement: "\\b(?i)(psignw|psignd|psignb|pshufb|pmulhrsw|pmaddubsw|phsubw|phsubsw|phsubd|phaddw|phaddsw|phaddd|palignr|pabsw|pabsd|pabsb)(?-i)\\b" 54 | - statement: "\\b(?i)(dpps|dppd|blendps|blendpd|blendvps|blendvpd|roundps|roundss|roundpd|roundsd|insertps|extractps)(?-i)\\b" 55 | - statement: "\\b(?i)(mpsadbw|phminposuw|pmulld|pmuldq|pblendvb|pblendw|pminsb|pmaxsb|pminuw|pmaxuw|pminud|pmaxud|pminsd|pmaxsd|pinsrb|pinsrd/pinsrq|pextrb|pextrw|pextrd/pextrq|pmovsxbw|pmovzxbw|pmovsxbd|pmovzxbd|pmovsxbq|pmovzxbq|pmovsxwd|pmovzxwd|pmovsxwq|pmovzxwq|pmovsxdq|pmovzxdq|ptest|pcmpeqq|packusdw|movntdqa)(?-i)\\b" 56 | - statement: "\\b(?i)(extrq|insertq|movntsd|movntss)(?-i)\\b" 57 | - statement: "\\b(?i)(crc32|pcmpestri|pcmpestrm|pcmpistri|pcmpistrm|pcmpgtq)(?-i)\\b" 58 | - statement: "\\b(?i)(vfmaddpd|vfmaddps|vfmaddsd|vfmaddss|vfmaddsubpd|vfmaddsubps|vfmsubaddpd|vfmsubaddps|vfmsubpd|vfmsubps|vfmsubsd|vfmsubss|vfnmaddpd|vfnmaddps|vfnmaddsd|vfnmaddss|vfnmsubps|vfnmsubsd|vfnmsubss)(?-i)\\b" 59 | 60 | # Crypto 61 | - statement: "\\b(?i)(aesenc|aesenclast|aesdec|aesdeclast|aeskeygenassist|aesimc)(?-i)\\b" 62 | - statement: "\\b(?i)(sha1rnds4|sha1nexte|sha1msg1|sha1msg2|sha256rnds2|sha256msg1|sha256msg2)(?-i)\\b" 63 | 64 | # Undocumented 65 | - statement: "\\b(?i)(aam|aad|salc|icebp|loadall|loadalld|ud1)(?-i)\\b" 66 | 67 | ## Registers 68 | - identifier: "\\b(?i)(al|ah|bl|bh|cl|ch|dl|dh|bpl|sil|r8b|r9b|r10b|r11b|dil|spl|r12b|r13b|r14b|r15)(?-i)\\b" 69 | - identifier: "\\b(?i)(cw|sw|tw|fp_ds|fp_opc|fp_ip|fp_dp|fp_cs|cs|ss|ds|es|fs|gs|gdtr|idtr|tr|ldtr|ax|bx|cx|dx|bp|si|r8w|r9w|r10w|r11w|di|sp|r12w|r13w|r14w|r15w|ip)(?-i)\\b" 70 | - identifier: "\\b(?i)(fp_dp|fp_ip|eax|ebx|ecx|edx|ebp|esi|r8d|r9d|r10d|r11d|edi|esp|r12d|r13d|r14d|r15d|eip|eflags|mxcsr)(?-i)\\b" 71 | - identifier: "\\b(?i)(mm0|mm1|mm2|mm3|mm4|mm5|mm6|mm7|rax|rbx|rcx|rdx|rbp|rsi|r8|r9|r10|r11|rdi|rsp|r12|r13|r14|r15|rip|rflags|cr0|cr1|cr2|cr3|cr4|cr5|cr6|cr7|cr8|cr9|cr10|cr11|cr12|cr13|cr14|cr15|msw|dr0|dr1|dr2|dr3|r4|dr5|dr6|dr7|dr8|dr9|dr10|dr11|dr12|dr13|dr14|dr15)(?-i)\\b" 72 | - identifier: "\\b(?i)(st0|st1|st2|st3|st4|st5|st6|st7)(?-i)\\b" 73 | - identifier: "\\b(?i)(xmm0|xmm1|xmm2|xmm3|xmm4|xmm5|xmm6|xmm7|xmm8|xmm9|xmm10|xmm11|xmm12|xmm13|xmm14|xmm15)(?-i)\\b" 74 | - identifier: "\\b(?i)(ymm0|ymm1|ymm2|ymm3|ymm4|ymm5|ymm6|ymm7|ymm8|ymm9|ymm10|ymm11|ymm12|ymm13|ymm14|ymm15)(?-i)\\b" 75 | - identifier: "\\b(?i)(zmm0|zmm1|zmm2|zmm3|zmm4|zmm5|zmm6|zmm7|zmm8|zmm9|zmm10|zmm11|zmm12|zmm13|zmm14|zmm15|zmm16|zmm17|zmm18|zmm19|zmm20|zmm21|zmm22|zmm23|zmm24|zmm25|zmm26|zmm27|zmm28|zmm29|zmm30|zmm31)(?-i)\\b" 76 | 77 | ## Constants 78 | # Number - it works 79 | - constant.number: "\\b(|h|A|0x)+[0-9]+(|h|A)+\\b" 80 | - constant.number: "\\b0x[0-9 a-f A-F]+\\b" 81 | 82 | ## Preprocessor (NASM) 83 | - preproc: "%+(\\+|\\?|\\?\\?|)[a-z A-Z 0-9]+" 84 | - preproc: "%\\[[. a-z A-Z 0-9]*\\]" 85 | 86 | ## Other 87 | - statement: "\\b(?i)(extern|global|section|segment|_start|\\.text|\\.data|\\.bss)(?-i)\\b" 88 | - statement: "\\b(?i)(db|dw|dd|dq|dt|ddq|do)(?-i)\\b" 89 | - identifier: "[a-z A-Z 0-9 _]+:" 90 | 91 | - constant.string: 92 | start: "\"" 93 | end: "\"" 94 | skip: "\\\\." 95 | rules: 96 | - constant.specialChar: "\\\\." 97 | 98 | - constant.string: 99 | start: "'" 100 | end: "'" 101 | skip: "\\\\." 102 | rules: 103 | - constant.specialChar: "\\\\." 104 | 105 | - comment: 106 | start: ";" 107 | end: "$" 108 | rules: 109 | - todo: "(TODO|XXX|FIXME):?" 110 | 111 | -------------------------------------------------------------------------------- /highlighter.go: -------------------------------------------------------------------------------- 1 | package highlight 2 | 3 | import ( 4 | "regexp" 5 | "strings" 6 | "unicode/utf8" 7 | ) 8 | 9 | // RunePos returns the rune index of a given byte index 10 | // This could cause problems if the byte index is between code points 11 | func runePos(p int, str string) int { 12 | if p < 0 { 13 | return 0 14 | } 15 | if p >= len(str) { 16 | return utf8.RuneCountInString(str) 17 | } 18 | return utf8.RuneCountInString(str[:p]) 19 | } 20 | 21 | func combineLineMatch(src, dst LineMatch) LineMatch { 22 | for k, v := range src { 23 | if g, ok := dst[k]; ok { 24 | if g == 0 { 25 | dst[k] = v 26 | } 27 | } else { 28 | dst[k] = v 29 | } 30 | } 31 | return dst 32 | } 33 | 34 | // A State represents the region at the end of a line 35 | type State *region 36 | 37 | // LineStates is an interface for a buffer-like object which can also store the states and matches for every line 38 | type LineStates interface { 39 | Line(n int) string 40 | LinesNum() int 41 | State(lineN int) State 42 | SetState(lineN int, s State) 43 | SetMatch(lineN int, m LineMatch) 44 | } 45 | 46 | // A Highlighter contains the information needed to highlight a string 47 | type Highlighter struct { 48 | lastRegion *region 49 | Def *Def 50 | } 51 | 52 | // NewHighlighter returns a new highlighter from the given syntax definition 53 | func NewHighlighter(def *Def) *Highlighter { 54 | h := new(Highlighter) 55 | h.Def = def 56 | return h 57 | } 58 | 59 | // LineMatch represents the syntax highlighting matches for one line. Each index where the coloring is changed is marked with that 60 | // color's group (represented as one byte) 61 | type LineMatch map[int]Group 62 | 63 | func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int { 64 | regexStr := regex.String() 65 | if strings.Contains(regexStr, "^") { 66 | if !canMatchStart { 67 | return nil 68 | } 69 | } 70 | if strings.Contains(regexStr, "$") { 71 | if !canMatchEnd { 72 | return nil 73 | } 74 | } 75 | 76 | var strbytes []byte 77 | if skip != nil { 78 | strbytes = skip.ReplaceAllFunc([]byte(string(str)), func(match []byte) []byte { 79 | res := make([]byte, utf8.RuneCount(match)) 80 | return res 81 | }) 82 | } else { 83 | strbytes = []byte(string(str)) 84 | } 85 | 86 | match := regex.FindIndex(strbytes) 87 | if match == nil { 88 | return nil 89 | } 90 | // return []int{match.Index, match.Index + match.Length} 91 | return []int{runePos(match[0], string(str)), runePos(match[1], string(str))} 92 | } 93 | 94 | func findAllIndex(regex *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) [][]int { 95 | regexStr := regex.String() 96 | if strings.Contains(regexStr, "^") { 97 | if !canMatchStart { 98 | return nil 99 | } 100 | } 101 | if strings.Contains(regexStr, "$") { 102 | if !canMatchEnd { 103 | return nil 104 | } 105 | } 106 | matches := regex.FindAllIndex([]byte(string(str)), -1) 107 | for i, m := range matches { 108 | matches[i][0] = runePos(m[0], string(str)) 109 | matches[i][1] = runePos(m[1], string(str)) 110 | } 111 | return matches 112 | } 113 | 114 | func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchEnd bool, lineNum int, line []rune, curRegion *region, statesOnly bool) LineMatch { 115 | // highlights := make(LineMatch) 116 | 117 | if start == 0 { 118 | if !statesOnly { 119 | if _, ok := highlights[0]; !ok { 120 | highlights[0] = curRegion.group 121 | } 122 | } 123 | } 124 | 125 | loc := findIndex(curRegion.end, curRegion.skip, line, start == 0, canMatchEnd) 126 | if loc != nil { 127 | if !statesOnly { 128 | highlights[start+loc[0]] = curRegion.limitGroup 129 | } 130 | if curRegion.parent == nil { 131 | if !statesOnly { 132 | highlights[start+loc[1]] = 0 133 | h.highlightRegion(highlights, start, false, lineNum, line[:loc[0]], curRegion, statesOnly) 134 | } 135 | h.highlightEmptyRegion(highlights, start+loc[1], canMatchEnd, lineNum, line[loc[1]:], statesOnly) 136 | return highlights 137 | } 138 | if !statesOnly { 139 | highlights[start+loc[1]] = curRegion.parent.group 140 | h.highlightRegion(highlights, start, false, lineNum, line[:loc[0]], curRegion, statesOnly) 141 | } 142 | h.highlightRegion(highlights, start+loc[1], canMatchEnd, lineNum, line[loc[1]:], curRegion.parent, statesOnly) 143 | return highlights 144 | } 145 | 146 | if len(line) == 0 || statesOnly { 147 | if canMatchEnd { 148 | h.lastRegion = curRegion 149 | } 150 | 151 | return highlights 152 | } 153 | 154 | firstLoc := []int{len(line), 0} 155 | 156 | var firstRegion *region 157 | for _, r := range curRegion.rules.regions { 158 | loc := findIndex(r.start, nil, line, start == 0, canMatchEnd) 159 | if loc != nil { 160 | if loc[0] < firstLoc[0] { 161 | firstLoc = loc 162 | firstRegion = r 163 | } 164 | } 165 | } 166 | if firstLoc[0] != len(line) { 167 | highlights[start+firstLoc[0]] = firstRegion.limitGroup 168 | h.highlightRegion(highlights, start, false, lineNum, line[:firstLoc[0]], curRegion, statesOnly) 169 | h.highlightRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, line[firstLoc[1]:], firstRegion, statesOnly) 170 | return highlights 171 | } 172 | 173 | fullHighlights := make([]Group, len([]rune(string(line)))) 174 | for i := 0; i < len(fullHighlights); i++ { 175 | fullHighlights[i] = curRegion.group 176 | } 177 | 178 | for _, p := range curRegion.rules.patterns { 179 | matches := findAllIndex(p.regex, line, start == 0, canMatchEnd) 180 | for _, m := range matches { 181 | for i := m[0]; i < m[1]; i++ { 182 | fullHighlights[i] = p.group 183 | } 184 | } 185 | } 186 | for i, h := range fullHighlights { 187 | if i == 0 || h != fullHighlights[i-1] { 188 | // if _, ok := highlights[start+i]; !ok { 189 | highlights[start+i] = h 190 | // } 191 | } 192 | } 193 | 194 | if canMatchEnd { 195 | h.lastRegion = curRegion 196 | } 197 | 198 | return highlights 199 | } 200 | 201 | func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canMatchEnd bool, lineNum int, line []rune, statesOnly bool) LineMatch { 202 | if len(line) == 0 { 203 | if canMatchEnd { 204 | h.lastRegion = nil 205 | } 206 | return highlights 207 | } 208 | 209 | firstLoc := []int{len(line), 0} 210 | var firstRegion *region 211 | for _, r := range h.Def.rules.regions { 212 | loc := findIndex(r.start, nil, line, start == 0, canMatchEnd) 213 | if loc != nil { 214 | if loc[0] < firstLoc[0] { 215 | firstLoc = loc 216 | firstRegion = r 217 | } 218 | } 219 | } 220 | if firstLoc[0] != len(line) { 221 | if !statesOnly { 222 | highlights[start+firstLoc[0]] = firstRegion.limitGroup 223 | } 224 | h.highlightEmptyRegion(highlights, start, false, lineNum, line[:firstLoc[0]], statesOnly) 225 | h.highlightRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, line[firstLoc[1]:], firstRegion, statesOnly) 226 | return highlights 227 | } 228 | 229 | if statesOnly { 230 | if canMatchEnd { 231 | h.lastRegion = nil 232 | } 233 | 234 | return highlights 235 | } 236 | 237 | fullHighlights := make([]Group, len(line)) 238 | for _, p := range h.Def.rules.patterns { 239 | matches := findAllIndex(p.regex, line, start == 0, canMatchEnd) 240 | for _, m := range matches { 241 | for i := m[0]; i < m[1]; i++ { 242 | fullHighlights[i] = p.group 243 | } 244 | } 245 | } 246 | for i, h := range fullHighlights { 247 | if i == 0 || h != fullHighlights[i-1] { 248 | // if _, ok := highlights[start+i]; !ok { 249 | highlights[start+i] = h 250 | // } 251 | } 252 | } 253 | 254 | if canMatchEnd { 255 | h.lastRegion = nil 256 | } 257 | 258 | return highlights 259 | } 260 | 261 | // HighlightString syntax highlights a string 262 | // Use this function for simple syntax highlighting and use the other functions for 263 | // more advanced syntax highlighting. They are optimized for quick rehighlighting of the same 264 | // text with minor changes made 265 | func (h *Highlighter) HighlightString(input string) []LineMatch { 266 | lines := strings.Split(input, "\n") 267 | var lineMatches []LineMatch 268 | 269 | for i := 0; i < len(lines); i++ { 270 | line := []rune(lines[i]) 271 | highlights := make(LineMatch) 272 | 273 | if i == 0 || h.lastRegion == nil { 274 | lineMatches = append(lineMatches, h.highlightEmptyRegion(highlights, 0, true, i, line, false)) 275 | } else { 276 | lineMatches = append(lineMatches, h.highlightRegion(highlights, 0, true, i, line, h.lastRegion, false)) 277 | } 278 | } 279 | 280 | return lineMatches 281 | } 282 | 283 | // HighlightStates correctly sets all states for the buffer 284 | func (h *Highlighter) HighlightStates(input LineStates) { 285 | for i := 0; i < input.LinesNum(); i++ { 286 | line := []rune(input.Line(i)) 287 | // highlights := make(LineMatch) 288 | 289 | if i == 0 || h.lastRegion == nil { 290 | h.highlightEmptyRegion(nil, 0, true, i, line, true) 291 | } else { 292 | h.highlightRegion(nil, 0, true, i, line, h.lastRegion, true) 293 | } 294 | 295 | curState := h.lastRegion 296 | 297 | input.SetState(i, curState) 298 | } 299 | } 300 | 301 | // HighlightMatches sets the matches for each line in between startline and endline 302 | // It sets all other matches in the buffer to nil to conserve memory 303 | // This assumes that all the states are set correctly 304 | func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int) { 305 | for i := startline; i < endline; i++ { 306 | if i >= input.LinesNum() { 307 | break 308 | } 309 | 310 | line := []rune(input.Line(i)) 311 | highlights := make(LineMatch) 312 | 313 | var match LineMatch 314 | if i == 0 || input.State(i-1) == nil { 315 | match = h.highlightEmptyRegion(highlights, 0, true, i, line, false) 316 | } else { 317 | match = h.highlightRegion(highlights, 0, true, i, line, input.State(i-1), false) 318 | } 319 | 320 | input.SetMatch(i, match) 321 | } 322 | } 323 | 324 | // ReHighlightStates will scan down from `startline` and set the appropriate end of line state 325 | // for each line until it comes across the same state in two consecutive lines 326 | func (h *Highlighter) ReHighlightStates(input LineStates, startline int) { 327 | // lines := input.LineData() 328 | 329 | h.lastRegion = nil 330 | if startline > 0 { 331 | h.lastRegion = input.State(startline - 1) 332 | } 333 | for i := startline; i < input.LinesNum(); i++ { 334 | line := []rune(input.Line(i)) 335 | // highlights := make(LineMatch) 336 | 337 | // var match LineMatch 338 | if i == 0 || h.lastRegion == nil { 339 | h.highlightEmptyRegion(nil, 0, true, i, line, true) 340 | } else { 341 | h.highlightRegion(nil, 0, true, i, line, h.lastRegion, true) 342 | } 343 | curState := h.lastRegion 344 | lastState := input.State(i) 345 | 346 | input.SetState(i, curState) 347 | 348 | if curState == lastState { 349 | break 350 | } 351 | } 352 | } 353 | 354 | // ReHighlightLine will rehighlight the state and match for a single line 355 | func (h *Highlighter) ReHighlightLine(input LineStates, lineN int) { 356 | line := []rune(input.Line(lineN)) 357 | highlights := make(LineMatch) 358 | 359 | h.lastRegion = nil 360 | if lineN > 0 { 361 | h.lastRegion = input.State(lineN - 1) 362 | } 363 | 364 | var match LineMatch 365 | if lineN == 0 || h.lastRegion == nil { 366 | match = h.highlightEmptyRegion(highlights, 0, true, lineN, line, false) 367 | } else { 368 | match = h.highlightRegion(highlights, 0, true, lineN, line, h.lastRegion, false) 369 | } 370 | curState := h.lastRegion 371 | 372 | input.SetMatch(lineN, match) 373 | input.SetState(lineN, curState) 374 | } 375 | --------------------------------------------------------------------------------