Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform: Fix class name lexing #2097

Merged
merged 3 commits into from Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions pygments/lexers/configs.py
Expand Up @@ -715,20 +715,15 @@ def heredoc_callback(self, match, ctx):

# e.g. resource "aws_security_group" "allow_tls" {
# e.g. backend "consul" {
(classes_re + r'(\s+)', bygroups(Keyword.Reserved, Whitespace), 'blockname'),
(classes_re + r'(\s+)("[0-9a-zA-Z-_]+")?(\s*)("[0-9a-zA-Z-_]+")(\s+)(\{)',
bygroups(Keyword.Reserved, Whitespace, Name.Class, Whitespace, Name.Variable, Whitespace, Punctuation)),

# here-doc style delimited strings
(
r'(<<-?)\s*([a-zA-Z_]\w*)(.*?\n)',
heredoc_callback,
)
],
'blockname': [
# e.g. resource "aws_security_group" "allow_tls" {
# e.g. backend "consul" {
(r'(\s*)("[0-9a-zA-Z-_]+")?(\s*)("[0-9a-zA-Z-_]+")(\s+)(\{)',
bygroups(Whitespace, Name.Class, Whitespace, Name.Variable, Whitespace, Punctuation)),
],
'identifier': [
(r'\b(var\.[0-9a-zA-Z-_\.\[\]]+)\b', bygroups(Name.Variable)),
(r'\b([0-9a-zA-Z-_\[\]]+\.[0-9a-zA-Z-_\.\[\]]+)\b', bygroups(Name.Variable)),
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/terraform/test_backend.txt
Expand Up @@ -18,7 +18,7 @@ terraform {
'"consul"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'address' Name.Attribute
Expand Down
20 changes: 20 additions & 0 deletions tests/snippets/terraform/test_comment.txt
Expand Up @@ -6,6 +6,9 @@
comment

*/
provider "azurerm" { # (1)
features {}
}

---tokens---
'# Single line comment\n' Comment.Single
Expand Down Expand Up @@ -42,3 +45,20 @@

'*/' Comment.Multiline
'\n' Text.Whitespace

'provider' Keyword.Reserved
' ' Text.Whitespace
'"azurerm"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
' # (1)\n' Comment.Single

' ' Text.Whitespace
'features' Name.Builtin
' ' Text.Whitespace
'{' Punctuation
'}' Punctuation
'\n' Text.Whitespace

'}' Punctuation
' \n' Text.Whitespace
4 changes: 2 additions & 2 deletions tests/snippets/terraform/test_functions.txt
Expand Up @@ -13,7 +13,7 @@ provider "aws" {
'"aws"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'value' Name.Attribute
Expand All @@ -36,7 +36,7 @@ provider "aws" {
'"aws"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'value' Name.Attribute
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/terraform/test_heredoc.txt
Expand Up @@ -13,7 +13,7 @@ resource "local_file" "heredoc" {
'"heredoc"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'content' Name.Attribute
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/terraform/test_module.txt
Expand Up @@ -10,7 +10,7 @@ module "consul" {
'"consul"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'source' Name.Attribute
Expand Down
4 changes: 2 additions & 2 deletions tests/snippets/terraform/test_resource.txt
Expand Up @@ -39,7 +39,7 @@ resource "aws_security_group" "allow_tls" {
'"base_igw"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'vpc_id' Name.Attribute
Expand Down Expand Up @@ -81,7 +81,7 @@ resource "aws_security_group" "allow_tls" {
'"allow_tls"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'name' Name.Attribute
Expand Down
18 changes: 9 additions & 9 deletions tests/snippets/terraform/test_types.txt
Expand Up @@ -17,7 +17,7 @@ variable "set-str" {
'"consul"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'data' Keyword.Reserved
' ' Text.Whitespace
Expand All @@ -26,35 +26,35 @@ variable "set-str" {
'"example"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'module' Keyword.Reserved
' ' Text.Whitespace
'"consul"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'output' Keyword.Reserved
' ' Text.Whitespace
'"instance_ip_addr"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'provider' Keyword.Reserved
' ' Text.Whitespace
'"aws"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'provisioner' Keyword.Reserved
' ' Text.Whitespace
'"local-exec"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'resource' Keyword.Reserved
' ' Text.Whitespace
Expand All @@ -63,21 +63,21 @@ variable "set-str" {
'"base_igw"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'variable' Keyword.Reserved
' ' Text.Whitespace
'"aws_region"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

'variable' Keyword.Reserved
' ' Text.Whitespace
'"set-str"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'type' Name.Attribute
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/terraform/test_variable_declaration.txt
Expand Up @@ -11,7 +11,7 @@ variable "aws_region" {
'"aws_region"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'description' Name.Attribute
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/terraform/test_variable_read.txt
Expand Up @@ -9,7 +9,7 @@ provider "aws" {
'"aws"' Name.Variable
' ' Text.Whitespace
'{' Punctuation
'\n' Text
'\n' Text.Whitespace

' ' Text.Whitespace
'region' Name.Attribute
Expand Down