Skip to content

Commit

Permalink
TerraformVariables: new parser
Browse files Browse the repository at this point in the history
This parser doesn't have its own kinds.
Instead, this parser emits Terraform parser's "variable"
kind tags with "assigned" role.

ref. https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Mar 31, 2023
1 parent 9186182 commit d3d9dc7
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Tmain/list-map-extensions.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## all|grep LdScript
#LANGUAGE EXTENSION
LdScript lds
LdScript scr
LdScript ld
LdScript ldi
#LANGUAGE EXTENSION
LdScript lds
LdScript scr
LdScript ld
LdScript ldi
## LdScript
#EXTENSION
lds
Expand Down
2 changes: 2 additions & 0 deletions Tmain/list-roles.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ SystemdUnit u/unit RequiredBy on referred in Required
SystemdUnit u/unit Requires on referred in Requires key
SystemdUnit u/unit WantedBy on referred in WantedBy key
SystemdUnit u/unit Wants on referred in Wants key
Terraform v/variable assigned on assigned in Variable Definitions (.tfvars) files
Tex e/environment used off environment usage introduced by \begin{MyEnv}
Tex i/xinput bibliography on bibliography (.bib) file
Tex i/xinput included on external input file specified with \include
Expand Down Expand Up @@ -221,6 +222,7 @@ SystemdUnit u/unit RequiredBy on referred in Required
SystemdUnit u/unit Requires on referred in Requires key
SystemdUnit u/unit WantedBy on referred in WantedBy key
SystemdUnit u/unit Wants on referred in Wants key
Terraform v/variable assigned on assigned in Variable Definitions (.tfvars) files
Tex e/environment used off environment usage introduced by \begin{MyEnv}
Tex i/xinput bibliography on bibliography (.bib) file
Tex i/xinput included on external input file specified with \include
Expand Down
2 changes: 2 additions & 0 deletions Units/parser-terraform.r/simple-terraform.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
--sort=no
--extras=+r
--fields=+rl
13 changes: 7 additions & 6 deletions Units/parser-terraform.r/simple-terraform.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
aws input.tf /^provider "aws" {$/;" p
events_bus_name input.tf /^variable "events_bus_name" {$/;" v
example_events_bus input.tf /^resource "aws_cloudwatch_event_bus" "example_events_bus" {$/;" r
database input.tf /^module "database" {$/;" m
example_database_password input.tf /^data "aws_ssm_parameter" "example_database_password" {$/;" d
password input.tf /^output "password" {$/;" o
aws input.tf /^provider "aws" {$/;" p language:Terraform roles:def
events_bus_name input.tf /^variable "events_bus_name" {$/;" v language:Terraform roles:def
example_events_bus input.tf /^resource "aws_cloudwatch_event_bus" "example_events_bus" {$/;" r language:Terraform roles:def
database input.tf /^module "database" {$/;" m language:Terraform roles:def
example_database_password input.tf /^data "aws_ssm_parameter" "example_database_password" {$/;" d language:Terraform roles:def
password input.tf /^output "password" {$/;" o language:Terraform roles:def
events_bus_name input-0.tfvars /^events_bus_name = "hyper-connector"$/;" v language:Terraform roles:assigned
1 change: 1 addition & 0 deletions Units/parser-terraform.r/simple-terraform.d/input-0.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
events_bus_name = "hyper-connector"
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ The following parsers have been added:
* SVG *libxml*
* TclOO (see :ref:`The new Tcl parser <tcl>`)
* Terraform (HCL) *optlib*
* TerraformVariables *optlib*
* Thrift *peg/packcc*
* TTCN
* Txt2tags
Expand Down
1 change: 1 addition & 0 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
TclParser, \
TclOOParser, \
TerraformParser, \
TerraformVariablesParser, \
TexParser, \
TexBeamerParser, \
TTCNParser, \
Expand Down
4 changes: 4 additions & 0 deletions optlib/terraform.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ extern parserDefinition* TerraformParser (void)
NULL
};

static roleDefinition TerraformVariableRoleTable [] = {
{ true, "assigned", "assigned in Variable Definitions (.tfvars) files" },
};
static kindDefinition TerraformKindTable [] = {
{
true, 'r', "resource", "resources",
Expand All @@ -36,6 +39,7 @@ extern parserDefinition* TerraformParser (void)
},
{
true, 'v', "variable", "variables",
ATTACH_ROLES(TerraformVariableRoleTable),
},
{
true, 'p', "provider", "providers",
Expand Down
6 changes: 6 additions & 0 deletions optlib/terraform.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
#
# Another notable thing is that this parser doesn't skip /* block comments */.
#
# .tfvars files relates code are moved to TerraformVariables parser.
#
--langdef=Terraform

--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
Expand Down
56 changes: 56 additions & 0 deletions optlib/terraformvariables.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Generated by ./misc/optlib2c from optlib/terraformvariables.ctags, Don't edit this manually.
*/
#include "general.h"
#include "parse.h"
#include "routines.h"
#include "field.h"
#include "xtag.h"
#include "dependency.h"


static void initializeTerraformVariablesParser (const langType language CTAGS_ATTR_UNUSED)
{
}

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

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

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

static tagRegexTable TerraformVariablesTagRegexTable [] = {
{"^([a-z0-9_]+)[[:space:]]*=", "\\1",
"v", "{_role=assigned}{_language=Terraform}", NULL, false},
};

static parserDependency TerraformVariablesDependencies [] = {
[0] = { DEPTYPE_FOREIGNER, "Terraform", NULL },
};

parserDefinition* const def = parserNew ("TerraformVariables");

def->versionCurrent= 0;
def->versionAge = 0;
def->enabled = true;
def->extensions = extensions;
def->patterns = patterns;
def->aliases = aliases;
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
def->tagRegexTable = TerraformVariablesTagRegexTable;
def->tagRegexCount = ARRAY_SIZE(TerraformVariablesTagRegexTable);
def->dependencies = TerraformVariablesDependencies;
def->dependencyCount = ARRAY_SIZE(TerraformVariablesDependencies);
def->initialize = initializeTerraformVariablesParser;

return def;
}
20 changes: 20 additions & 0 deletions optlib/terraformvariables.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright (c) 2021, Julio Tain Sueiras
# Copyright (c) 2023 Masatake YAMATO
# Copyright (c) 2023 Red Hat, Inc.
#
# 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.
#
# The regex pattern is derrived from
# - https://github.com/juliosueiras/vim-terraform-completion/blob/master/ctags/terraform.ctags
#
# This module contains functions to extract language objects for Terraform from
# Terraform Variable Definitions (.tfvars) files.
# See: https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files
#
--langdef=TerraformVariables{_foreignLanguage=Terraform}

--map-TerraformVariables=+.tfvars

--regex-TerraformVariables=/^([a-z0-9_]+)[[:space:]]*=/\1/v/{_role=assigned}{_language=Terraform}
1 change: 1 addition & 0 deletions source.mak
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ OPTLIB2C_INPUT = \
optlib/scss.ctags \
optlib/systemtap.ctags \
optlib/terraform.ctags \
optlib/terraformvariables.ctags \
optlib/yacc.ctags \
\
$(NULL)
Expand Down
1 change: 1 addition & 0 deletions win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
<ClCompile Include="..\optlib\scss.c" />
<ClCompile Include="..\optlib\systemtap.c" />
<ClCompile Include="..\optlib\terraform.c" />
<ClCompile Include="..\optlib\terraformvariables.c" />
<ClCompile Include="..\optlib\yacc.c" />
<ClCompile Include="..\parsers\abaqus.c" />
<ClCompile Include="..\parsers\abc.c" />
Expand Down
3 changes: 3 additions & 0 deletions win32/ctags_vs2013.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@
<ClCompile Include="..\optlib\terraform.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
<ClCompile Include="..\optlib\terraformvariables.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
<ClCompile Include="..\optlib\yacc.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
Expand Down

0 comments on commit d3d9dc7

Please sign in to comment.