#
# terraform.ctags: regex parse for Terraform (HCL).
#
# Copyright (c) 2021, Julio Tain Sueiras
# Copyright (c) 2021, Antony Southworth
#
# Antony Southworth adapted Julio's code to Universal Ctags.
#
# This source code is released for free distribution under the terms of the
# GNU General Public License version 2 or (at your option) any later version.
#
# Derived from `vim-terraform-completion`:
#   - https://github.com/juliosueiras/vim-terraform-completion/blob/master/ctags/terraform.ctags
#
# About the language:
#   - https://developer.hashicorp.com/terraform/language/syntax/configuration
#
# There ctags regex were re-implemented into multi-table regex to support
# multi-line comments and locals blocks 
#
# Changed the name from `terraform` to `tf` so vim will recognise it properly based
# on file extension (*.tf).
#
# .tfvars files relates code are moved to TerraformVariables parser.
#
--langdef=Terraform{version=1.1}

--map-Terraform=+.tf

--kinddef-Terraform=r,resource,resources
--kinddef-Terraform=d,data,data

--kinddef-Terraform=v,variable,variables
# See https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files
--_roledef-Terraform.v=assigned,assigned in Variable Definitions (.tfvars) files

--kinddef-Terraform=p,provider,providers
--kinddef-Terraform=m,module,modules
--kinddef-Terraform=o,output,output
--kinddef-Terraform=l,local,locals


--_tabledef-Terraform=toplevel
--_tabledef-Terraform=comment
--_tabledef-Terraform=locals
--_tabledef-Terraform=multicomment


--_mtable-regex-Terraform=toplevel/(\#|\/\/)//{tenter=comment}
--_mtable-regex-Terraform=toplevel/\/\*//{tenter=multicomment}
--_mtable-regex-Terraform=toplevel/locals[[:space:]]*\{//{tenter=locals}
--_mtable-regex-Terraform=toplevel/^resource[[:space:]]"([^"]+)"[[:space:]]"([^"]+)"/\2/r/
--_mtable-regex-Terraform=toplevel/^data[[:space:]]"([^"]+)"[[:space:]]"([^"]+)"/\2/d/
--_mtable-regex-Terraform=toplevel/^variable[[:space:]]"([^"]+)"/\1/v/
--_mtable-regex-Terraform=toplevel/^provider[[:space:]]"([^"]+)"/\1/p/
--_mtable-regex-Terraform=toplevel/^module[[:space:]]"([^"]+)"/\1/m/
--_mtable-regex-Terraform=toplevel/^output[[:space:]]"([^"]+)"/\1/o/
--_mtable-regex-Terraform=toplevel/.//

--_mtable-regex-Terraform=comment/[^\n]+//
--_mtable-regex-Terraform=comment/\n//{tleave}
--_mtable-regex-Terraform=comment/.//

--_mtable-regex-Terraform=multicomment/\*\///{tleave}
--_mtable-regex-Terraform=multicomment/.//

--_mtable-regex-Terraform=locals/\}//{tleave}
--_mtable-regex-Terraform=locals/\{//{tenter=locals}
--_mtable-regex-Terraform=locals/(\#|\/\/)//{tenter=comment}
--_mtable-regex-Terraform=locals/\/\*//{tenter=multicomment}
--_mtable-regex-Terraform=locals/([a-z0-9_]+)+[[:space:]]*=[[:space:]]+/\1/l/
--_mtable-regex-Terraform=locals/.//
