Skip to content

Commit

Permalink
Merge pull request #64 from SublimeText/bugfix/underscore-identifiers
Browse files Browse the repository at this point in the history
Support identifiers starting with an underscore character
  • Loading branch information
FichteFoll authored Aug 7, 2024
2 parents f2d8046 + 46c108a commit dab171f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

---

Expand Down
13 changes: 10 additions & 3 deletions Terraform.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
9 changes: 9 additions & 0 deletions syntax_test_terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
identifier-with-hyphens
# ^^^^^^^^^^^^^^^^^^^^^^^ variable.other.readwrite.terraform

__EOF__
# ^^^^^^^ variable.other.readwrite.terraform

identifier.
// comment
# <- comment
Expand Down Expand Up @@ -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
/////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit dab171f

Please sign in to comment.