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

Add Operator Support to the HCL Lexer #2047

Merged
merged 1 commit into from
May 1, 2024
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
1 change: 1 addition & 0 deletions lib/rouge/lexers/hcl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Hcl < RegexLexer
state :primitives do
rule %r/[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?([kKmMgG]b?)?/, Num::Float
rule %r/[0-9]+([kKmMgG]b?)?/, Num::Integer
rule %r/[-+*\/!%&<>|=:?]/, Operator

rule %r/"/, Str::Double, :dq
rule %r/'/, Str::Single, :sq
Expand Down
14 changes: 14 additions & 0 deletions spec/visual/samples/hcl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ resource "aws_subnet" "main" {
resource "aws_cloudfront_distribution" "s3_distribution" {
aliases = ["www.${replace(var.domain_name, "/\\.$/", "")}"]
}

## operators
locals {
op01 = var.var1 != var.var2 ? var.var1 : var.var2
op02 = var.var1 == var.var2 ? var.var1 : var.var2
op05 = var.var1 < var.var2 ? var.var1 : var.var2
op06 = var.var1 <= var.var2 ? var.var1 : var.var2
op07 = var.var1 > var.var2 ? var.var1 : var.var2
op08 = var.var1 >= var.var2 ? var.var1 : var.var2
op09 = var.var1 && var.var2 ? var.var1 : var.var2
op10 = var.var1 || var.var2 ? var.var1 : var.var2
op11 = !var.var1 ? var.var1 : var.var2
op12 = 1 + 2 * 3 / 4 % 5 - 6
}