Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: GitHub noreply@github.com Date: Sun, 23 Feb 2025 17:05:09 UTC Commit: 045d28bfc3b7f0e6a85ef080094e663b208fee0f https://github.com/geany/geany/commit/045d28bfc3b7f0e6a85ef080094e663b208fee...
Log Message: ----------- Add new filetype and ctags parser for Terraform HCL language (#4246)
Modified Paths: -------------- ctags/Makefile.am ctags/optlib/terraform.c data/Makefile.am data/filedefs/filetypes.HCL.conf data/filetype_extensions.conf meson.build src/tagmanager/tm_parser.c src/tagmanager/tm_parser.h src/tagmanager/tm_parsers.h tests/ctags/Makefile.am tests/ctags/simple.tf tests/ctags/simple.tf.tags tests/meson.build
Modified: ctags/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -14,6 +14,7 @@ parsers = \ optlib/forth.c \ optlib/meson.c \ optlib/scss.c \ + optlib/terraform.c \ parsers/cxx/cxx.c \ parsers/cxx/cxx_debug.c \ parsers/cxx/cxx_debug.h \
Modified: ctags/optlib/terraform.c 88 lines changed, 88 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,88 @@ +/* + * 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", + NULL + }; + + static const char *const aliases [] = { + NULL + }; + + static const char *const patterns [] = { + NULL + }; + + static roleDefinition TerraformVariableRoleTable [] = { + { true, "assigned", "assigned in Variable Definitions (.tfvars) files" }, + }; + static kindDefinition TerraformKindTable [] = { + { + true, 'r', "resource", "resources", + }, + { + true, 'd', "data", "data", + }, + { + true, 'v', "variable", "variables", + ATTACH_ROLES(TerraformVariableRoleTable), + }, + { + true, 'p', "provider", "providers", + }, + { + true, 'm', "module", "modules", + }, + { + true, 'o', "output", "output", + }, + }; + static tagRegexTable TerraformTagRegexTable [] = { + {"^[[:space:]]*(#|//)"", "", + "", "{exclusive}", NULL, false}, + {"^resource[[:space:]]"([^"]+)"[[:space:]]"([^"]+)"", "\2", + "r", "{exclusive}", NULL, false}, + {"^data[[:space:]]"([^"]+)"[[:space:]]"([^"]+)"", "\2", + "d", "{exclusive}", NULL, false}, + {"^variable[[:space:]]"([^"]+)"", "\1", + "v", "{exclusive}", NULL, false}, + {"^provider[[:space:]]"([^"]+)"", "\1", + "p", "{exclusive}", NULL, false}, + {"^module[[:space:]]"([^"]+)"", "\1", + "m", "{exclusive}", NULL, false}, + {"^output[[:space:]]"([^"]+)"", "\1", + "o", "{exclusive}", NULL, false}, + }; + + + parserDefinition* const def = parserNew ("Terraform"); + + 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->kindTable = TerraformKindTable; + def->kindCount = ARRAY_SIZE(TerraformKindTable); + def->tagRegexTable = TerraformTagRegexTable; + def->tagRegexCount = ARRAY_SIZE(TerraformTagRegexTable); + def->initialize = initializeTerraformParser; + + return def; +}
Modified: data/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -45,6 +45,7 @@ filetypes_dist = \ filedefs/filetypes.Groovy.conf \ filedefs/filetypes.haskell \ filedefs/filetypes.haxe \ + filedefs/filetypes.HCL.conf \ filedefs/filetypes.html \ filedefs/filetypes.java \ filedefs/filetypes.javascript \
Modified: data/filedefs/filetypes.HCL.conf 39 lines changed, 39 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,39 @@ +# For complete documentation of this file, please see Geany's main documentation + +# This custom filetype uses the HTML styling settings and the Zephir lexer filetype +# for pretty good results. +# Symbols are parsed using a Terraform specific ctags parser. +# For additional autocompletion tags, see https://wiki.geany.org/tags/start#hcl_terraformopentofu_tags. +[styling=HTML] + +[keywords] +# all items must be in one line +php=data locals module output provider resource terraform variable + +[settings=PHP] +extension=tf +lexer_filetype=Zephir +tag_parser=Terraform +comment_single=# +comment_use_indent=true +mime_type= + +[indentation] +#width=2 +# 0 is spaces, 1 is tabs, 2 is tab & spaces +#type=0 + +[build-menu] +FT_00_LB=Plan +FT_00_CM=terraform plan -no-color +FT_00_WD=%d +EX_00_LB=Apply +EX_00_CM=terraform apply +EX_00_WD=%d +EX_01_LB=Destroy +EX_01_CM=terraform destroy +EX_01_WD=%d +FT_01_LB=Init +FT_01_CM=terraform init -no-color +FT_01_WD=%d +error_regex=^.*on (.+) line ([0-9]+)(,|:)
Modified: data/filetype_extensions.conf 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -43,6 +43,7 @@ Graphviz=*.gv;*.dot; Groovy=*.groovy;*.gradle; Haskell=*.hs;*.lhs;*.hs-boot;*.lhs-boot; Haxe=*.hx; +HCL=*.tf;*.tfvars;*.hcl; HTML=*.htm;*.html;*.shtml;*.hta;*.htd;*.htt;*.cfm;*.tpl;*.tmpl;*.vue; Java=*.java;*.jsp; Javascript=*.js;*.cjs;*.mjs;*.jsx;
Modified: meson.build 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -611,6 +611,7 @@ ctags = static_library('ctags', 'ctags/optlib/forth.c', 'ctags/optlib/meson.c', 'ctags/optlib/scss.c', + 'ctags/optlib/terraform.c', 'ctags/parsers/abaqus.c', 'ctags/parsers/abc.c', 'ctags/parsers/ada.c',
Modified: src/tagmanager/tm_parser.c 18 lines changed, 18 insertions(+), 0 deletions(-) =================================================================== @@ -1260,6 +1260,23 @@ static TMParserMapGroup group_SCSS[] = { {N_("ID Selectors"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_local_var_t}, };
+static TMParserMapEntry map_TERRAFORM[] = { + {'r', tm_tag_class_t}, // resource + {'d', tm_tag_enum_t}, // data + {'m', tm_tag_package_t}, // module + {'v', tm_tag_variable_t}, // variable + {'p', tm_tag_macro_t}, // provider + {'o', tm_tag_function_t}, // output +}; +static TMParserMapGroup group_TERRAFORM[] = { + {N_("Resources"), TM_ICON_CLASS, tm_tag_class_t}, + {N_("Data"), TM_ICON_OTHER, tm_tag_enum_t}, + {N_("Modules"), TM_ICON_NAMESPACE, tm_tag_package_t}, + {N_("Variable"), TM_ICON_VAR, tm_tag_variable_t}, + {N_("Providers"), TM_ICON_MACRO, tm_tag_macro_t}, + {N_("Outputs"), TM_ICON_METHOD, tm_tag_function_t}, +}; + typedef struct { TMParserMapEntry *entries; @@ -1339,6 +1356,7 @@ static TMParserMap parser_map[] = { MAP_ENTRY(MESON), MAP_ENTRY(SYSVERILOG), MAP_ENTRY(SCSS), + MAP_ENTRY(TERRAFORM), }; /* make sure the parser map is consistent and complete */ G_STATIC_ASSERT(G_N_ELEMENTS(parser_map) == TM_PARSER_COUNT);
Modified: src/tagmanager/tm_parser.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -146,6 +146,7 @@ enum TM_PARSER_MESON, TM_PARSER_SYSVERILOG, TM_PARSER_SCSS, + TM_PARSER_TERRAFORM, TM_PARSER_COUNT };
Modified: src/tagmanager/tm_parsers.h 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -80,6 +80,7 @@ ForthParser, \ MesonParser, \ SystemVerilogParser, \ - SCSSParser + SCSSParser, \ + TerraformParser
#endif
Modified: tests/ctags/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -331,6 +331,7 @@ test_sources = \ simple.scss \ simple.sh \ simple.tcl \ + simple.tf \ simple.ts \ simple.vala \ simple.zep \
Modified: tests/ctags/simple.tf 29 lines changed, 29 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,29 @@ + + +provider "aws" { + region = "us-east-1" +} + +variable "events_bus_name" { + type = string + default = "hello-world" +} + +# variable "dont_extract_me0" { +// variable "dont_extract_me1" { + +resource "aws_cloudwatch_event_bus" "example_events_bus" { + name = var.events_bus_name +} + +module "database" { + source = "../../modules/database" +} + +data "aws_ssm_parameter" "example_database_password" { + name = "example-database-password" +} + +output "password" { + value = data.aws_ssm_parameter.example_database_password.value +}
Modified: tests/ctags/simple.tf.tags 12 lines changed, 12 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,12 @@ +aws�65536�0 +macro: aws +database�512�0 +package: database +events_bus_name�16384�0 +variable: events_bus_name +example_database_password�2�0 +enum: example_database_password +example_events_bus�1�0 +class: example_events_bus +password�16�0 +function: password
Modified: tests/meson.build 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -328,6 +328,7 @@ ctags_tests = [ 'ctags/simple.scss.tags', 'ctags/simple.sh.tags', 'ctags/simple.tcl.tags', + 'ctags/simple.tf.tags', 'ctags/simple.ts.tags', 'ctags/simple.vala.tags', 'ctags/simple.zep.tags',
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).