kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.67k stars 118 forks source link

Comment "# ----" is not treated as comment and causes parse error #1338

Closed taylormonacelli closed 5 months ago

taylormonacelli commented 5 months ago

Bug Report

1. Minimal reproduce step (Required)

This fails:


kcl --version
cat >config.yaml <<EOF
# ---------------------------------- Cluster -----------------------------------
cluster.name: my-application
EOF

kcl import --force config.yaml

With this error:


root@ip-172-31-19-201:~# kcl --version
kcl version 0.9.0-alpha.1
root@ip-172-31-19-201:~# cat >config.yaml <<EOF
> # ---------------------------------- Cluster -----------------------------------
> cluster.name: my-application
> EOF
root@ip-172-31-19-201:~#
root@ip-172-31-19-201:~# kcl import --force config.yaml
[1:1] sequence was used where mapping is expected
>  1 | - Cluster
       ^

root@ip-172-31-19-201:~#

This fails


kcl --version
cat >config.yaml <<EOF
# ----
cluster.name: my-application
EOF

kcl import --force config.yaml

with the same error.

This works as expected:


kcl --version
cat >config.yaml <<EOF
# ---
cluster.name: my-application
EOF

kcl import --force config.yaml
cat config.k
root@ip-172-31-19-201:~# kcl --version
kcl version 0.9.0-alpha.1
root@ip-172-31-19-201:~# cat >config.yaml <<EOF
> # ---
> cluster.name: my-application
> EOF
root@ip-172-31-19-201:~#
root@ip-172-31-19-201:~# kcl import --force config.yaml
root@ip-172-31-19-201:~# cat config.k
"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

{
    "cluster.name" = "my-application"
}
root@ip-172-31-19-201:~#

2. What did you expect to see? (Required)

I expect anything starting with # should be treated as comment.

3. What did you see instead (Required)

Parse error for line that is a comment.

4. What is your KCL components version? (Required)


root@ip-172-31-19-201:~# kcl --version
kcl version 0.9.0-alpha.1
root@ip-172-31-19-201:~#
Peefy commented 5 months ago

Thanks for the feedback, I've fixed it in https://github.com/kcl-lang/kcl-go/pull/310