-
Notifications
You must be signed in to change notification settings - Fork 632
Terraform (HCL) (*.tf): new parser #2952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
616c2d1
c78ccef
c4d902e
ca9d8fe
489c04c
7d58baf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Generated by ./misc/optlib2c from optlib/terraform.ctags, Don't edit this manually. | ||
*/ | ||
#include "general.h" | ||
#include "parse.h" | ||
#include "routines.h" | ||
#include "field.h" | ||
#include "xtag.h" | ||
|
||
|
||
static void initializeTerraformParser (const langType language CTAGS_ATTR_UNUSED) | ||
{ | ||
} | ||
|
||
extern parserDefinition* TerraformParser (void) | ||
{ | ||
static const char *const extensions [] = { | ||
"tf", | ||
"tfvars", | ||
NULL | ||
}; | ||
|
||
static const char *const aliases [] = { | ||
NULL | ||
}; | ||
|
||
static const char *const patterns [] = { | ||
NULL | ||
}; | ||
|
||
static kindDefinition TerraformKindTable [] = { | ||
{ | ||
true, 'r', "Resource", "Terraform Resource", | ||
}, | ||
{ | ||
true, 'd', "Data", "Terraform Data", | ||
}, | ||
{ | ||
true, 'v', "Variable", "Terraform Variable", | ||
}, | ||
{ | ||
true, 'p', "Provider", "Terraform Provider", | ||
}, | ||
{ | ||
true, 'm', "Module", "Terraform Module", | ||
}, | ||
{ | ||
true, 'o', "Output", "Terraform Output", | ||
}, | ||
}; | ||
static tagRegexTable TerraformTagRegexTable [] = { | ||
{"^[[:space:]]*resource[[:space:]]*\"([^\"]*)\"[[:space:]]*\"([^\"]*)\"", "\\2", | ||
"r,Resource", NULL, NULL, false}, | ||
{"^[[:space:]]*data[[:space:]]*\"([^\"]*)\"[[:space:]]*\"([^\"]*)\"", "\\2", | ||
"d,Data", NULL, NULL, false}, | ||
{"^[[:space:]]*variable[[:space:]]*\"([^\"]*)\"", "\\1", | ||
"v,Variable", NULL, NULL, false}, | ||
{"^[[:space:]]*provider[[:space:]]*\"([^\"]*)\"", "\\1", | ||
"p,Provider", NULL, NULL, false}, | ||
{"^[[:space:]]*module[[:space:]]*\"([^\"]*)\"", "\\1", | ||
"m,Module", NULL, NULL, false}, | ||
{"^[[:space:]]*output[[:space:]]*\"([^\"]*)\"", "\\1", | ||
"o,Output", NULL, NULL, false}, | ||
{"^([a-z0-9_]+)[[:space:]]*=", "\\1", | ||
"f,TFVar", NULL, NULL, false}, | ||
}; | ||
|
||
|
||
parserDefinition* const def = parserNew ("terraform"); | ||
|
||
def->enabled = true; | ||
def->extensions = extensions; | ||
def->patterns = patterns; | ||
def->aliases = aliases; | ||
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX; | ||
def->kindTable = TerraformKindTable; | ||
def->kindCount = ARRAY_SIZE(TerraformKindTable); | ||
def->tagRegexTable = TerraformTagRegexTable; | ||
def->tagRegexCount = ARRAY_SIZE(TerraformTagRegexTable); | ||
def->initialize = initializeTerraformParser; | ||
|
||
return def; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# | ||
# terraform.ctags: regex parse for Terraform (HCL). | ||
# | ||
# Author: Antony Southworth <https://github.com/antonysouthworth-halter> | ||
# | ||
# 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 | ||
# | ||
# Changed the name from `terraform` to `tf` so vim will recognise it properly based | ||
# on file extension (*.tf). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the name of the parser must be "tf"? |
||
# | ||
# A notable abscence is `local`, because `locals` are defined inside a block and | ||
# it's way harder to write a good regex for that. | ||
# - https://www.terraform.io/docs/language/values/locals.html | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you put a URL for the language reference? |
||
--langdef=terraform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I forgot writing one thing. A parser that is part of ctags should have Capitalized name. |
||
--map-terraform=+.tf | ||
--map-terraform=+.tfvars | ||
--kinddef-terraform=r,Resource,Terraform Resource | ||
--kinddef-terraform=d,Data,Terraform Data | ||
--kinddef-terraform=v,Variable,Terraform Variable | ||
--kinddef-terraform=p,Provider,Terraform Provider | ||
--kinddef-terraform=m,Module,Terraform Module | ||
--kinddef-terraform=o,Output,Terraform Output | ||
--regex-terraform=/^[[:space:]]*resource[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/r,Resource/ | ||
--regex-terraform=/^[[:space:]]*data[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/d,Data/ | ||
--regex-terraform=/^[[:space:]]*variable[[:space:]]*"([^"]*)"/\1/v,Variable/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. v is already defined with
I don't know well about the syntax of Terraforms. However, I guess a whitespace may be needed after
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is applicable to other lines of |
||
--regex-terraform=/^[[:space:]]*provider[[:space:]]*"([^"]*)"/\1/p,Provider/ | ||
--regex-terraform=/^[[:space:]]*module[[:space:]]*"([^"]*)"/\1/m,Module/ | ||
--regex-terraform=/^[[:space:]]*output[[:space:]]*"([^"]*)"/\1/o,Output/ | ||
--regex-terraform=/^([a-z0-9_]+)[[:space:]]*=/\1/f,TFVar/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you reuse the regex patterns of @juliosueiras's work, ask @juliosueiras to allow to use one's .ctags in GPLv2 or later. Copy & paste the evidence of alowing to use here as comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would I need to paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you fill and paste it at the head of your .ctags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!