| 1 |
" Vim highlighting for PyOpenCL |
| 2 |
" ----------------------------- |
| 3 |
" |
| 4 |
" (C) Andreas Kloeckner 2011, MIT license |
| 5 |
" |
| 6 |
" Uses parts of mako.vim by Armin Ronacher. |
| 7 |
" |
| 8 |
" Installation: |
| 9 |
" Just drop this file into ~/.vim/syntax/pyopencl.vim |
| 10 |
" |
| 11 |
" Then do |
| 12 |
" :set filetype=pyopencl |
| 13 |
" and use |
| 14 |
" """//CL// ...code...""" |
| 15 |
" for OpenCL code included in your Python file. |
| 16 |
" |
| 17 |
" You may also include a line |
| 18 |
" vim: filetype=pyopencl.python |
| 19 |
" at the end of your file to set the file type automatically. |
| 20 |
" |
| 21 |
" Optional: Install opencl.vim from |
| 22 |
" http://www.vim.org/scripts/script.php?script_id=3157 |
| 23 |
|
| 24 |
runtime! syntax/python.vim |
| 25 |
|
| 26 |
unlet b:current_syntax |
| 27 |
try |
| 28 |
syntax include @clCode syntax/opencl.vim |
| 29 |
catch |
| 30 |
syntax include @clCode syntax/c.vim |
| 31 |
endtry |
| 32 |
|
| 33 |
unlet b:current_syntax |
| 34 |
syn include @pythonTop syntax/python.vim |
| 35 |
|
| 36 |
" {{{ mako |
| 37 |
|
| 38 |
syn region clmakoLine start="^\s*%" skip="\\$" end="$" |
| 39 |
syn region clmakoVariable start=#\${# end=#}# contains=@pythonTop |
| 40 |
syn region clmakoBlock start=#<%!# end=#%># keepend contains=@pythonTop |
| 41 |
|
| 42 |
syn match clmakoAttributeKey containedin=clmakoTag contained "[a-zA-Z_][a-zA-Z0-9_]*=" |
| 43 |
syn region clmakoAttributeValue containedin=clmakoTag contained start=/"/ skip=/\\"/ end=/"/ |
| 44 |
syn region clmakoAttributeValue containedin=clmakoTag contained start=/'/ skip=/\\'/ end=/'/ |
| 45 |
|
| 46 |
syn region clmakoTag start="</\?%\(def\|call\|page\|include\|namespace\|inherit\|self:[_[:alnum:]]\+\)\>" end="/\?>" |
| 47 |
|
| 48 |
" The C highlighter's paren error detection screws up highlighting of |
| 49 |
" Mako variables in C parens--turn it off. |
| 50 |
|
| 51 |
syn clear cParen |
| 52 |
syn clear cParenError |
| 53 |
if !exists("c_no_bracket_error") |
| 54 |
syn clear cBracket |
| 55 |
endif |
| 56 |
|
| 57 |
syn cluster clmakoCode contains=clmakoLine,clmakoVariable,clmakoBlock,clmakoTag |
| 58 |
|
| 59 |
hi link clmakoLine Preproc |
| 60 |
hi link clmakoVariable Preproc |
| 61 |
hi link clmakoBlock Preproc |
| 62 |
hi link clmakoTag Define |
| 63 |
hi link clmakoAttributeKey String |
| 64 |
hi link clmakoAttributeValue String |
| 65 |
|
| 66 |
" }}} |
| 67 |
|
| 68 |
syn region pythonCLString |
| 69 |
\ start=+[uU]\=\z('''\|"""\)//CL\(:[a-zA-Z_0-9]\+\)\?//+ end="\z1" keepend |
| 70 |
\ contains=@clCode,@clmakoCode |
| 71 |
|
| 72 |
syn region pythonCLRawString |
| 73 |
\ start=+[uU]\=[rR]\z('''\|"""\)//CL\(:[a-zA-Z_0-9]\+\)\?//+ end="\z1" keepend |
| 74 |
\ contains=@clCode,@clmakoCode |
| 75 |
|
| 76 |
" Uncomment if you still want the code highlighted as a string. |
| 77 |
" hi link pythonCLString String |
| 78 |
" hi link pythonCLRawString String |
| 79 |
|
| 80 |
syntax sync fromstart |
| 81 |
|
| 82 |
let b:current_syntax = "pyopencl" |
| 83 |
|
| 84 |
" vim: foldmethod=marker |