Vim syntax update: highlight the 'def' as a Statement, and add highlighting of the...
[bitbake.git] / contrib / vim / syntax / bb.vim
1 " Vim syntax file
2 "
3 " Language:     BitBake
4 " Maintainer:   Chris Larson <kergoth@handhelds.org>
5 " Filenames:    *.bb, *.bbclass
6
7 if version < 600
8   syntax clear
9 elseif exists("b:current_syntax")
10   finish
11 endif
12
13 syn case match
14
15 syn match bbComment             "^#.*$" display contains=bbTodo
16 syn keyword bbTodo              TODO FIXME XXX contained
17 syn match bbDelimiter           "[(){}=]" contained
18 syn match bbQuote               /['"]/ contained
19
20 "syn region bbString            matchgroup=bbQuote start=/"/ skip=/\\$/ excludenl end=/"/ keepend contains=bbTodo
21 "syn region bbString            matchgroup=bbQuote start=/'/ skip=/\\$/ excludenl end=/'/ keepend contains=bbTodo
22 syn region bbString             matchgroup=bbQuote start=/"/ skip=/\\$/ excludenl end=/"/ contained keepend contains=bbTodo
23 syn region bbString             matchgroup=bbQuote start=/'/ skip=/\\$/ excludenl end=/'/ contained keepend contains=bbTodo
24
25 " First attempt:
26 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
27 " syn region bbPythonFuncRegion start="^python\s\+\w\+\s*()\s*{" end="^}$" keepend contains=bbPythonFuncDef
28 " syn match bbPythonFuncDef     "^python\s\+\w\+\s*()\s*{" contained contains=bbPythonFlag
29 " hi def link bbPythonFuncRegion        Comment
30 " hi def link bbPythonFlag      Type
31
32 " Second attempt:
33 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
34 " syn match bbPythonFuncDef     "^python\s\+\w\+\s*()\s*{" contained contains=bbPythonFlag,bbFunction,bbDelimiter
35 " syn region bbPythonFuncRegion start="^python\s\+\w\+\s*()\s*{" end="^}$" keepend contains=bbPythonFuncDef,bbDelimiter
36 " hi def link bbPythonFuncRegion        Comment
37 " hi def link bbPythonFlag      Type
38
39 " Third attempt:
40 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
41 " syn match bbPythonFuncDef     "^\(python\s\+\w\+\s*()\s*\)\({\)\@=" contains=bbPythonFlag,bbFunction,bbDelimiter nextgroup=bbPythonFuncRegion
42 " syn region bbPythonFuncRegion matchgroup=bbDelimiter start="{" end="^}$" keepend contained
43 " hi def link bbPythonFuncRegion        Comment
44 " hi def link bbPythonFlag      Type
45
46 " BitBake variable metadata
47 syn match bbVarDef              "^\([a-zA-Z0-9\-_]\+\)\s*\(=\)\@=" contains=bbIdentifier nextgroup=bbVarEq
48 syn match bbIdentifier          "[a-zA-Z0-9\-_]\+" display contained
49 "syn keyword bbVarEq    = display contained nextgroup=bbVarValue
50 syn match bbVarEq               "=" contained contains=bbOperator nextgroup=bbVarValue
51 syn match bbVarValue            ".*$" contained contains=bbString
52
53 " Functions!
54 syn match bbFunction    "\h\w*" display contained
55
56 " BitBake python metadata
57 syn include @python syntax/python.vim
58 if exists("b:current_syntax")
59   unlet b:current_syntax
60 endif
61
62 syn keyword bbPythonFlag        python contained nextgroup=bbFunction
63 syn match bbPythonFuncDef       "^\(python\s\+\w\+\s*()\s*\)\({\)\@=" contains=bbPythonFlag,bbFunction,bbDelimiter nextgroup=bbPythonFuncRegion
64 syn region bbPythonFuncRegion   matchgroup=bbDelimiter start="{" end="^}$" keepend contained contains=@python
65 "hi def link bbPythonFuncRegion Comment
66
67 " BitBake shell metadata
68 syn include @shell syntax/sh.vim
69 if exists("b:current_syntax")
70   unlet b:current_syntax
71 endif
72
73 syn match bbShellFuncDef        "^\(\w\+\)\(python\)\@<!\(\s*()\s*\)\({\)\@=" contains=bbFunction,bbDelimiter nextgroup=bbShellFuncRegion
74 syn region bbShellFuncRegion    matchgroup=bbDelimiter start="{" end="^}$" keepend contained contains=@shell
75 "hi def link bbShellFuncRegion  Comment
76
77
78 " BitBake 'def'd python functions
79 syn keyword bbDef       def     contained
80
81 syn match bbDefCmd              "^def" contains=bbDef skipwhite nextgroup=bbDefFunc
82 syn match bbDefFunc             "\w\+" contains=bbFunction contained skipwhite nextgroup=bbDefArgs
83 syn region bbDefArgs            matchgroup=bbDelimiter start="(" end=")" excludenl contained skipwhite keepend contains=bbIdentifier nextgroup=bbDefRegion
84 syn region bbDefRegion          start=":$" end='^$' end='^\(\s\)\@!' contained contains=@python
85
86
87 " BitBake statements
88 syn keyword bbStatement         include inherit addtask addhandler
89
90 hi def link bbDef               Statement
91 hi def link bbPythonFlag        Type
92 hi def link bbStatement         Statement
93 hi def link bbString            String
94 hi def link bbTodo              Todo
95 hi def link bbComment           Comment
96 hi def link bbOperator          Operator
97 hi def link bbError             Error
98 hi def link bbFunction          Function
99 hi def link bbDelimiter         Delimiter
100 hi def link bbIdentifier        Identifier
101 hi def link bbQuote             Statement
102 hi def link bbVarEq             Operator
103
104 let b:current_syntax = "bb"