Repository: martinohmann/hcl-rs (rust)

Issue:
Error when trying to parse comments starting with `//`
Despite the copious signage, I was brave (foolish?) enough to try out `hcl-edit`.

I'm happy to report that it did exactly what I wanted it to and would have been easier than the alternatives. So, thank you!

I did find one issue where `hcl-edit` doesn't correctly parse comments starting with `//`:

```
Error:    --> HCL parse error in line 112, column 51
    |
112 |   ami                  = "ami-5f6495430e7781fe5" // Ubuntu 20.04 LTS
    |                                                   ^---
    |
    = invalid expression; expected `"`, `[`, `{`, `-`, `!`, `(`, `_`, `<`, letter or digit
```

I was able to work around this for my use case by just using `#` for the comments.

Pull request description:
fix(parser): handle `/` ambiguity in expression parser
Fixes #188

Patch:
diff --git a/crates/hcl-edit/src/parser/expr.rs b/crates/hcl-edit/src/parser/expr.rs
index bb49182..ad078f7 100644
--- a/crates/hcl-edit/src/parser/expr.rs
+++ b/crates/hcl-edit/src/parser/expr.rs
@@ -54,6 +54,8 @@ pub(super) fn expr_inner<'i, 's>(
                     // argument of a function call, do not mistakenly parse it as a traversal
                     // operator.
                     b".." => return Ok((input, ())),
+                    // This is a comment start, do not mistakenly parse a binary division operator.
+                    b"//" | b"/*" => return Ok((input, ())),
                     // Traversal operator.
                     //
                     // Note: after the traversal is consumed, the loop is entered again to consume


Test patch:
diff --git a/crates/hcl-edit/src/parser/tests.rs b/crates/hcl-edit/src/parser/tests.rs
index 66185c5..8274e30 100644
--- a/crates/hcl-edit/src/parser/tests.rs
+++ b/crates/hcl-edit/src/parser/tests.rs
@@ -84,6 +84,8 @@ fn roundtrip_body() {
                   heredoc
                 EOT
         "#},
+        "ami = \"ami-5f6495430e7781fe5\" // Ubuntu 20.04 LTS\n",
+        "ami = \"ami-5f6495430e7781fe5\" /* Ubuntu 20.04 LTS */\n",
     ];
 
     let tests = testdata::load().unwrap();