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

Reserve more keywords in KCL #4486

Closed
jtran opened this issue Nov 14, 2024 · 3 comments · Fixed by #4517
Closed

Reserve more keywords in KCL #4486

jtran opened this issue Nov 14, 2024 · 3 comments · Fixed by #4517
Assignees
Labels
kcl Language and compiler features

Comments

@jtran
Copy link
Collaborator

jtran commented Nov 14, 2024

Before 1.0, we'd like to reserve more keywords so that users don't use them as variable names.

This is the list that was proposed:

  • _ (underscore)
  • as
  • new
  • interface
  • type
  • record
  • struct
  • object

I think we should add to this list:

  • self Pipelines, tagging, and for loops kcl-experiments#15
  • array - Could be a runtime conversion function or the type. We already support optional type annotations, like string, number, and sketch. We use [] for the type, but it still may be useful to refer to the type or constructor by name.

Should we consider others? Here's JavaScript's and Python's.

These will not be reserved:

  • from - It's used in import statements, but because of the syntax chosen, it's unambiguous. This will likely be used for named parameters.
@jtran jtran added the kcl Language and compiler features label Nov 14, 2024
@jtran jtran self-assigned this Nov 14, 2024
@jtran
Copy link
Collaborator Author

jtran commented Nov 15, 2024

type is used for the keys of objects in the stdlib. For example, see ImportFormat, which is the options of the import() function. Our options:

  1. Disallow all keywords and types as object members and change all stdlib usage of type to kind, format, type_, or some other alternative.
  2. Allow all keywords and types as object members by changing the parser to accept keywords or types in object literals and in dot notation when accessing members
  3. Special-case type, specifically, to allow it, but not other keywords and types
  4. Never treat type as a keyword. I.e. the proposed change is not wanted.

My inclination is to not special-case things, keep things simple, and go with option 1.

Update: from is another one that we'll probably want to use for named arguments.

@nrc
Copy link
Contributor

nrc commented Nov 19, 2024

IMO, import should become a full keyword too.

@jtran
Copy link
Collaborator Author

jtran commented Nov 19, 2024

For import, the parser doesn't let you define something that's the same name as any stdlib function. See into_valid_binding_name() in parser_impl.rs. So I think we're fine for now. But we should be aware of this if we rename, refactor, make namespaces, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kcl Language and compiler features
Projects
None yet
2 participants