diff options
| author | mo khan <mo@mokhan.ca> | 2021-06-06 16:34:39 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-06-06 16:34:39 -0600 |
| commit | 1d35f4c6fc2a3133021f366b0917067435c4bffb (patch) | |
| tree | 46086e30e0710b1d929d7f39ff20a4c5e81f97a4 | |
| parent | df10720292a96e76d4f839ba9c5726f63c4c5dc1 (diff) | |
fix: parse slightly more complicated strings and identifiers
| -rw-r--r-- | lib/hcl2/parser.rb | 8 | ||||
| -rw-r--r-- | spec/parser_spec.rb | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/hcl2/parser.rb b/lib/hcl2/parser.rb index 43dabeb..58f6c21 100644 --- a/lib/hcl2/parser.rb +++ b/lib/hcl2/parser.rb @@ -23,12 +23,14 @@ module Hcl2 rule(:plus) { str("+") } rule(:pre_release) { hyphen >> (alpha | digit).repeat } rule(:pre_release?) { pre_release.maybe } + rule(:question_mark) { str("?") } rule(:quote) { str('"') } rule(:rbracket) { str("]") } rule(:rcurly) { str("}") } rule(:slash) { str("/") } rule(:space) { match('\s') } rule(:tilda_wacka) { str("~>") } + rule(:underscore) { str("_") } rule(:version) { number >> dot >> number >> dot >> number >> pre_release? } rule(:whitespace) { (multiline_comment | comment | space).repeat } rule(:whitespace?) { whitespace.maybe } @@ -63,7 +65,7 @@ module Hcl2 rule :string do quote >> ( - digit | dot | alpha | str("~> ") | slash | colon | assign | plus + digit | dot | alpha | str("~> ") | slash | colon | assign | plus | hyphen | question_mark | assign ).repeat(1).as(:value) >> quote end @@ -84,7 +86,7 @@ module Hcl2 end rule :argument do - whitespace >> alpha.repeat(1).as(:name) >> whitespace >> assign >> whitespace >> argument_value + whitespace >> (alpha).repeat(1).as(:name) >> whitespace >> assign >> whitespace >> argument_value end rule :block_body do @@ -92,7 +94,7 @@ module Hcl2 end rule :identifier do - whitespace >> quote >> (alpha | dot | slash).repeat(1).as(:name) >> quote >> whitespace + whitespace >> quote >> (alpha | dot | slash | underscore).repeat(1).as(:name) >> quote >> whitespace end rule :block do diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index c8d50fc..023dfe9 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -134,7 +134,14 @@ RSpec.describe Hcl2::Parser do HCL end - pending { expect(subject).to be_truthy } + specify { expect(subject).to be_truthy } + + specify do + expect(subject[:blocks][0][:type].to_s).to eq("module") + expect(subject[:blocks][0][:name].to_s).to eq("origin_label") + expect(subject[:blocks][0][:arguments][0][:name].to_s).to eq("source") + expect(subject[:blocks][0][:arguments][0][:value].to_s).to eq("git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.7") + end end context "when parsing a module with an argument assignment via string interpolation" do |
