vim: update syntax for strings
[nit.git] / misc / vim / syntax / nit.vim
1 " Vim syntax file
2 " Language:     Nit
3 " Maintainer:   Jean Privat <jean@pryen.org>
4
5 " This file is part of NIT ( http://www.nitlanguage.org ).
6 "
7 " Copyright 2009 Jean Privat <jean@pryen.org>
8 "
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
12 "
13 "     http://www.apache.org/licenses/LICENSE-2.0
14 "
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.
20
21 if !exists("main_syntax")
22   if version < 600
23     syntax clear
24   elseif exists("b:current_syntax")
25     finish
26   endif
27   " we define it here so that included files can test for it
28   let main_syntax='nit'
29 endif
30
31 " Expression Substitution and Backslash Notation
32 syn match NITExprSubstError "{\|}" contained
33 syn match NITExprSubst "\\." contained
34 syn match NITExprSubst "{\([^}]\|\n\)*}" contained
35
36 syn match NITExprSubstLong "\\." contained
37 syn match NITExprSubstLong "{*\zs{{{\([^}]\|\n\)*}}}\ze}*" contained
38
39 " Numbers and ASCII Codes
40 syn match NITNumber "\<\(\d\+\.\d\+\|\d\+\)\>"
41
42 " Identifiers
43 syn match NITClass              "\<\u\w*"
44 syn match NITAttribute          "\<_\h\w*"
45
46 " Literal strings
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="\\\\\|\\'"
50
51 " Labels
52 syn match NITLabel "\<label \h\w*"
53
54 " Closures
55 syn match NITClosure "!\h\w*"
56
57 " Fallback highlight keywords
58 syn match NITNull "\<\(null\)\>"
59 syn match NITControl "\<\(init\|end\|not null\|not\|var\|do\|then\|else\|loop\)\>"
60 syn match NITKeyword "\<\(super\)\>"
61 " Unmatchning error
62 syn match Error "\<end\>"
63
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=ALL 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*\ze_" 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
72
73 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>\ze\s*\(#\|$\)" matchgroup=NITControl end="^\s*\<\(end\|\zeelse\|\ze!\)\>" contains=ALLBUT,NITTypeDecl,NITAttrDecl,NITInitDecl
74 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>" matchgroup=NITControl end="\<end\>" oneline
75
76 if !exists("NIT_minlines")
77         let NIT_minlines = 50
78 endif
79 exec "syn sync minlines=" . NIT_minlines
80
81 " Comments and Documentation
82 syn match  NITSharpBang "\%^#!.*"
83 syn match  NITComment   "#.*" contains=NITTodo
84
85 " Keywords
86 syn keyword NITKeyword   is abstract intern new
87 syn keyword NITDefine    private public protected intrude readable writable redef
88 syn keyword NITControl   if while for assert and or in as isa once break continue return abort
89 syn keyword NITClass     nullable
90 syn keyword NITInclude   special
91 syn keyword NITTodo      FIXME NOTE TODO XXX contained
92 syn keyword NITBoolean   true false
93 syn keyword NITSelf      self
94
95 " Define the default highlighting.
96 hi def link NITDefine                   Define
97 hi def link NITModuleDecl               Identifier
98 hi def link NITFunctionDecl             Function
99 hi def link NITTypeDecl                 Function
100 hi def link NITAttrDecl                 Function
101 hi def link NITInitDecl                 Function
102 hi def link NITControl                  Statement
103 hi def link NITLabel                    PreProc
104 hi def link NITInclude                  Include
105 hi def link NITNumber                   Number
106 hi def link NITBoolean                  Boolean
107 hi def link NITNull                     Constant
108 hi def link NITSelf                     Constant
109 hi def link NITClass                    Type
110 hi def link NITAttribute                Identifier
111 hi def link NITClosure                  Function
112 hi def link NITSharpBang                PreProc
113 hi def link NITKeyword                  Keyword
114
115 hi def link NITString                   String
116 hi def link NITStringDelimit            Delimiter
117 hi def link NITExprSubst                Special
118 hi def link NITExprSubstLong            Special
119 hi def link NITExprSubstError           Error
120
121 hi def link NITComment                  Comment
122 hi def link NITTodo                     Todo
123
124 " FFI Section
125 syn match NITFFIDelimiters "\<\(`{\|`}\)\>"
126 hi def link NITFFIDelimiters            Keyword
127 " FFI Python
128 syntax include @FFIPython syntax/python.vim
129 unlet b:current_syntax
130 syn match NITFFILanguage        '"Python"' nextgroup=NITFFIBlockPython skipwhite
131 syn region NITFFIBlockPython matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIPython
132
133 " FFI C (the last one is the default)
134 syntax include @FFIC syntax/c.vim
135 unlet b:current_syntax
136 syn match NITFFILanguage                '"C\(\| header\| body\)"'       nextgroup=NITFFIBlockC skipwhite
137 syn region NITFFIBlockC matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIC
138
139 hi def link NITFFILanguage              Define
140
141 let b:current_syntax = "Nit"