Skip to content

Commit 67f3244

Browse files
authored
Support special escape sequences in Terraform (rouge-ruby#2073)
1 parent 98febba commit 67f3244

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/rouge/lexers/terraform.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def self.builtins
3939

4040
state :strings do
4141
rule %r/\\./, Str::Escape
42+
rule %r/(\$[\$]+|%[%]+)(\{)/, Str
4243
rule %r/\$\{/ do
43-
token Keyword
44+
token Punctuation
4445
push :interpolation
4546
end
4647
end
@@ -66,7 +67,7 @@ def self.builtins
6667

6768
state :interpolation do
6869
rule %r/\}/ do
69-
token Keyword
70+
token Punctuation
7071
pop!
7172
end
7273

spec/visual/samples/terraform

+15
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,18 @@ resource "aws_subnet" "main" {
8484
resource "aws_cloudfront_distribution" "s3_distribution" {
8585
aliases = ["www.${replace(var.domain_name, "/\\.$/", "")}"]
8686
}
87+
88+
# Directives in string templates
89+
locals {
90+
policy = <<EOT
91+
%{ for ip in aws_instance.example[*].private_ip }
92+
server ${ip}
93+
%{ endfor }
94+
EOT
95+
}
96+
97+
# Special escape sequences that do not use backslashes
98+
locals {
99+
demo_dollars_1 = "$${local.demo}"
100+
demo_dollars_2 = "%%{for i in items}"
101+
}

0 commit comments

Comments
 (0)