1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" method="text" omit-xml-declaration="yes" version="2.0"/>
<xsl:template match="/">
" Vim syntax file
" Language: CP2K input files
" Maintainer: based on work by Alin M Elena available at https://gitorious.org/cp2k-vim
" Revision: 13th of September 2010
" History:
" - XSLT dump and improved syntax highlighting (10.12.2013, Matthias Krack)
" - Folding and automatic indentation added (13.12.2013, Matthias Krack)
" - Remove folding since it overrides user's defaults (18.11.2016, Patrick Seewald)
" CP2K-Version: <xsl:value-of select="/CP2K_INPUT/CP2K_VERSION"/> (<xsl:value-of select="/CP2K_INPUT/COMPILE_REVISION"/>)
if exists("b:current_syntax")
finish
endif
let b:current_syntax = "cp2k"
syn case ignore
"----------------------------------------------------------------/
" CP2K numbers used in blocks
"----------------------------------------------------------------/
" Regular int like number with - + or nothing in front
" e.g. 918, or -49
syn match cp2kNumber '\d\+'
syn match cp2kNumber '[-+]\d\+'
" Floating point number with decimal no E or e (+,-)
" e.g. 0.198781, or -3.141592
syn match cp2kNumber '\d\+\.\d*'
syn match cp2kNumber '[-+]\d\+\.\d*'
" Floating point like number with E and no decimal point (+,-)
" e.g. 3E+9, 3e+09, or -3e+02
syn match cp2kNumber '[-+]\=\d[[:digit:]]*[eE][\-+]\=\d\+'
syn match cp2kNumber '\d[[:digit:]]*[eE][\-+]\=\d\+'
" Floating point like number with E and decimal point (+,-)
" e.g. -3.9188e+09, or 0.9188E-93
syn match cp2kNumber '[-+]\=\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'
syn match cp2kNumber '\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+'
"----------------------------------------------------------------/
" CP2K Boolean entities
"----------------------------------------------------------------/
syn keyword cp2kBool true false T F yes no
"-----------------------------------------------------------------/
" CP2K comments
"-----------------------------------------------------------------/
syn keyword cp2kTodo TODO FIXME NOTE REMARK
syn match cp2kComment "#.*$" contains=cp2kTodo
syn match cp2kComment "!.*$" contains=cp2kTodo
"----------------------------------------------------------------/
" CP2K predefined constants
"----------------------------------------------------------------/
<xsl:for-each-group select="//ITEM" group-by="NAME">
<xsl:sort select="NAME"/>
syn keyword cp2kConstant <xsl:value-of select="NAME"/>
</xsl:for-each-group>
"----------------------------------------------------------------/
" CP2K sections
"----------------------------------------------------------------/
<xsl:for-each-group select="//SECTION" group-by="NAME">
<xsl:sort select="NAME"/>
syn keyword cp2kSection <xsl:value-of select="NAME"/>
</xsl:for-each-group>
syn keyword cp2kSection END
syn keyword cp2kSection ENDIF
syn match cp2kBegSection '^\s*&\w\+' contains=cp2kSection
syn match cp2kEndSection '^\s*&END\s*\w\+' contains=cp2kSection
"----------------------------------------------------------------/
" CP2K default keyword names
"----------------------------------------------------------------/
<xsl:for-each-group select="//KEYWORD" group-by="NAME[@type='default']">
<xsl:sort select="NAME[@type='default']"/>
<xsl:if test="NAME[@type='default']!=''">
syn keyword cp2kKeyword <xsl:value-of select="NAME[@type='default']"/>
</xsl:if>
</xsl:for-each-group>
"----------------------------------------------------------------/
" CP2K alias keyword names
"----------------------------------------------------------------/
<xsl:for-each-group select="//KEYWORD" group-by="NAME[@type='alias'][1]">
<xsl:sort select="NAME[@type='alias'][1]"/>
<xsl:if test="NAME[@type='alias']!=''">
syn keyword cp2kKeyword <xsl:value-of select="NAME[@type='alias']"/>
</xsl:if>
</xsl:for-each-group>
"-----------------------------------------------------------------/
" CP2K preprocessing directives
"-----------------------------------------------------------------/
syn keyword cp2kPreProc ENDIF FFTYPE IF INCLUDE PRINT SET XCTYPE
"-----------------------------------------------------------------/
" CP2K strings
"-----------------------------------------------------------------/
syn region cp2kString matchgroup=cp2kStringDelimiter start=+"+ end=+"+
syn region cp2kString matchgroup=cp2kStringDelimiter start=+'+ end=+'+
syn region cp2kString matchgroup=cp2kStringDelimiter start=+`+ end=+`+
"----------------------------------------------------------------------------/
" Final setup
"----------------------------------------------------------------------------/
setlocal autoindent
setlocal expandtab
setlocal iskeyword+=-
"----------------------------------------------------------------------------/
" Indentation support for CP2K input syntax
"----------------------------------------------------------------------------/
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetCp2kIndent()
setlocal indentkeys+=0=~&END,0=~@ENDIF,0=#,0=@
setlocal nosmartindent
if exists("*GetCp2kIndent")
finish
endif
function! GetCp2kIndent()
let lnum = prevnonblank(v:lnum - 1)
if lnum == 0
return 0
endif
let ind = indent(lnum)
let line = getline(lnum)
if line =~ '^\s*\c\%(&\|@IF\)'
let ind += &shiftwidth
if line =~ '^\s*\c\%(&END\|@ENDIF\)\>'
let ind -= &shiftwidth
endif
endif
let line = getline(v:lnum)
if line =~ '^\s*\c\%(&END\|@ENDIF\)\>'
let ind -= &shiftwidth
endif
return ind
endfunction
"----------------------------------------------------------------------------/
" CP2K keyword highlighting rules
"----------------------------------------------------------------------------/
hi def link cp2kComment Comment
hi def link cp2kConstant Constant
hi def link cp2kTodo Todo
hi def link cp2kBool Boolean
hi def link cp2kNumber Number
hi def link cp2kKeyword Keyword
hi def link cp2kSection Structure
hi def link cp2kPreProc PreProc
hi def link cp2kString String
hi def link cp2kStringDelimiter Delimiter
</xsl:template>
</xsl:stylesheet>
|