Open munjalpatel opened 1 year ago
Found out that it is supported. https://github.com/drowzy/hxl/blob/2f9295c10c8d3d4a2f6090683e9aa62d5d903705/src/hcl_parser.yrl#L196
So, fixed my code by adding a missing space
like below.
action "transform_data" {
js = <<- EOT
const output = { ...input, x: 1 };
return output;
EOT
}
However, it seems that the library is trying to parse string inside heredoc
as well since now I am getting this error:
{:error, "Unrecognized input: ';\n return output;\n EOT\n}\n' at 19:238"}
Thanks for the issue! You are correct that it should treat the lines in the heredoc as text and not parse it. Seems to be a bug. I’ll look into it!
Thanks Simon :)
I tried with the following:
hcl = """
action "transform_data" {
js = <<-EOT
const output = { ...input, x: 1 };
return output;
EOT
}
"""
iex(8)> HXL.Lexer.tokenize(hcl)
{:ok,
[
{:identifier, {1, 6}, ["action"]},
{:string_part, {1, 23}, ["transform_data"]},
{:"{", {1, 25}},
{:identifier, {2, 4}, ["js"]},
{:=, {2, 6}},
{:heredoc, {0, 0}},
{:identifier, {2, 13}, ["EOT"]},
{:text, {4, 0}, [" const output = { ...input, x: 1 };"]},
{:text, {5, 0}, [" return output;"]},
{:identifier, {5, 5}, ["EOT"]},
{:"}", {6, 1}}
], "", %{}, {7, 106}, 106}
and
HXL.Parser.parse(hcl)
{:ok,
%HXL.Ast.Body{
statements: [
%HXL.Ast.Block{
type: "action",
labels: ["transform_data"],
body: %HXL.Ast.Body{
statements: [
%HXL.Ast.Attr{
name: "js",
expr: %HXL.Ast.TemplateExpr{
delimiter: "EOT",
lines: [" const output = { ...input, x: 1 };",
" return output;"]
}
}
]
}
}
]
}}
Which seems to be correct. Can you post a complete example? Might be something else that is wrong.
Or atleast the output from HXL.Lexer.tokenize/1
.
Oh and both <<-EOT
and <<- EOT
is allowed now, in the second example that you posted it skipped tokenize as a heredoc due to the space, which it should do now :).
The only difference is that you used tokenized
while I am using devode_file
test.hcl
action "transform_data" {
js = <<- EOT
const output = { ...input, x: 1 };
return output;
EOT
}
hcl_parser.ex
defmodule HclParser do
def parse do
HXL.decode_file("test.hcl")
end
end
Hey @drowzy,
I am trying to parse a config with
heredoc
like this:But it is failing with the following error:
Is parsing HCL that contains
heredoc
supported? If not, are there any potential workarounds?BTW, this is a great library, excellent work!