diff options
Diffstat (limited to 'syntax/hcl.vim')
-rw-r--r-- | syntax/hcl.vim | 112 |
1 files changed, 70 insertions, 42 deletions
diff --git a/syntax/hcl.vim b/syntax/hcl.vim index d11c031b..7b6ab441 100644 --- a/syntax/hcl.vim +++ b/syntax/hcl.vim @@ -1,48 +1,76 @@ -if polyglot#init#is_disabled(expand('<sfile>:p'), 'hcl', 'syntax/hcl.vim') +if polyglot#init#is_disabled(expand('<sfile>:p'), 'terraform', 'syntax/hcl.vim') finish endif - -if exists("b:current_syntax") +" Forked from Larry Gilbert's syntax file +" github.com/L2G/vim-syntax-terraform +if exists('b:current_syntax') finish endif -syn match hclEqual '=' -syn match hclSimpleString '"[^\"]*"' -syn region hclComment display oneline start='\%\(^\|\s\)#' end='$' -syn region hclComment display oneline start='\%\(^\|\s\)//' end='$' -syn region hclInterpolation display oneline start='(' end=')' contains=hclInterpolation,hclSimpleString -syn region hclSmartString display oneline start='"' end='"\s*$' contains=hclInterpolation - -syn keyword hclRootKeywords variable provider resource nextgroup=hclString,hclString skipwhite -syn keyword hclRootKeywords default nextgroup=hclEquals skipwhite - - -syn keyword hclAwsResourcesKeywords availability_zones desired_capacity force_delete health_check_grace_period health_check_type launch_configuration load_balancers max_size min_size name vpc_zone_identifier nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords allocated_storage availability_zone backup_retention_period backup_window db_subnet_group_name engine engine_version final_snapshot_identifier identifier instance_class iops maintenance_window multi_az name password port publicly_accessible security_group_names skip_final_snapshot username vpc_security_group_ids nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords cidr description ingress name security_group_id security_group_name security_group_owner_id source_security_group_id nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords description name subnet_ids nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords instance vpc nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords availability_zones health_check healthy_threshold instance_port instance_protocol instances internal interval lb_port lb_protocol listener name security_groups ssl_certificate_id subnets target timeout unhealthy_threshold nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords ami associate_public_ip_address availability_zone ebs_optimized iam_instance_profile instance_type key_name private_ip security_groups source_dest_check subnet_id tags user_data nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords vpc_id nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords iam_instance_profile image_id instance_type key_name name name_prefix security_groups user_data nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords name records ttl type zone_id nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords name nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords route_table_id subnet_id nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords cidr_block gateway_id instance_id route vpc_id nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords acl bucket nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords cidr_blocks description from_port ingress name owner_id protocol security_groups self tags to_port vpc_id nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords availability_zone- cidr_block map_public_ip_on_launch vpc_id nextgroup=hclEquals,hclString skipwhite -syn keyword hclAwsResourcesKeywords cidr_block enable_dns_hostnames enable_dns_support tags nextgroup=hclEquals,hclString skipwhite - - -hi def link hclComment Comment -hi def link hclEqual Operator -hi def link hclRootKeywords Statement -hi def link hclAwsResourcesKeywords Type -hi def link hclSmartString String -hi def link hclInterpolation String -hi def link hclSimpleString PreProc - -let b:current_syntax = "hcl" +let s:cpo_save = &cpoptions +set cpoptions&vim + +" Identifiers are made up of alphanumeric characters, underscores, and +" hyphens. +if has('patch-7.4.1142') + syn iskeyword a-z,A-Z,48-57,_,- +endif + +syn case match + +" A block is introduced by a type, some number of labels - which are either +" strings or identifiers - and an opening curly brace. Match the type. +syn match hclBlockType /^\s*\zs\K\k*\ze\s\+\(\("\K\k*"\|\K\k*\)\s\+\)*{/ + +" An attribute name is an identifier followed by an equals sign. +syn match hclAttributeAssignment /\(\K\k*\.\)*\K\k*\s\+=\s/ contains=hclAttributeName +syn match hclAttributeName /\<\K\k*\>/ contained + +syn keyword hclValueBool true false + +syn keyword hclTodo contained TODO FIXME XXX BUG +syn region hclComment start="/\*" end="\*/" contains=hclTodo,@Spell +syn region hclComment start="#" end="$" contains=hclTodo,@Spell +syn region hclComment start="//" end="$" contains=hclTodo,@Spell + +""" misc. +syn match hclValueDec "\<[0-9]\+\([kKmMgG]b\?\)\?\>" +syn match hclValueHexaDec "\<0x[0-9a-f]\+\([kKmMgG]b\?\)\?\>" +syn match hclBraces "[\[\]]" + +""" skip \" and \\ in strings. +syn region hclValueString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=hclStringInterp +syn region hclStringInterp matchgroup=hclBraces start=/\(^\|[^$]\)\$\zs{/ end=/}/ contained contains=ALLBUT,hclAttributeName +syn region hclHereDocText start=/<<-\?\z([a-z0-9A-Z]\+\)/ end=/^\s*\z1/ contains=hclStringInterp + +"" Functions. +syn match hclFunction "[a-z0-9]\+(\@=" + +""" HCL2 +syn keyword hclRepeat for in +syn keyword hclConditional if +syn keyword hclValueNull null + +" enable block folding +syn region hclBlockBody matchgroup=hclBraces start="{" end="}" fold transparent + +hi def link hclComment Comment +hi def link hclTodo Todo +hi def link hclBraces Delimiter +hi def link hclAttributeName Identifier +hi def link hclBlockType Type +hi def link hclValueBool Boolean +hi def link hclValueDec Number +hi def link hclValueHexaDec Number +hi def link hclValueString String +hi def link hclHereDocText String +hi def link hclFunction Function +hi def link hclRepeat Repeat +hi def link hclConditional Conditional +hi def link hclValueNull Constant + +let b:current_syntax = 'hcl' + +let &cpoptions = s:cpo_save +unlet s:cpo_save |