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