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 /////////////////////////////////////////////////////////////////////