diff --git a/parser.go b/parser.go index 7f97de9..6dd5326 100644 --- a/parser.go +++ b/parser.go @@ -45,7 +45,6 @@ type Region struct { } // ParseDef parses an input syntax file into a highlight Def -// Note that ParseDef may return multiple errors func ParseDef(input []byte) (*Def, error) { var rules map[interface{}]interface{} if err := yaml.Unmarshal(input, &rules); err != nil { diff --git a/syntax_files/go.yaml b/syntax_files/go.yaml index e37b045..3103e60 100644 --- a/syntax_files/go.yaml +++ b/syntax_files/go.yaml @@ -28,7 +28,8 @@ rules: - comment: start: "/\\*" end: "\\*/" - rules: [] + rules: + - todo: "(TODO|XXX|FIXME):?" - constant.string: start: "\"" diff --git a/syntax_files/rust.yaml b/syntax_files/rust.yaml new file mode 100644 index 0000000..dc6d101 --- /dev/null +++ b/syntax_files/rust.yaml @@ -0,0 +1,46 @@ +filetype: rust + +detect: + filename: "\\.rs$" + +rules: + # function definition + - identifier: "fn [a-z0-9_]+" + # Reserved words + - 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" + # macros + - special: "[a-z_]+!" + # Constants + - constant: "[A-Z][A-Z_]+" + # Numbers + - constant.number: "\\b[0-9]+\\b" + # Traits/Enums/Structs/Types/etc. + - type: "[A-Z][a-z]+" + + - constant.string: + start: "\"" + end: "\"" + rules: + - constant.specialChar: "\\\\." + + - constant.string: + start: "r#+\"" + end: "\"#+" + rules: [] + + - comment: + start: "//" + end: "$" + rules: + - todo: "(TODO|XXX|FIXME):?" + + - comment: + start: "/\\*" + end: "\\*/" + rules: + - todo: "(TODO|XXX|FIXME):?" + + - special: + start: "#!\\[" + end: "\\]" + rules: [] diff --git a/syntax_files/sh.yaml b/syntax_files/sh.yaml new file mode 100644 index 0000000..a44ce6e --- /dev/null +++ b/syntax_files/sh.yaml @@ -0,0 +1,41 @@ +filetype: shell + +detect: + 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)" + header: "^#!.*/(env +)?(ba)?sh( |$)" + +rules: + # Numbers + - constant.number: "\\b[0-9]+\\b" + # Conditionals and control flow + - statement: "\\b(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\\b" + - special: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" + # Shell commands + - type: "\\b(cd|echo|export|let|set|umask|unset)\\b" + # Common linux commands + - type: "\\b((g|ig)?awk|bash|dash|find|\\w{0,4}grep|kill|killall|\\w{0,4}less|make|pkill|sed|sh|tar)\\b" + # Coreutils commands + - 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" + # Conditional flags + - statement: "--[a-z-]+" + - statement: "\\ -[a-z]+" + + - identifier: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" + - identifier: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" + + - constant.string: + start: "\"" + end: "\"" + rules: + - constant.specialChar: "\\\\." + + - constant.string: + start: "'" + end: "'" + rules: + + - comment: + start: "#" + end: "$" + rules: + - todo: "(TODO|XXX|FIXME):?" diff --git a/syntax_files/swift.yaml b/syntax_files/swift.yaml new file mode 100644 index 0000000..307aaf6 --- /dev/null +++ b/syntax_files/swift.yaml @@ -0,0 +1,49 @@ +filetype: swift + +detect: + filename: "\\.swift$" + +rules: + # Operators + - statement: "[.:;,+*|=!?\\%]" "<" ">" "/" "-" "&" + + # Statements + - statement: "(class|import|let|var|struct|enum|func|if|else|switch|case|default|for|in|internal|external|unowned|private|public|throws)\\ " + - statement: "(prefix|postfix|operator|extension|lazy|get|set|self|willSet|didSet|override|super|convenience|weak|strong|mutating|return|guard)\\ " + + # Keywords + - statement: "(print)" + - statement: "(init)" + + # Numbers + - constant.number: "([0-9]+)" + + # Standard Types + - type: "\\ ((U)?Int(8|16|32|64))" + - constant: "(true|false|nil)" + - type: "\\ (Double|String|Float|Boolean|Dictionary|Array|Int)" + - type: "\\ (AnyObject)" + + - constant.string: + start: "\"" + end: "\"" + rules: + - constant.specialChar: "\\\\." + + - comment: + start: "//" + end: "$" + rules: + - todo: "(TODO|XXX|FIXME):?" + + - comment: + start: "///" + end: "$" + rules: + - todo: "(TODO|XXX|FIXME):?" + + - comment: + start: "/\\*\\*" + end: "\\*/" + rules: + - todo: "(TODO|XXX|FIXME):?"