hcl.vim (3172B)
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 " License: ISC 7 " 8 " Copyright (c) 2014-2016 Mark Cornick <mark@markcornick.com> 9 " 10 " Permission to use, copy, modify, and/or distribute this software for any purpose 11 " with or without fee is hereby granted, provided that the above copyright notice 12 " and this permission notice appear in all copies. 13 " 14 " THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 15 " REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 " FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 17 " INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 18 " OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 " TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 20 " THIS SOFTWARE. 21 22 if exists('b:current_syntax') 23 finish 24 endif 25 26 syn iskeyword a-z,A-Z,48-57,_,- 27 28 syn case match 29 30 " A block is introduced by a type, some number of labels - which are either 31 " strings or identifiers - and an opening curly brace. Match the type. 32 syn match hclBlockType /^\s*\zs\K\k*\ze\s\+\(\("\K\k*"\|\K\k*\)\s\+\)*{/ 33 34 " An attribute name is an identifier followed by an equals sign. 35 syn match hclAttributeAssignment /\(\K\k*\.\)*\K\k*\s\+=\s/ contains=hclAttributeName 36 syn match hclAttributeName /\<\K\k*\>/ contained 37 38 syn keyword hclValueBool true false 39 40 syn keyword hclTodo contained TODO FIXME XXX BUG 41 syn region hclComment start="/\*" end="\*/" contains=hclTodo,@Spell 42 syn region hclComment start="#" end="$" contains=hclTodo,@Spell 43 syn region hclComment start="//" end="$" contains=hclTodo,@Spell 44 45 """ misc. 46 syn match hclValueDec "\<[0-9]\+\([kKmMgG]b\?\)\?\>" 47 syn match hclValueHexaDec "\<0x[0-9a-f]\+\([kKmMgG]b\?\)\?\>" 48 syn match hclBraces "[\[\]]" 49 50 """ skip \" and \\ in strings. 51 syn region hclValueString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=hclStringInterp 52 syn region hclStringInterp matchgroup=hclBraces start=/\(^\|[^$]\)\$\zs{/ end=/}/ contained contains=ALLBUT,hclAttributeName 53 syn region hclHereDocText start=/<<-\?\z([a-z0-9A-Z]\+\)/ end=/^\s*\z1/ contains=hclStringInterp 54 55 "" Functions. 56 syn match hclFunction "[a-z0-9]\+(\@=" 57 58 """ HCL2 59 syn keyword hclRepeat for in 60 syn keyword hclConditional if 61 syn keyword hclValueNull null 62 63 " enable block folding 64 syn region hclBlockBody matchgroup=hclBraces start="{" end="}" fold transparent 65 66 hi def link hclComment Comment 67 hi def link hclTodo Todo 68 hi def link hclBraces Delimiter 69 hi def link hclAttributeName Identifier 70 hi def link hclBlockType Type 71 hi def link hclValueBool Boolean 72 hi def link hclValueDec Number 73 hi def link hclValueHexaDec Number 74 hi def link hclValueString String 75 hi def link hclHereDocText String 76 hi def link hclFunction Function 77 hi def link hclRepeat Repeat 78 hi def link hclConditional Conditional 79 hi def link hclValueNull Constant 80 81 let b:current_syntax = 'hcl'