From 46c108aedbc1ed1d79a110706187cf6470201219 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Wed, 7 Aug 2024 13:48:21 +0200 Subject: [PATCH] Support identifiers starting with an underscore character Fixes #43 --- CHANGELOG.md | 1 + Terraform.sublime-syntax | 13 ++++++++++--- syntax_test_terraform.tf | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc50e2b..63064ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - Improved matching of identifiers by adding a scope and properly recognizing hyphens. +- Support identifiers starting with an underscore character (#43). --- diff --git a/Terraform.sublime-syntax b/Terraform.sublime-syntax index dc4c3ac..b3419e5 100644 --- a/Terraform.sublime-syntax +++ b/Terraform.sublime-syntax @@ -28,10 +28,17 @@ file_extensions: scope: source.terraform variables: - # Identifiers: (UTF-8) (ID_Continue | '-')*; + # Identifiers: ID_Start (ID_Continue | '-')*; # - # https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#identifiers - identifier: (?:\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\b) + # There is an undocumented exception + # that an underscore character is also accepted + # as an id start character. + # + # https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#identifiers + # http://unicode.org/reports/tr31/#Table_Lexical_Classes_for_Identifiers + ID_Start: '[\p{ID_Start}_]' + ID_Continue: '[\p{ID_Continue}-]' + identifier: (?:{{ID_Start}}{{ID_Continue}}*) # Exponent: "e" or "E" followed by an optional sign # diff --git a/syntax_test_terraform.tf b/syntax_test_terraform.tf index b30789e..6047d43 100644 --- a/syntax_test_terraform.tf +++ b/syntax_test_terraform.tf @@ -274,6 +274,9 @@ identifier-with-hyphens # ^^^^^^^^^^^^^^^^^^^^^^^ variable.other.readwrite.terraform + __EOF__ +# ^^^^^^^ variable.other.readwrite.terraform + identifier. // comment # <- comment @@ -3128,6 +3131,12 @@ END # ^^^^ keyword.control.heredoc.terraform + <<__EOF__ +# ^^ keyword.operator.heredoc.terraform +# ^^^^^^^ keyword.control.heredoc.terraform + aaa + __EOF__ +# ^^^^^^^^ keyword.control.heredoc.terraform ///////////////////////////////////////////////////////////////////// // IMPORTS /////////////////////////////////////////////////////////////////////