diff options
| author | mo khan <mo@mokhan.ca> | 2021-05-09 21:05:08 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-05-09 21:05:08 -0600 |
| commit | 656a431eee93824a30970d440cbf7e7f42c7c83e (patch) | |
| tree | 96c5bab01ddb11e846a59f13322958acd007b07b /lib | |
| parent | a7f40094fb2f305ec4d05403070e81edda2e350e (diff) | |
feat: parse array assignments
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/spandx/terraform/parsers/hcl.rb | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/lib/spandx/terraform/parsers/hcl.rb b/lib/spandx/terraform/parsers/hcl.rb index 94da2ab..6e170fd 100644 --- a/lib/spandx/terraform/parsers/hcl.rb +++ b/lib/spandx/terraform/parsers/hcl.rb @@ -6,39 +6,46 @@ module Spandx class Hcl < Parslet::Parser rule(:alpha) { match['a-zA-Z'] } rule(:assign) { str('=') } + rule(:comma) { str(',') } + rule(:comment) { (str('#') | str('//')) >> ((str("\n") >> str("\r").maybe).absent? >> any).repeat >> eol } rule(:crlf) { match('[\r\n]') } rule(:digit) { match('\d') } rule(:dot) { str('.') } rule(:eol) { whitespace? >> crlf.repeat } + rule(:greater_than_or_equal_to) { str('>=') } rule(:hyphen) { str('-') } + rule(:lbracket) { str('[') } rule(:lcurly) { str('{') } rule(:major) { number } rule(:major_minor) { (number >> dot >> number) } rule(:major_minor_patch) { number >> dot >> number >> dot >> number } + rule(:multiline_comment) { str('/*') >> (str('*/').absent? >> any).repeat >> str('*/') } rule(:number) { digit.repeat } rule(:pre_release) { hyphen >> (alpha | digit).repeat } rule(:pre_release?) { pre_release.maybe } rule(:quote) { str('"') } + rule(:rbracket) { str(']') } rule(:rcurly) { str('}') } rule(:space) { match('\s') } rule(:tilda_wacka) { str('~>') } rule(:version) { number >> dot >> number >> dot >> number >> pre_release? } - 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('>=') } - - rule :attribute_name do - alpha.repeat - end - rule :assignment do - whitespace? >> attribute_name >> whitespace >> assign >> whitespace >> assign >> whitespace >> match('[0-9A-Za-z.~> ]') >> quote >> eol + rule(:pessimistic_version_constraint) do + tilda_wacka >> whitespace >> ( + major_minor_patch | + major_minor | + major + ) end - rule :value do - match('[0-9A-Za-z.~> ]').repeat + rule(:greater_than_or_equal_to_version) do + greater_than_or_equal_to >> whitespace >> ( + major_minor_patch | + major_minor | + major + ) end rule(:version_constraint) do @@ -53,24 +60,20 @@ module Spandx str('constraints') >> whitespace >> assign >> whitespace >> quote >> version_constraint.as(:constraints) >> quote end - rule(:pessimistic_version_constraint) do - tilda_wacka >> whitespace >> ( - major_minor_patch | - major_minor | - major - ) + rule :string do + quote >> match('[0-9A-Za-z.~> :=/]').repeat.as(:value) >> quote end - rule(:greater_than_or_equal_to_version) do - greater_than_or_equal_to >> whitespace >> ( - major_minor_patch | - major_minor | - major - ) + rule :array_item do + whitespace >> string >> comma >> eol + end + + rule :array do + lbracket >> eol >> array_item.repeat >> rbracket end rule :argument do - alpha.repeat.as(:name) >> whitespace >> assign >> whitespace >> quote >> value.as(:value) >> quote + alpha.repeat.as(:name) >> whitespace >> assign >> whitespace >> (array.as(:values) | string) end rule :arguments do |
