summaryrefslogtreecommitdiffstats
path: root/syntax
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2015-12-17 10:47:00 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2015-12-17 10:49:17 +0100
commitad44c4f7a316e798a9354197b20a80eabf280f1a (patch)
treed68b73b60b73d19bf3e83d8e0f807fbae406cffd /syntax
parent3c56c1c7cd051cc7ac7cea0ad66748d8afe1a3cb (diff)
downloadvim-polyglot-ad44c4f7a316e798a9354197b20a80eabf280f1a.tar.gz
vim-polyglot-ad44c4f7a316e798a9354197b20a80eabf280f1a.zip
Add nix support, closes #97
Diffstat (limited to 'syntax')
-rw-r--r--syntax/nix.vim131
1 files changed, 131 insertions, 0 deletions
diff --git a/syntax/nix.vim b/syntax/nix.vim
new file mode 100644
index 00000000..9a275ea7
--- /dev/null
+++ b/syntax/nix.vim
@@ -0,0 +1,131 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
+
+"
+" Syntax file for Nix
+"
+" TODO:
+" Emphasize :
+" Deemphasize ;
+" Consistent ()
+" rec (red?)
+
+if exists("b:current_syntax")
+ finish
+endif
+
+" Operators
+syn match nixOperator "\V++"
+syn match nixOperator "\V+"
+syn match nixOperator "\V!"
+syn match nixOperator "\V=="
+syn match nixOperator "\V!="
+syn match nixOperator "\V&&"
+syn match nixOperator "\V||"
+syn match nixOperator "\V->"
+
+syn match nixOperator "\V-"
+syn match nixOperator "\V*"
+syn match nixOperator "\V/"
+syn match nixOperator "\V>"
+syn match nixOperator "\V<"
+
+" Keywords
+syn keyword nixKeyword let in or assert inherit null with rec
+syn keyword nixConditional if else then
+syn keyword nixBoolean true false
+
+" Builtins
+syn keyword nixBuiltin builtins abort add attrNames attrValues
+ \ baseNameOf compareVersions concatLists currentSystem deepSeq
+ \ derivation dirOf div elem elemAt filter filterSource fromJSON
+ \ getAttr getEnv hasAttr hashString head import intersectAttrs
+ \ isAttrs isList isFunction isString isInt isBool isNull length
+ \ lessThan listToAttrs map mul parseDrvNames pathExists readDir
+ \ readFile removeAttrs seq stringLength sub substring tail throw
+ \ toFile toJSON toPath toString toXML trace typeOf tryEval
+
+syn match nixpkgs "<nixpkgs>"
+syn match nixSpecialOper "\V@\|;\|,\|?\|..."
+
+" Attribute Lists
+"syn match nixBrace "\v[(){}\[\]]|rec\s*\{"
+syn region nixSet matchgroup=nixBraces start="{" end="}" contains=ALL
+syn region nixRecSet matchgroup=nixBraces start="rec\s*{" end="}" contains=ALL
+syn region nixList matchgroup=nixBraces start="\[" end="\]" contains=ALLBUT,nixAttr
+syn match nixAttr "\v[0-9A-Za-z\-\_]+\ze\s*\=" contained
+
+syn match nixInteger "\v<\d+>"
+
+" Functions
+syn match nixFuncArg "\v\zs\w+\ze\s*:"
+
+" TODO: Exclude ; and other illegal characters
+syn match nixPath "\v\S*/\S+|\S+/\S*"
+
+" This operator is placed after nixPath to override nixPath's highlighting
+syn match nixOperator "\V//"
+
+" Strings
+syn match nixStringIndentedEscapes +'''\|''\${\|''\\n\|''\\r\|''\\t+
+syn match nixStringEscapes +\\"\|\\\${\|\\n\|\\r\|\\t\|\\\\+
+syn region nixStringIndented
+ \ start=+''+
+ \ skip=+'''+
+ \ end=+''+
+ \ contains=nixAntiquotation,nixStringIndentedEscapes
+syn region nixString
+ \ start=+"+
+ \ skip=+\\"+
+ \ end=+"+
+ \ contains=nixAntiquotation,nixStringEscapes
+
+" If this contains nixBrace, it ignores its own closing brace and syntax gets
+" thrown way off contains=ALLBUT,nixBrace
+syn region nixAntiquotation start=+\${+ end=+}+ contains=nixAntiQuotation
+
+" Comments
+syn region nixMultiLineComment start=+/\*+ skip=+\\"+ end=+\*/+ contains=nixTodos
+syn match nixEndOfLineComment "#.*$" contains=nixTodos
+syntax keyword nixTodos TODO XXX FIXME NOTE TODOS contained
+
+" Special (Delimiter
+hi def link nixBraces Delimiter
+hi def link nixpkgs Special
+hi def link nixSpecialOper Special
+hi def link nixStringIndentedEscapes SpecialChar
+hi def link nixStringEscapes SpecialChar
+hi def link nixBuiltin Special
+hi def link nixOperator Operator
+
+" Constants
+hi def link nixBoolean Boolean
+hi def link nixInteger Number
+hi def link nixString String
+hi def link nixStringIndented String
+
+" Comments
+hi def link nixMultiLineComment Comment
+hi def link nixEndOfLineComment Comment
+
+" Identifiers
+hi def link nixConditional Conditional
+hi def link nixKeyword Keyword
+hi def link nixOperator Operator
+hi def link nixException Exception
+hi def link nixAttr Identifier
+hi def link nixFuncArg Identifier
+
+" PreProc
+hi def link nixAntiquotation Macro
+
+" Underlined (html links)
+hi def link nixPath Underlined
+
+" Error
+
+syn sync maxlines=20000
+syn sync minlines=50000
+
+let b:current_syntax = 'nix'
+
+endif