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

[DIP 1007] Allow to use keywords as identifiers with a new special token sequence #6324

Closed
wants to merge 1 commit into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Dec 15, 2016

This PR is the implementation of the possible DIP 1007 (warning, not official, the document is not merged)

It shows how it would be simple to use a lexical rule that allows to use any keyword as identifier, without breaking changes. This is based on the usage of # which is already used for special token sequences.
The new special token sequence is simply # Keyword. Read the DIP for more detailed information.

@ghost ghost changed the title [POC] allow to use keywords as identifier with a special token sequence Allow to use keywords as identifiers with a new special token sequence Dec 16, 2016
@PetarKirov
Copy link
Member

PetarKirov commented Dec 16, 2016

BTW, the same is accomplished in C# with string @for (i.e. prefixing the keyword with @).

https://msdn.microsoft.com/en-us/library/x53a06bb.aspx

https://msdn.microsoft.com/en-us/library/8d7y7wz6.aspx

Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier but if is not because if is a keyword.

As a former C# user, in my experience, this feature is occasionally useful and has never been a problem of any sort in practice, so I think this PR would be a nice addition to the language. Personally I would prefer a different syntax, than #keyword, but we can discuss this at later stage.

@ghost
Copy link
Author

ghost commented Dec 16, 2016

# is the only available ascii token that has no impact on the complexity. For the others you have to make a forward lookup each time it happens even if you know it's unlikely to be a keyword escape case.
# is rare, and that's why it's good. You say yourself that

this feature is occasionally useful

@ghost ghost changed the title Allow to use keywords as identifiers with a new special token sequence [DIP 1007] Allow to use keywords as identifiers with a new special token sequence Dec 17, 2016
@ghost ghost closed this Dec 26, 2016
@ghost ghost deleted the escape-kw branch March 27, 2017 15:31
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant