diff options
| author | mo khan <mo@mokhan.ca> | 2021-05-09 19:56:25 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-05-09 19:56:25 -0600 |
| commit | a7f40094fb2f305ec4d05403070e81edda2e350e (patch) | |
| tree | 9aaeb1f16f1be3bcb5e1fc849da1e9546cdbc66b | |
| parent | 90299819eec8848ca52b57a45c14f6eff8b58772 (diff) | |
feat: ignore multi-line comments
| -rw-r--r-- | lib/spandx/terraform/parsers/hcl.rb | 29 | ||||
| -rw-r--r-- | spec/unit/terraform/parsers/hcl_spec.rb | 6 |
2 files changed, 10 insertions, 25 deletions
diff --git a/lib/spandx/terraform/parsers/hcl.rb b/lib/spandx/terraform/parsers/hcl.rb index 2cb397d..94da2ab 100644 --- a/lib/spandx/terraform/parsers/hcl.rb +++ b/lib/spandx/terraform/parsers/hcl.rb @@ -23,8 +23,9 @@ module Spandx rule(:space) { match('\s') } rule(:tilda_wacka) { str('~>') } rule(:version) { number >> dot >> number >> dot >> number >> pre_release? } - rule(:line_comment) { str('#') >> ((str("\n") >> str("\r").maybe).absent? >> any).repeat >> eol } - rule(:whitespace) { (line_comment | space).repeat } + rule(:comment) { (str('#') | str('//')) >> ((str("\n") >> str("\r").maybe).absent? >> any).repeat >> eol } + rule(:multiline_comment) { str('/*') >> (str('*/').absent? >> any).repeat >> str('*/') } + rule(:whitespace) { (multiline_comment | comment | space).repeat } rule(:whitespace?) { whitespace.maybe } rule(:greater_than_or_equal_to) { str('>=') } @@ -92,29 +93,7 @@ module Spandx block.repeat.as(:blocks) end - rule :comment do - str('#') >> match('.').repeat >> eol - line_comment - end - - rule :comments do - comment.repeat - end - - rule :blank_line do - eol - end - - rule :blank_lines do - blank_line.repeat - end - - rule :hcl do - # comments.maybe >> blank_lines.maybe >> blocks - blocks - end - - root(:hcl) + root(:blocks) end end end diff --git a/spec/unit/terraform/parsers/hcl_spec.rb b/spec/unit/terraform/parsers/hcl_spec.rb index 26172e1..fd97a64 100644 --- a/spec/unit/terraform/parsers/hcl_spec.rb +++ b/spec/unit/terraform/parsers/hcl_spec.rb @@ -16,6 +16,11 @@ RSpec.describe Spandx::Terraform::Parsers::Hcl do version = "3.39.0" constraints = "~> 3.27" } + + /* + This is a multi-line comment + that spans multiple lines + */ HCL end @@ -110,4 +115,5 @@ RSpec.describe Spandx::Terraform::Parsers::Hcl do specify { expect(parser.space).to parse(' ') } specify { expect(parser.comment).to parse('# This file is maintained automatically by "terraform init".') } specify { expect(parser.comment).to parse('# Manual edits may be lost in future updates.') } + specify { expect(parser.comment).to parse('// This file is maintained automatically by "terraform init".') } end |
