diff --git a/lib/rouge/lexers/hcl.rb b/lib/rouge/lexers/hcl.rb index eb290e7141..55143ea366 100644 --- a/lib/rouge/lexers/hcl.rb +++ b/lib/rouge/lexers/hcl.rb @@ -56,7 +56,7 @@ def self.builtins @builtins ||= %w() end - id = /[$a-z_][a-z0-9_]*/io + id = /[$a-z_\-][a-z0-9_\-]*/io state :root do mixin :comments_and_whitespace @@ -114,6 +114,7 @@ def self.builtins state :hash do mixin :comments_and_whitespace + rule %r/[.,()\\\/*]/, Punctuation rule %r/\=/, Punctuation rule %r/\}/, Punctuation, :pop! @@ -123,7 +124,7 @@ def self.builtins state :array do mixin :comments_and_whitespace - rule %r/,/, Punctuation + rule %r/[.,()\\\/*]/, Punctuation rule %r/\]/, Punctuation, :pop! mixin :root diff --git a/lib/rouge/lexers/terraform.rb b/lib/rouge/lexers/terraform.rb index 8b9545552f..1732b93af9 100644 --- a/lib/rouge/lexers/terraform.rb +++ b/lib/rouge/lexers/terraform.rb @@ -37,14 +37,6 @@ def self.builtins @builtins ||= %w() end - prepend :hash do - rule %r/[.,()*]/, Punctuation - end - - prepend :array do - rule %r/[.,()*]/, Punctuation - end - state :strings do rule %r/\\./, Str::Escape rule %r/\$\{/ do diff --git a/spec/visual/samples/hcl b/spec/visual/samples/hcl index 8ea3e4dcc2..511d04be87 100644 --- a/spec/visual/samples/hcl +++ b/spec/visual/samples/hcl @@ -1 +1,86 @@ -# See Terraform lexer +# Comment + +# Object with no key/value pairs +data "aws_availability_zones" "available" {} + +# Object with single key/value +provider "aws" { + most_recent = false +} + +# Object with various comma-separated values +provider "aws" { + most_recent = false, other_value = null +} + +# Object with various newline-separated values +resource "aws_vpc" "main" { + most_recent = true + cidr_block = "10.10.0.0/16" + region = "${var.aws_region}" + count = 0 + another_num = 3.14 +} + +# Object with interpolated values +resource "aws_subnet" "main" { + count = "${var.az_count}" + cidr_block = "${cidrsubnet(aws_vpc.main.cidr_block, 8, count.index)}" + availability_zone = "${data.aws_availability_zones.available.names[count.index]}" + vpc_id = "${aws_vpc.main.id}" +} + +# Object with nested object +resource "aws_route_table" "r" { + vpc_id = "${aws_vpc.main.id}" + + route { + cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.gw.id}" + } +} + +# Object with list value +resource "aws_autoscaling_group" "app" { + vpc_zone_identifier = ["${aws_subnet.main.*.id}"] +} + +# Object with nested interpolation +data "template_file" "cloud_config" { + template = "${file("${path.module}/cloud-config.yml")}" +} + +# Object with HEREDOC string +resource "aws_iam_role" "ecs_service" { + name = "tf_example_ecs_role" + + assume_role_policy = <