Skip to content

Commit

Permalink
Support special escape sequences in Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
tancnle committed Sep 17, 2024
1 parent 173ec77 commit eebba7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rouge/lexers/terraform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def self.builtins

state :strings do
rule %r/\\./, Str::Escape
rule %r/\$\{/ do
token Keyword
rule %r{(\$[\$]*|%[%]*)(\{)} do |m|
groups Str::Escape, Punctuation
push :interpolation
end
end

state :dq do
rule %r/[^\\"\$]+/, Str::Double
rule %r/[^\\"\$%]+/, Str::Double
mixin :strings
rule %r/"/, Str::Double, :pop!
end
Expand All @@ -66,7 +66,7 @@ def self.builtins

state :interpolation do
rule %r/\}/ do
token Keyword
token Punctuation
pop!
end

Expand Down
6 changes: 6 additions & 0 deletions spec/visual/samples/terraform
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ resource "aws_subnet" "main" {
resource "aws_cloudfront_distribution" "s3_distribution" {
aliases = ["www.${replace(var.domain_name, "/\\.$/", "")}"]
}

## Special escape sequences that do not use backslashes
locals {
demo_dollars_1 = "$${local.demo}"
demo_dollars_2 = "%%{for i in items}"
}

0 comments on commit eebba7c

Please sign in to comment.