Gregory Anders | 150b507 | 2024-09-04 22:19:45 +0200 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: HCL |
| 3 | " Maintainer: Gregory Anders |
| 4 | " Upstream: https://github.com/hashivim/vim-terraform |
| 5 | " Last Change: 2024-09-03 |
| 6 | |
| 7 | if exists('b:current_syntax') |
| 8 | finish |
| 9 | endif |
| 10 | |
| 11 | syn iskeyword a-z,A-Z,48-57,_,- |
| 12 | |
| 13 | syn case match |
| 14 | |
| 15 | " A block is introduced by a type, some number of labels - which are either |
| 16 | " strings or identifiers - and an opening curly brace. Match the type. |
| 17 | syn match hclBlockType /^\s*\zs\K\k*\ze\s\+\(\("\K\k*"\|\K\k*\)\s\+\)*{/ |
| 18 | |
| 19 | " An attribute name is an identifier followed by an equals sign. |
| 20 | syn match hclAttributeAssignment /\(\K\k*\.\)*\K\k*\s\+=\s/ contains=hclAttributeName |
| 21 | syn match hclAttributeName /\<\K\k*\>/ contained |
| 22 | |
| 23 | syn keyword hclValueBool true false |
| 24 | |
| 25 | syn keyword hclTodo contained TODO FIXME XXX BUG |
| 26 | syn region hclComment start="/\*" end="\*/" contains=hclTodo,@Spell |
| 27 | syn region hclComment start="#" end="$" contains=hclTodo,@Spell |
| 28 | syn region hclComment start="//" end="$" contains=hclTodo,@Spell |
| 29 | |
| 30 | """ misc. |
| 31 | syn match hclValueDec "\<[0-9]\+\([kKmMgG]b\?\)\?\>" |
| 32 | syn match hclValueHexaDec "\<0x[0-9a-f]\+\([kKmMgG]b\?\)\?\>" |
| 33 | syn match hclBraces "[\[\]]" |
| 34 | |
| 35 | """ skip \" and \\ in strings. |
| 36 | syn region hclValueString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=hclStringInterp |
| 37 | syn region hclStringInterp matchgroup=hclBraces start=/\(^\|[^$]\)\$\zs{/ end=/}/ contained contains=ALLBUT,hclAttributeName |
| 38 | syn region hclHereDocText start=/<<-\?\z([a-z0-9A-Z]\+\)/ end=/^\s*\z1/ contains=hclStringInterp |
| 39 | |
| 40 | "" Functions. |
| 41 | syn match hclFunction "[a-z0-9]\+(\@=" |
| 42 | |
| 43 | """ HCL2 |
| 44 | syn keyword hclRepeat for in |
| 45 | syn keyword hclConditional if |
| 46 | syn keyword hclValueNull null |
| 47 | |
| 48 | " enable block folding |
| 49 | syn region hclBlockBody matchgroup=hclBraces start="{" end="}" fold transparent |
| 50 | |
| 51 | hi def link hclComment Comment |
| 52 | hi def link hclTodo Todo |
| 53 | hi def link hclBraces Delimiter |
| 54 | hi def link hclAttributeName Identifier |
| 55 | hi def link hclBlockType Type |
| 56 | hi def link hclValueBool Boolean |
| 57 | hi def link hclValueDec Number |
| 58 | hi def link hclValueHexaDec Number |
| 59 | hi def link hclValueString String |
| 60 | hi def link hclHereDocText String |
| 61 | hi def link hclFunction Function |
| 62 | hi def link hclRepeat Repeat |
| 63 | hi def link hclConditional Conditional |
| 64 | hi def link hclValueNull Constant |
| 65 | |
| 66 | let b:current_syntax = 'hcl' |