3 " Maintainer: Jean Privat <jean@pryen.org>
5 " This file is part of NIT ( http://www.nitlanguage.org ).
7 " Copyright 2009 Jean Privat <jean@pryen.org>
9 " Licensed under the Apache License, Version 2.0 (the "License");
10 " you may not use this file except in compliance with the License.
11 " You may obtain a copy of the License at
13 " http://www.apache.org/licenses/LICENSE-2.0
15 " Unless required by applicable law or agreed to in writing, software
16 " distributed under the License is distributed on an "AS IS" BASIS,
17 " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 " See the License for the specific language governing permissions and
19 " limitations under the License.
21 if !exists("main_syntax")
24 elseif exists("b:current_syntax")
27 " we define it here so that included files can test for it
31 " Expression Substitution and Backslash Notation
32 syn match NITExprSubstError "{\|}" contained
33 syn match NITExprSubst "\\." contained
34 syn match NITExprSubst "{\([^}]\|\n\)*}" contained
36 syn match NITExprSubstLong "\\." contained
37 syn match NITExprSubstLong "{*\zs{{{\([^}]\|\n\)*}}}\ze}*" contained
39 " Numbers and ASCII Codes
40 syn match NITNumber "\<\(\d\+\.\d\+\|\d\+\)\>"
43 syn match NITClass "\<\u\w*"
44 syn match NITAttribute "\<_\h\w*"
47 syn region NITString matchgroup=NITStringDelimit start="\"" end="\"" skip="\\\\\|\\\"" contains=NITExprSubst,NITExprSubstError
48 syn region NITString matchgroup=NITStringDelimit start="\"\"\"" end="\"*\zs\"\"\"" skip="\\\\\|\\\"" contains=NITExprSubstLong
49 syn region NITString matchgroup=NITStringDelimit start="'" end="'" skip="\\\\\|\\'"
52 syn match NITLabel "\<label \h\w*"
55 syn match NITClosure "!\h\w*"
57 " Fallback highlight keywords
58 syn match NITNull "\<\(null\)\>"
59 syn match NITControl "\<\(init\|end\|not null\|not\|var\|do\|then\|else\|loop\|is\)\>"
60 syn match NITKeyword "\<\(super\)\>"
62 syn match Error "\<end\>"
64 " Declarations, definitions and blocks
65 syn region NITModuleDecl matchgroup=NITDefine start="\<\(import\|module\|package\)\>\s*" matchgroup=NONE end="\ze\(\s\|:\|(\|$\)" oneline
66 syn region NITClassBlock matchgroup=NITDefine start="\<\(class\|enum\|universal\|interface\|extern\)\>" matchgroup=NITDefine end="\<end\>" contains=ALLBUT,NITAnnotLine fold
67 syn region NITFunctionDecl matchgroup=NITDefine start="\<fun\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)" oneline
68 syn region NITTypeDecl matchgroup=NITDefine start="\<type\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)" oneline contained containedin=NITClassBlock
69 syn region NITAttrDecl matchgroup=NITDefine start="\<var\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)" oneline contained containedin=NITClassBlock
70 syn region NITInitDecl matchgroup=NITDefine start="\<init\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)" oneline contained containedin=NITClassBlock
71 syn match NITDefine "\<\(super\)\ze\s\+[A-Z]" contained containedin=NITClassBlock
73 syn region NITAnnotBlock matchgroup=NITControl start="\<is\>\ze\s*\(#\|$\)" matchgroup=NITControl end="\(\ze\<do\>\|\<end\>\)" transparent contains=ALL
74 syn match NITAnnotLine "^\s*\zs\w\+" contained containedin=NITAnnotBlock
76 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>\ze\s*\(#\|$\)" matchgroup=NITControl end="^\s*\<\(end\|\zeelse\|\ze!\)\>" contains=ALLBUT,NITTypeDecl,NITAttrDecl,NITInitDecl,NITAnnotLine
77 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>" matchgroup=NITControl end="\<end\>" oneline
78 if !exists("NIT_minlines")
81 exec "syn sync minlines=" . NIT_minlines
83 " Comments and Documentation
84 syn match NITSharpBang "\%^#!.*"
85 syn match NITComment "#.*" contains=NITTodo
88 syn keyword NITKeyword abstract intern new
89 syn keyword NITDefine private public protected intrude readable writable redef
90 syn keyword NITControl if while for assert and or in as isa once break continue return abort
91 syn keyword NITClass nullable
92 syn keyword NITInclude special
93 syn keyword NITTodo FIXME NOTE TODO XXX contained
94 syn keyword NITBoolean true false
95 syn keyword NITSelf self
97 " Define the default highlighting.
98 hi def link NITDefine Define
99 hi def link NITModuleDecl Identifier
100 hi def link NITFunctionDecl Function
101 hi def link NITTypeDecl Function
102 hi def link NITAttrDecl Function
103 hi def link NITInitDecl Function
104 hi def link NITControl Statement
105 hi def link NITAnnotLine Statement
106 hi def link NITLabel PreProc
107 hi def link NITInclude Include
108 hi def link NITNumber Number
109 hi def link NITBoolean Boolean
110 hi def link NITNull Constant
111 hi def link NITSelf Constant
112 hi def link NITClass Type
113 hi def link NITAttribute Identifier
114 hi def link NITClosure Function
115 hi def link NITSharpBang PreProc
116 hi def link NITKeyword Keyword
118 hi def link NITString String
119 hi def link NITStringDelimit Delimiter
120 hi def link NITExprSubst Special
121 hi def link NITExprSubstLong Special
122 hi def link NITExprSubstError Error
124 hi def link NITComment Comment
125 hi def link NITTodo Todo
128 syn match NITFFIDelimiters "\<\(`{\|`}\)\>"
129 hi def link NITFFIDelimiters Keyword
132 syntax include @FFIPython syntax/python.vim
133 unlet b:current_syntax
134 syn match NITFFILanguage '"Python"' nextgroup=NITFFIBlockPython skipwhite
135 syn region NITFFIBlockPython matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIPython
138 syntax include @FFIJava syntax/java.vim
139 unlet b:current_syntax
140 syn match NITFFILanguage '"Java"' nextgroup=NITFFIBlockJava skipwhite
141 syn region NITFFIBlockJava matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIJava
144 syntax include @FFICpp syntax/cpp.vim
145 unlet b:current_syntax
146 syn match NITFFILanguage '"C++"' nextgroup=NITFFIBlockCpp skipwhite
147 syn region NITFFIBlockCpp matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFICpp
149 " FFI C (the last one is the default)
150 syntax include @FFIC syntax/c.vim
151 unlet b:current_syntax
152 syn match NITFFILanguage '"C\(\| header\| body\)"' nextgroup=NITFFIBlockC skipwhite
153 syn region NITFFIBlockC matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIC
155 hi def link NITFFILanguage Define
157 let b:current_syntax = "Nit"