Mark all strings as atomic #325

Open
opened 2025-04-16 09:40:44 +02:00 by wetneb · 2 comments
Owner

Quoting @ada4a in #210:

The compact output was somewhat more surprising:

# ExpectedCompact.hcl
variable "foo" {
  description = "
<<<<<<< LEFT
hello left
||||||| BASE
hello world
=======
hello right
>>>>>>> RIGHT
"
}

I would've expect the quotes to stay around the strings. But an identical test in Rust has the same behaviour, so I guess it's fine.

This can be solved by marking string nodes as being atomic, to prevent them from being analyzed into "opening quote, contents, closing quote".

  • mark strings as atomics for all existing supported languages
  • update the documentation to recommend marking them as atomic in new languages too
Quoting @ada4a in https://codeberg.org/mergiraf/mergiraf/pulls/210: > The compact output was somewhat more surprising: > ```hcl > # ExpectedCompact.hcl > variable "foo" { > description = " > <<<<<<< LEFT > hello left > ||||||| BASE > hello world > ======= > hello right > >>>>>>> RIGHT > " > } > ``` > I would've expect the quotes to stay around the strings. But an identical test in Rust has the same behaviour, so I guess it's fine. This can be solved by marking string nodes as being atomic, to prevent them from being analyzed into "opening quote, contents, closing quote". - [ ] mark strings as atomics for all existing supported languages - [ ] update the documentation to recommend marking them as atomic in new languages too
Author
Owner

We need to consider the implications for matching carefully, since marking strings as atomic will tend to decrease the depth of some trees, making matching more conservative.

We need to consider the implications for matching carefully, since marking strings as atomic will tend to decrease the depth of some trees, making matching more conservative.
Author
Owner

Strings not being marked as atomic is the source of bugs when the string contents are not exposed as public nodes by the grammar, which happens surprisingly often (in YAML #380, but also earlier in Go).

Strings not being marked as atomic is the source of bugs when the string contents are not exposed as public nodes by the grammar, which happens surprisingly often (in YAML #380, but also earlier in Go).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mergiraf/mergiraf#325
No description provided.