tree-sitter-grammars / tree-sitter-hcl

HCL grammar for tree-sitter
https://tree-sitter-grammars.github.io/tree-sitter-hcl/
Apache License 2.0
92 stars 20 forks source link

Allow dots in identifiers #53

Open nachtjasmin opened 1 month ago

nachtjasmin commented 1 month ago

Describe the bug Grafana Alloy is a telemetry collector that uses a HCL-like language for configuration. Their configuration language "alloy" is almost exactly like HCL, except that it also seems to support dots in block identifiers.

Example, copied from their documentation:

// Collection: mount a local directory with a certain path spec
local.file_match "applogs" {
    path_targets = [{"__path__" = "/tmp/app-logs/app.log"}]
}

// Collection: Take the file match as input, and scrape those mounted log files
loki.source.file "local_files" {
    targets    = local.file_match.applogs.targets

    // This specifies which component should process the logs next, the "link in the chain"
    forward_to = [loki.process.add_new_label.receiver]
}

// Transformation: pull some data out of the log message, and turn it into a label
loki.process "add_new_label" {
    stage.logfmt {
        mapping = {
            "extracted_level" = "level",
        }
    }

    // Add the value of "extracted_level" from the extracted map as a "level" label
    stage.labels {
        values = {
            "level" = "extracted_level",
        }
    }

    // The next link in the chain is the local_loki "receiver" (receives the telemetry)
    forward_to = [loki.write.local_loki.receiver]
}

// Anything that comes into this component gets written to the loki remote API
loki.write "local_loki" {
    endpoint {
        url = "http://loki:3100/loki/api/v1/push"
    }
}

It would be nice if this could be supported by this tree-sitter syntax. I know it's not exactly HCL, but I am not sure whether it already makes sense to fork this repo just for this minor addition.

To Reproduce Steps to reproduce the behavior:

  1. Write HCL-like syntax like above.
  2. The tree-sitter marks this as invalid syntax.

Expected behavior I'd like to see the dots supported in identifiers.

Screenshots None.

Additional context None.

MichaHoffmann commented 1 month ago

I think we could support them, but we also could add a dialect for "alloy" in case that some other rules also change eventually?

nachtjasmin commented 1 month ago

If that's possible, sure, sounds like a good idea!