Vim syntax update: match anonymous python functions with no specified name.
[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 syn match bbComment             "^#.*$" display contains=bbTodo
20 syn keyword bbTodo              TODO FIXME XXX contained
21 syn match bbDelimiter           "[(){}=]" contained
22 syn match bbQuote               /['"]/ contained
23
24 "syn region bbString            matchgroup=bbQuote start=/"/ skip=/\\$/ excludenl end=/"/ keepend contains=bbTodo
25 "syn region bbString            matchgroup=bbQuote start=/'/ skip=/\\$/ excludenl end=/'/ keepend contains=bbTodo
26 syn region bbString             matchgroup=bbQuote start=/"/ skip=/\\$/ excludenl end=/"/ contained keepend contains=bbTodo
27 syn region bbString             matchgroup=bbQuote start=/'/ skip=/\\$/ excludenl end=/'/ contained keepend contains=bbTodo
28
29 " First attempt:
30 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
31 " syn region bbPythonFuncRegion start="^python\s\+\w\+\s*()\s*{" end="^}$" keepend contains=bbPythonFuncDef
32 " syn match bbPythonFuncDef     "^python\s\+\w\+\s*()\s*{" contained contains=bbPythonFlag
33 " hi def link bbPythonFuncRegion        Comment
34 " hi def link bbPythonFlag      Type
35
36 " Second attempt:
37 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
38 " syn match bbPythonFuncDef     "^python\s\+\w\+\s*()\s*{" contained contains=bbPythonFlag,bbFunction,bbDelimiter
39 " syn region bbPythonFuncRegion start="^python\s\+\w\+\s*()\s*{" end="^}$" keepend contains=bbPythonFuncDef,bbDelimiter
40 " hi def link bbPythonFuncRegion        Comment
41 " hi def link bbPythonFlag      Type
42
43 " Third attempt:
44 " syn keyword bbPythonFlag      python contained nextgroup=bbFunction
45 " syn match bbPythonFuncDef     "^\(python\s\+\w\+\s*()\s*\)\({\)\@=" contains=bbPythonFlag,bbFunction,bbDelimiter nextgroup=bbPythonFuncRegion
46 " syn region bbPythonFuncRegion matchgroup=bbDelimiter start="{" end="^}$" keepend contained
47 " hi def link bbPythonFuncRegion        Comment
48 " hi def link bbPythonFlag      Type
49
50 " BitBake variable metadata
51 syn match bbVarDef              "^\([a-zA-Z0-9\-_]\+\)\s*\(=\)\@=" contains=bbIdentifier nextgroup=bbVarEq
52 syn match bbIdentifier          "[a-zA-Z0-9\-_]\+" display contained
53 "syn keyword bbVarEq    = display contained nextgroup=bbVarValue
54 syn match bbVarEq               "=" contained contains=bbOperator nextgroup=bbVarValue
55 syn match bbVarValue            ".*$" contained contains=bbString
56
57
58 " BitBake variable metadata flags
59 syn match bbVarFlagDef          "^\([a-zA-Z0-9\-_]\+\)\(\[[a-zA-Z0-9\-_]\+\]\)\@=" contains=bbIdentifier nextgroup=bbVarFlagFlag
60 syn region bbVarFlagFlag        matchgroup=bbArrayBrackets start="\[" end="\]\s*\(=\)\@=" keepend excludenl contained contains=bbIdentifier nextgroup=bbVarEq
61 "syn match bbVarFlagFlag                "\[\([a-zA-Z0-9\-_]\+\)\]\s*\(=\)\@=" contains=bbIdentifier nextgroup=bbVarEq
62
63
64 " Functions!
65 syn match bbFunction    "\h\w*" display contained
66
67
68 " BitBake python metadata
69 syn include @python syntax/python.vim
70 if exists("b:current_syntax")
71   unlet b:current_syntax
72 endif
73
74 syn keyword bbPythonFlag        python contained nextgroup=bbFunction
75 syn match bbPythonFuncDef       "^\(python\s\+\)\(\w\+\)\?\(\s*()\s*\)\({\)\@=" contains=bbPythonFlag,bbFunction,bbDelimiter nextgroup=bbPythonFuncRegion
76 syn region bbPythonFuncRegion   matchgroup=bbDelimiter start="{" end="^}$" keepend contained contains=@python
77 "hi def link bbPythonFuncRegion Comment
78
79
80 " BitBake shell metadata
81 syn include @shell syntax/sh.vim
82 if exists("b:current_syntax")
83   unlet b:current_syntax
84 endif
85
86 syn match bbShellFuncDef        "^\(\w\+\)\(python\)\@<!\(\s*()\s*\)\({\)\@=" contains=bbFunction,bbDelimiter nextgroup=bbShellFuncRegion
87 syn region bbShellFuncRegion    matchgroup=bbDelimiter start="{" end="^}$" keepend contained contains=@shell
88 "hi def link bbShellFuncRegion  Comment
89
90
91 " BitBake 'def'd python functions
92 syn keyword bbDef       def     contained
93
94 syn match bbDefCmd              "^def" contains=bbDef skipwhite nextgroup=bbDefFunc
95 syn match bbDefFunc             "\w\+" contains=bbFunction contained skipwhite nextgroup=bbDefArgs
96 syn region bbDefArgs            matchgroup=bbDelimiter start="(" end=")" excludenl contained skipwhite keepend contains=bbIdentifier nextgroup=bbDefRegion
97 syn region bbDefRegion          matchgroup=bbDelimiter start=":$" end='^$' end='^\(\s\)\@!' contained contains=@python
98
99
100 " BitBake statements
101 syn keyword bbStatement         include inherit addtask addhandler
102
103 syn match bbArrayBrackets       "[\[\]]" contained
104 hi def link bbArrayBrackets     Statement
105
106 hi def link bbDef               Statement
107 hi def link bbPythonFlag        Type
108 hi def link bbStatement         Statement
109 hi def link bbString            String
110 hi def link bbTodo              Todo
111 hi def link bbComment           Comment
112 hi def link bbOperator          Operator
113 hi def link bbError             Error
114 hi def link bbFunction          Function
115 hi def link bbDelimiter         Delimiter
116 hi def link bbIdentifier        Identifier
117 hi def link bbQuote             Statement
118 hi def link bbVarEq             Operator
119
120 let b:current_syntax = "bb"