Vim syntax: add a catchall which should flag anything which isn't explicitly matched...
[bitbake.git] / contrib / vim / syntax / bb.vim
1 " Vim syntax file
2 "
3 " Copyright (C) 2004  Chris Larson <kergoth@handhelds.org>
4 " This file is licensed under the MIT license, see COPYING.MIT in
5 " this source distribution for the terms.
6 "
7 " Language:     BitBake
8 " Maintainer:   Chris Larson <kergoth@handhelds.org>
9 " Filenames:    *.bb, *.bbclass
10
11 if version < 600
12   syntax clear
13 elseif exists("b:current_syntax")
14   finish
15 endif
16
17 syn case match
18
19 " Catch incorrect syntax (only matches if nothing else does)
20 syn match bbUnmatched           "."
21
22 syn match bbComment             "^#.*$" display contains=bbTodo
23 syn keyword bbTodo              TODO FIXME XXX contained
24 syn match bbDelimiter           "[(){}=]" contained
25 syn match bbQuote               /['"]/ contained
26
27 "syn region bbString            matchgroup=bbQuote start=/"/ skip=/\\$/ excludenl end=/"/ keepend contains=bbTodo
28 "syn region bbString            matchgroup=bbQuote start=/'/ skip=/\\$/ excludenl end=/'/ keepend contains=bbTodo
29 syn match bbContinue            "\\$"
30 syn region bbString             matchgroup=bbQuote start=/"/ skip=/\\$/ excludenl end=/"/ contained keepend contains=bbTodo,bbContinue,bbVarDeref
31 syn region bbString             matchgroup=bbQuote start=/'/ skip=/\\$/ excludenl end=/'/ contained keepend contains=bbTodo,bbContinue,bbVarDeref
32
33 " First attempt:
34 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
35 " syn region bbPythonFuncRegion start="^python\s\+\w\+\s*()\s*{" end="^}$" keepend contains=bbPythonFuncDef
36 " syn match bbPythonFuncDef     "^python\s\+\w\+\s*()\s*{" contained contains=bbPythonFlag
37 " hi def link bbPythonFuncRegion        Comment
38 " hi def link bbPythonFlag      Type
39
40 " Second attempt:
41 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
42 " syn match bbPythonFuncDef     "^python\s\+\w\+\s*()\s*{" contained contains=bbPythonFlag,bbFunction,bbDelimiter
43 " syn region bbPythonFuncRegion start="^python\s\+\w\+\s*()\s*{" end="^}$" keepend contains=bbPythonFuncDef,bbDelimiter
44 " hi def link bbPythonFuncRegion        Comment
45 " hi def link bbPythonFlag      Type
46
47 " Third attempt:
48 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
49 " syn match bbPythonFuncDef     "^\(python\s\+\w\+\s*()\s*\)\({\)\@=" contains=bbPythonFlag,bbFunction,bbDelimiter nextgroup=bbPythonFuncRegion
50 " syn region bbPythonFuncRegion matchgroup=bbDelimiter start="{" end="^}$" keepend contained
51 " hi def link bbPythonFuncRegion        Comment
52 " hi def link bbPythonFlag      Type
53
54 " BitBake variable metadata
55
56 syn keyword bbExportFlag        export contained nextgroup=bbIdentifier skipwhite
57 syn match bbVarDeref    "${[a-zA-Z0-9\-_\.]\+}" contained
58 syn match bbVarDef              "^\(export\s*\)\?\([a-zA-Z0-9\-_\.]\+\(_[${}a-zA-Z0-9\-_\.]\+\)\?\)\s*\(\(:=\)\|\(+=\)\|\(=+\)\|\(?=\)\|=\)\@=" contains=bbExportFlag,bbIdentifier,bbVarDeref nextgroup=bbVarEq
59
60 syn match bbIdentifier          "[a-zA-Z0-9\-_\.]\+" display contained
61 "syn keyword bbVarEq    = display contained nextgroup=bbVarValue
62 syn match bbVarEq               "\(:=\)\|\(+=\)\|\(=+\)\|\(?=\)\|=" contained nextgroup=bbVarValue
63 syn match bbVarValue            ".*$" contained contains=bbString,bbVarDeref
64
65
66 " BitBake variable metadata flags
67 syn match bbVarFlagDef          "^\([a-zA-Z0-9\-_\.]\+\)\(\[[a-zA-Z0-9\-_\.]\+\]\)\@=" contains=bbIdentifier nextgroup=bbVarFlagFlag
68 syn region bbVarFlagFlag        matchgroup=bbArrayBrackets start="\[" end="\]\s*\(=\)\@=" keepend excludenl contained contains=bbIdentifier nextgroup=bbVarEq
69 "syn match bbVarFlagFlag                "\[\([a-zA-Z0-9\-_\.]\+\)\]\s*\(=\)\@=" contains=bbIdentifier nextgroup=bbVarEq
70
71
72 " Functions!
73 syn match bbFunction    "\h\w*" display contained
74
75
76 " BitBake python metadata
77 syn include @python syntax/python.vim
78 if exists("b:current_syntax")
79   unlet b:current_syntax
80 endif
81
82 syn keyword bbPythonFlag        python contained nextgroup=bbFunction
83 syn match bbPythonFuncDef       "^\(python\s\+\)\(\w\+\)\?\(\s*()\s*\)\({\)\@=" contains=bbPythonFlag,bbFunction,bbDelimiter nextgroup=bbPythonFuncRegion skipwhite
84 syn region bbPythonFuncRegion   matchgroup=bbDelimiter start="{\s*" end="^}\s*$" keepend contained contains=@python
85 "hi def link bbPythonFuncRegion Comment
86
87
88 " BitBake shell metadata
89 syn include @shell syntax/sh.vim
90 if exists("b:current_syntax")
91   unlet b:current_syntax
92 endif
93
94 syn keyword bbFakerootFlag      fakeroot contained nextgroup=bbFunction
95 syn match bbShellFuncDef        "^\(fakeroot\s*\)\?\(\w\+\)\(python\)\@<!\(\s*()\s*\)\({\)\@=" contains=bbFakerootFlag,bbFunction,bbDelimiter nextgroup=bbShellFuncRegion skipwhite
96 syn region bbShellFuncRegion    matchgroup=bbDelimiter start="{\s*" end="^}\s*$" keepend contained contains=@shell
97 "hi def link bbShellFuncRegion  Comment
98
99
100 " BitBake 'def'd python functions
101 syn keyword bbDef       def     contained
102
103 syn match bbDefCmd              "^def" contains=bbDef skipwhite nextgroup=bbDefFunc
104 syn match bbDefFunc             "\w\+" contains=bbFunction contained skipwhite nextgroup=bbDefArgs
105 syn region bbDefArgs            matchgroup=bbDelimiter start="(" end=")" excludenl contained skipwhite keepend contains=bbIdentifier nextgroup=bbDefRegion
106 syn region bbDefRegion          matchgroup=bbDelimiter start=":$" end='^\(\s\|$\)\@!' contained contains=@python
107
108
109 " BitBake statements
110 syn keyword bbStatement         include inherit addtask addhandler EXPORT_FUNCTIONS display contained
111 syn match bbStatementLine       "^\(include\|inherit\|addtask\|addhandler\|EXPORT_FUNCTIONS\)\s\+" contains=bbStatement nextgroup=bbStatementRest
112 syn match bbStatementRest               ".*$" contained contains=bbString,bbVarDeref
113
114 syn match bbArrayBrackets       "[\[\]]" contained
115 hi def link bbArrayBrackets     Statement
116
117 hi def link bbUnmatched         Error
118 hi def link bbVarDeref          String
119 hi def link bbContinue          Special
120 hi def link bbDef               Statement
121 hi def link bbPythonFlag        Type
122 hi def link bbExportFlag        Type
123 hi def link bbFakerootFlag      Type
124 hi def link bbStatement         Statement
125 hi def link bbString            String
126 hi def link bbTodo              Todo
127 hi def link bbComment           Comment
128 hi def link bbOperator          Operator
129 hi def link bbError             Error
130 hi def link bbFunction          Function
131 hi def link bbDelimiter         Delimiter
132 hi def link bbIdentifier        Identifier
133 hi def link bbVarEq             Operator
134
135 hi def link bbQuote             String
136 hi def link bbVarValue          String
137
138 let b:current_syntax = "bb"