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

Support regular expressions in Terraform lexer #1490

Merged
merged 2 commits into from
Apr 9, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/rouge/lexers/terraform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,24 @@ def self.builtins
mixin :expression
end

state :regexps do
rule %r/"\// do
token Str::Delimiter
goto :regexp_inner
end
end

state :regexp_inner do
rule %r/[^"\/\\]+/, Str::Regex
rule %r/\\./, Str::Regex
rule %r/\/"/, Str::Delimiter, :pop!
rule %r/["\/]/, Str::Regex
end

id = /[$a-z_\-][a-z0-9_\-]*/io

state :expression do
mixin :regexps
mixin :primitives
rule %r/\s+/, Text

Expand Down
5 changes: 5 additions & 0 deletions spec/visual/samples/terraform
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ resource "aws_subnet" "main" {
vpc_id = aws_vpc.main.id
fqns = aws_route53_record.cert_validation[*].fqdn
}

## Object with regular expression
resource "aws_cloudfront_distribution" "s3_distribution" {
aliases = ["www.${replace(var.domain_name, "/\\.$/", "")}"]
}