blob: 5e9349ab38e0faf0d509dcc84178667aa974d28d [file] [log] [blame]
Gregory Anders150b5072024-09-04 22:19:45 +02001" 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
7if exists('b:current_syntax')
8 finish
9endif
10
11syn iskeyword a-z,A-Z,48-57,_,-
12
13syn 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.
17syn 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.
20syn match hclAttributeAssignment /\(\K\k*\.\)*\K\k*\s\+=\s/ contains=hclAttributeName
21syn match hclAttributeName /\<\K\k*\>/ contained
22
23syn keyword hclValueBool true false
24
25syn keyword hclTodo contained TODO FIXME XXX BUG
26syn region hclComment start="/\*" end="\*/" contains=hclTodo,@Spell
27syn region hclComment start="#" end="$" contains=hclTodo,@Spell
28syn region hclComment start="//" end="$" contains=hclTodo,@Spell
29
30""" misc.
31syn match hclValueDec "\<[0-9]\+\([kKmMgG]b\?\)\?\>"
32syn match hclValueHexaDec "\<0x[0-9a-f]\+\([kKmMgG]b\?\)\?\>"
33syn match hclBraces "[\[\]]"
34
35""" skip \" and \\ in strings.
36syn region hclValueString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=hclStringInterp
37syn region hclStringInterp matchgroup=hclBraces start=/\(^\|[^$]\)\$\zs{/ end=/}/ contained contains=ALLBUT,hclAttributeName
38syn region hclHereDocText start=/<<-\?\z([a-z0-9A-Z]\+\)/ end=/^\s*\z1/ contains=hclStringInterp
39
40"" Functions.
41syn match hclFunction "[a-z0-9]\+(\@="
42
43""" HCL2
44syn keyword hclRepeat for in
45syn keyword hclConditional if
46syn keyword hclValueNull null
47
48" enable block folding
49syn region hclBlockBody matchgroup=hclBraces start="{" end="}" fold transparent
50
51hi def link hclComment Comment
52hi def link hclTodo Todo
53hi def link hclBraces Delimiter
54hi def link hclAttributeName Identifier
55hi def link hclBlockType Type
56hi def link hclValueBool Boolean
57hi def link hclValueDec Number
58hi def link hclValueHexaDec Number
59hi def link hclValueString String
60hi def link hclHereDocText String
61hi def link hclFunction Function
62hi def link hclRepeat Repeat
63hi def link hclConditional Conditional
64hi def link hclValueNull Constant
65
66let b:current_syntax = 'hcl'