-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 TODO: * This should be rewritten in optlib like: --langdef=TerraformVariables{_foreign=Terraform} --map-TerraformVariables=.tfvars --regex-TerraformVariables=/^([a-z0-9_]+)[[:space:]]*=/\1/v/{_role=assigned}{_lang=Terraform} * Introduce "indexer:" or "parser:" fields. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
- Loading branch information
Showing
10 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
--sort=no | ||
--extras=+r | ||
--fields=+r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 roles:def | ||
events_bus_name input.tf /^variable "events_bus_name" {$/;" v roles:def | ||
example_events_bus input.tf /^resource "aws_cloudwatch_event_bus" "example_events_bus" {$/;" r roles:def | ||
database input.tf /^module "database" {$/;" m roles:def | ||
example_database_password input.tf /^data "aws_ssm_parameter" "example_database_password" {$/;" d roles:def | ||
password input.tf /^output "password" {$/;" o roles:def | ||
events_bus_name input-0.tfvars /^events_bus_name = "hyper-connector"$/;" v roles:assigned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
events_bus_name = "hyper-connector" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
#include "general.h" /* must always come first */ | ||
|
||
#include <regex.h> | ||
|
||
#include "debug.h" | ||
#include "entry.h" | ||
#include "parse.h" | ||
#include "read.h" | ||
|
||
#include "dependency.h" | ||
|
||
struct terraformVariablesCtx { | ||
langType terraformLang; | ||
int variableKindIndex; | ||
int assignedRoleIndex; | ||
}; | ||
|
||
static void findTerraformVariablesTags (void) | ||
{ | ||
findRegexTags (); | ||
} | ||
|
||
static bool found_tag_cb (const char *line, | ||
const regexMatch *matches, | ||
unsigned int count, | ||
void *userData) | ||
{ | ||
if (count >0) | ||
{ | ||
tagEntryInfo e; | ||
struct terraformVariablesCtx *ctx = userData; | ||
|
||
vString *name = vStringNew (); | ||
vStringNCopyS (name, line + matches[1].start, matches[1].length); | ||
initForeignRefTagEntry(&e, vStringValue (name), ctx->terraformLang, | ||
ctx->variableKindIndex, ctx->assignedRoleIndex); | ||
makeTagEntry (&e); | ||
vStringDelete (name); | ||
} | ||
return true; | ||
} | ||
|
||
static void initializeTerraformVariablesParser (langType language) | ||
{ | ||
static struct terraformVariablesCtx ctx; | ||
kindDefinition *kdef; | ||
roleDefinition *rdef; | ||
|
||
ctx.terraformLang = getNamedLanguage("Terraform", 0); | ||
Assert(ctx.terraformLang != LANG_IGNORE); | ||
kdef = getLanguageKindForName (ctx.terraformLang, "variable"); | ||
Assert(kdef); | ||
ctx.variableKindIndex = kdef->id; | ||
rdef = getLanguageRoleForName (ctx.terraformLang, ctx.variableKindIndex, | ||
"assigned"); | ||
Assert(rdef); | ||
ctx.assignedRoleIndex = rdef->id; | ||
|
||
addLanguageCallbackRegex (language, "^([a-z0-9_]+)[[:space:]]*=", | ||
"", found_tag_cb, NULL, &ctx); | ||
} | ||
|
||
extern parserDefinition* TerraformVariablesParser (void) | ||
{ | ||
static const char *const extensions [] = { "tfvars", NULL }; | ||
parserDefinition* const def = parserNew ("TerraformVariables"); | ||
|
||
static parserDependency dependencies [] = { | ||
[0] = { DEPTYPE_FOREIGNER, "Terraform", NULL }, | ||
}; | ||
|
||
def->extensions = extensions; | ||
def->dependencies = dependencies; | ||
def->dependencyCount = ARRAY_SIZE (dependencies); | ||
def->parser = findTerraformVariablesTags; | ||
def->method = METHOD_REGEX; | ||
def->initialize = initializeTerraformVariablesParser; | ||
return def; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters