Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Top level expression statement value plan. #545

Closed
Peefy opened this issue May 12, 2023 · 1 comment
Closed

[Feature] Top level expression statement value plan. #545

Peefy opened this issue May 12, 2023 · 1 comment
Assignees
Labels
codegen feat runtime Issues or PRs related to kcl runtime including value and value opertions semantic Issues or PRs related to kcl semantic and checker

Comments

@Peefy
Copy link
Contributor

Peefy commented May 12, 2023

Feature

In previous versions of KCL, the values of top-level expression statements were not output to JSON/YAML, such as the following example, which we can now support them.

1
[1, 2, 3]
{
    a = 1
    b = 1
}
Pod {
    apiVersion = "v1"
}

Design

In previous versions of KCL, the values of top-level expression statements did not have any semantics. We can set their semantics to correspond to scalar values in JSON/YAML, giving KCL more semantics that is closer to Jsonlike. For example, the following KCL code will be output as JSON/YAML.

1

The output JSON/YAML is

1

We collectively refer to these values as scalars, The output principle of scalars in KCL is

  • All scalars undergo idempotent configuration merging, and an error is thrown when a collision error occurs during the merge. KCL does not output any JSON/YAML values.
  • Any scalar and nonscalar types cannot be merged because they are different types. For example, the following code will throw an error:
a = 1
1 # Error: conflict values between {a = 1} and 1

Example

Schema

schema Config:
    id: int

Config {
    id = 1
}

The output YAML is

id: 1

Conflict Value Errors

  • Case 1
1
2
  • Case 2
a = 1
2
  • Case 3
{
   a = 1
}
2

Reference

@Peefy Peefy added semantic Issues or PRs related to kcl semantic and checker runtime Issues or PRs related to kcl runtime including value and value opertions feat labels May 12, 2023
@Peefy Peefy added this to the v0.5.0 Release milestone May 12, 2023
@Peefy Peefy self-assigned this May 12, 2023
@Peefy Peefy added the codegen label May 18, 2023
@Peefy
Copy link
Contributor Author

Peefy commented May 23, 2023

Closed by #556

@Peefy Peefy closed this as completed May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen feat runtime Issues or PRs related to kcl runtime including value and value opertions semantic Issues or PRs related to kcl semantic and checker
Projects
None yet
Development

No branches or pull requests

1 participant