syntax: add 'loop' construction
[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("b:current_syntax")
22         finish
23 endif
24
25 " Expression Substitution and Backslash Notation
26 syn match NITExprSubstError "{\|}" contained
27 syn match NITExprSubst "\\." contained
28 syn match NITExprSubst "{[^}]*}" contained
29
30 " Numbers and ASCII Codes
31 syn match NITNumber "\<\(\d\+\.\d\+\|\d\+\)\>"
32
33 " Identifiers
34 syn match NITClass              "\<\u\w*"
35 syn match NITAttribute          "\<_\h\w*"
36
37 " Literal strings
38 syn region NITString matchgroup=NITStringDelimit start="\"" end="\"" skip="\\\\\|\\\"" contains=NITExprSubst,NITExprSubstError
39 syn region NITString matchgroup=NITStringDelimit start="'"  end="'"  skip="\\\\\|\\'"
40
41 " Labels
42 syn match NITLabel "\<label \h\w*"
43
44 " Closures
45 syn match NITClosure "!\h\w*"
46
47 " Fallback highlight keywords
48 syn match NITNull "\<\(null\)\>"
49 syn match NITControl "\<\(init\|end\|not null\|not\|var\|do\|then\|else\|loop\)\>"
50 " Unmatchning error
51 syn match Error "\<end\>"
52
53 " Declarations, definitions and blocks
54 syn region NITPackageDecl matchgroup=NITDefine start="\<\(import\|package\)\>\s*" matchgroup=NONE end="\ze\(\s\|:\|(\|$\)"  oneline
55 syn region NITClassBlock matchgroup=NITDefine start="\<\(class\|universal\|interface\)\>" matchgroup=NITDefine end="\<end\>" contains=ALL fold
56 syn region NITFunctionDecl matchgroup=NITDefine start="\<fun\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline
57 syn region NITTypeDecl matchgroup=NITDefine start="\<type\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
58 syn region NITAttrDecl matchgroup=NITDefine start="\<var\>\s*\ze_" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
59 syn region NITInitDecl matchgroup=NITDefine start="\<init\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
60
61 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>\ze\s*\(#\|$\)" matchgroup=NITControl end="^\s*\<\(end\|\zeelse\|\ze!\)\>" contains=ALLBUT,NITTypeDecl,NITAttrDecl,NITInitDecl
62 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>" matchgroup=NITControl end="\<end\>" oneline
63
64 if !exists("NIT_minlines")
65         let NIT_minlines = 50
66 endif
67 exec "syn sync minlines=" . NIT_minlines
68
69 " Comments and Documentation
70 syn match  NITSharpBang "\%^#!.*"
71 syn match  NITComment   "#.*" contains=NITTodo
72
73 " Keywords
74 syn keyword NITKeyword   is abstract intern extern super new
75 syn keyword NITDefine    private public protected intrude readable writable redef
76 syn keyword NITControl   if while for assert and or in as isa once break continue return abort
77 syn keyword NITClass     nullable
78 syn keyword NITInclude   special
79 syn keyword NITTodo      FIXME NOTE TODO XXX contained
80 syn keyword NITBoolean   true false
81 syn keyword NITSelf      self
82
83 " Define the default highlighting.
84 hi def link NITDefine                   Define
85 hi def link NITPackageDecl              Identifier
86 hi def link NITFunctionDecl             Function
87 hi def link NITTypeDecl                 Function
88 hi def link NITAttrDecl                 Function
89 hi def link NITInitDecl                 Function
90 hi def link NITControl                  Statement
91 hi def link NITLabel                    PreProc
92 hi def link NITInclude                  Include
93 hi def link NITNumber                   Number
94 hi def link NITBoolean                  Boolean
95 hi def link NITNull                     Constant
96 hi def link NITSelf                     Constant
97 hi def link NITClass                    Type
98 hi def link NITAttribute                Identifier
99 hi def link NITClosure                  Function
100 hi def link NITSharpBang                PreProc
101 hi def link NITKeyword                  Keyword
102
103 hi def link NITString                   String
104 hi def link NITStringDelimit            Delimiter
105 hi def link NITExprSubst                Special
106 hi def link NITExprSubstError           Error
107
108 hi def link NITComment                  Comment
109 hi def link NITTodo                     Todo
110
111 let b:current_syntax = "Nit"