Skip to content
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

Terraform (HCL) (*.tf): new parser #2952

Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ The following parsers have been added:
* SystemVerilog
* SVG *libxml*
* TclOO (see :ref:`The new Tcl parser <tcl>`)
* Terraform (HCL) *optlib*
* TTCN
* Txt2tags
* TypeScript
Expand Down
1 change: 1 addition & 0 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
SystemTapParser, \
TclParser, \
TclOOParser, \
TfParser, \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TerraformParser or TerraFormParser is better.

TexParser, \
TexBeamerParser, \
TTCNParser, \
Expand Down
1 change: 1 addition & 0 deletions makefiles/optlib2c_input.mak
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ OPTLIB2C_INPUT = \
optlib/puppetManifest.ctags \
optlib/scss.ctags \
optlib/systemtap.ctags \
optlib/terraform.ctags \
\
$(NULL)
60 changes: 60 additions & 0 deletions optlib/terraform.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 initializeTfParser (const langType language CTAGS_ATTR_UNUSED)
{
}

extern parserDefinition* TfParser (void)
{
static const char *const extensions [] = {
"tf.tfvars",
NULL
};

static const char *const aliases [] = {
NULL
};

static const char *const patterns [] = {
NULL
};

static tagRegexTable TfTagRegexTable [] = {
{"^[[: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 ("tf");

def->enabled = true;
def->extensions = extensions;
def->patterns = patterns;
def->aliases = aliases;
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
def->tagRegexTable = TfTagRegexTable;
def->tagRegexCount = ARRAY_SIZE(TfTagRegexTable);
def->initialize = initializeTfParser;

return def;
}
28 changes: 28 additions & 0 deletions optlib/terraform.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# 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
Copy link
Member

@masatake masatake Apr 11, 2021

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.

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?

Copy link
Member

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?

#
#  Copyright (c) 2021, <YOUR NAME HERE>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

#
# Changed the name from `terraform` to `tf` so vim will recognise it properly based
# on file extension (*.tf).
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put a URL for the language reference?

--langdef=tf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terraform or TerraformHCL is better. I'm not sure which one is better.
If you are not sure, too, use longer name as I did in "PupppetManifest".

--map-tf=+tf:.tf.tfvars
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be

--map-tf=+.tf
--map-tf=+.tfvars

See https://docs.ctags.io/en/latest/man/ctags.1.html#options for more details.

--regex-tf=/^[[:space:]]*resource[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/r,Resource/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use --kinddef-=... option before using kinds.
https://docs.ctags.io/en/latest/man/ctags-optlib.7.html#options

--regex-tf=/^[[:space:]]*data[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/d,Data/
--regex-tf=/^[[:space:]]*variable[[:space:]]*"([^"]*)"/\1/v,Variable/
--regex-tf=/^[[:space:]]*provider[[:space:]]*"([^"]*)"/\1/p,Provider/
--regex-tf=/^[[:space:]]*module[[:space:]]*"([^"]*)"/\1/m,Module/
--regex-tf=/^[[:space:]]*output[[:space:]]*"([^"]*)"/\1/o,Output/
--regex-tf=/^([a-z0-9_]+)[[:space:]]*=/\1/f,TFVar/

3 changes: 2 additions & 1 deletion win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
<ClCompile Include="..\parsers\systemdunit.c" />
<ClCompile Include="..\parsers\tcl.c" />
<ClCompile Include="..\parsers\tcloo.c" />
<ClCompile Include="..\parsers\terraform.c" />
<ClCompile Include="..\parsers\tex.c" />
<ClCompile Include="..\parsers\tex-beamer.c" />
<ClCompile Include="..\parsers\ttcn.c" />
Expand Down Expand Up @@ -452,4 +453,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About this file, no newline at the of file

5 changes: 4 additions & 1 deletion win32/ctags_vs2013.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@
<ClCompile Include="..\parsers\tcloo.c">
<Filter>Source Files\Parsers</Filter>
</ClCompile>
<ClCompile Include="..\parsers\terraform.c">
<Filter>Source Files\Parsers</Filter>
</ClCompile>
<ClCompile Include="..\parsers\tex.c">
<Filter>Source Files\Parsers</Filter>
</ClCompile>
Expand Down Expand Up @@ -848,4 +851,4 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About this file, no newline at the end of file.