Skip to content

Can I tell the parser more about an expected node argument? #27

@theophile-scrive

Description

@theophile-scrive

Hi @brandonchinn178!

I have the following KDL format:

inventory "base" {
	var "name" {
		value "value"
	}
}

And I want to improve the error reporting in case the inventory name name is omitted:

inventory {
	var "name" {
		value "value"
	}
}

At the moment, a rendered error gives me the following:

        At: inventory #0
          Expected arg #0

I'd like to be able to report an error saying Node inventory is expecting an argument "name" of type "text".

The parser looks like this at the moment:

KDL.nodeWith "inventory" $ do
  name <- KDL.arg @Text

I guess I could use optional and throw a custom error if I see a Nothing?


Note that I adopt this syntax because the tool I'm building is aimed at people who are exposed to Terraform, which has HCL configuration such as:

module "outscale-vm" {
  source       = "../modules/outscale-vm"
  vm_type      = "tinav6.c2r4p1"
  keypair_name = "bastion"
}

but if this is stretching the language / parser beyond what it's been made for, I can understand that I should use props instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions