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

add: Meta.isreserved public api #57846

Closed

Conversation

prashantrahul141
Copy link
Contributor

This adds Meta.isreserved to check whether a symbol or string is a reserved julia keyword
closes #26090

julia> Meta.isreserved(:for)
true

julia> Meta.isreserved("cat")
false

Signed-off-by: prashantrahul141 <prashantrahul141@protonmail.com>
Signed-off-by: prashantrahul141 <prashantrahul141@protonmail.com>
Signed-off-by: prashantrahul141 <prashantrahul141@protonmail.com>
Signed-off-by: prashantrahul141 <prashantrahul141@protonmail.com>
@Seelengrab
Copy link
Contributor

Sorry, but what is this for? Shouldn't this live in the parser somewhere instead?

@KristofferC
Copy link
Member

#26090 has some info when it would be useful.

@prashantrahul141
Copy link
Contributor Author

prashantrahul141 commented Mar 21, 2025

@Seelengrab I noticed that the definitions of other similar exported functions, like isidentifier and isoperator, are present there. Additionally, the keyword_syms set is also there but isn't exported, so it cannot be used elsewhere.

Also, the reason I moved keyword_syms and is_valid_identifier about 80 lines up is that I noticed most exported functions are placed before private ones in the file.

Copy link
Member

@LilithHafner LilithHafner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that this is defined in Base and imported and re-exported from Meta as well as public in Base because I would prefer there only be a single way to publically access functions when possible. That said, I agree with your choice to follow the same pattern as isoperator, isidentifier, etc.

Tagging triage because this adds a new public feature and once we release it we'll be committed to living with the consequences forever so it's worth double checking that we want this.

@LilithHafner LilithHafner added triage This should be discussed on a triage call feature Indicates new feature / enhancement requests labels Mar 21, 2025
@Seelengrab
Copy link
Contributor

Seelengrab commented Mar 21, 2025

#26090 has some info when it would be useful

That makes sense as a use, but I'd still place this in the parser rather than Meta.

noticed that the definitions of other similar exported functions, like isidentifier and isoperator, are present there

Tbh, I'm not entirely sure why there's a bunch of parser-related functionality in Meta in the first place - I'd assume that this module is for metaprogramming related stuff, not parsing/lexing. Probably some legacy reasons?

@LilithHafner
Copy link
Member

I get that you don't like the location of the existing functionality (and neither do I) but hopefully we can agree that it would be silly to have isreserved and isidentifier in different modules.

If you care enough to want to make a change, @Seelengrab, you can open a conversation about isbinaryoperator, isidentifier, isoperator, ispostfixoperator, and isunaryoperator in a separate issue or PR.

@prashantrahul141, good job following the existing pattern and maintaining consistency among related concepts.

@Seelengrab
Copy link
Contributor

hopefully we can agree that it would be silly to have isreserved and isidentifier in different modules.

I do think we agree, that's exactly why I'm proposing to put this into the actual parser module :) I believe that's JuliaSyntax at the moment? It might already be there, I haven't checked. I'm not sure why you seem to think that we disagree 🤔 I'm not proposing to move the existing code somewhere else.

The code in this PR is (from what I can tell) good and the reasoning why it came up also makes sense.

@prashantrahul141
Copy link
Contributor Author

I think users should be able to check things like valid operators and reserved keywords with just the standard library without relying on external modules or libraries. This is especially true for Julia, given its powerful metaprogramming capabilities.

That said, I agree with you, @Seelengrab, that metaprogramming-related functionality doesn’t belong in a file named show.jl. Instead, it should be placed in a dedicated submodule within the standard library.

If you care enough to want to make a change, @Seelengrab, you can open a conversation about isbinaryoperator, isidentifier, isoperator, ispostfixoperator, and isunaryoperator in a separate issue or PR.

Also, I would be interested in working on that!

Signed-off-by: prashantrahul141 <prashantrahul141@protonmail.com>
@LilithHafner
Copy link
Member

Triage meets every other Thursday at 13:15 ET. The next meeting is 4 days and 4.5 hours from now. @prashantrahul141, you're welcome to attend if you would like! (but there's no expectation if you don't want to or can't make the time). By virtue of having the triage label on it, this PR will be added to our agenda. We'll talk about weather this feature is worth including and maintaining and weather the name is appropriate.

There is some asynchronous triage discussion on the #triage slack channel (get an invite here: https://julialang.org/slack/) and the meetings themselves happen here: https://mit.zoom.us/j/92625773516?pwd=TG0zUVpvSnlCdVRJd3NHeW9XK1ErQT09

@KristofferC
Copy link
Member

That makes sense as a use, but I'd still place this in the parser rather than Meta.

Where? Meta is even the entrypoint to the parser. It is completely consistent to have this in Meta.

@Seelengrab
Copy link
Contributor

Seelengrab commented Mar 24, 2025

Where? Meta is even the entrypoint to the parser. It is completely consistent to have this in Meta.

Probably right below is_keyword? The overlap seems significant, so perhaps that and the version in this PR are even intended to be the same. I'm also not sure if the version in JuliaSyntax is intended to take Symbols.

@KristofferC
Copy link
Member

JuliaSyntax is an implementation detail of Julia. It is not an stdlib so adding it there does nothing unless you want people to have to add a dependency on JuliaSyntax for this feature.

@Seelengrab
Copy link
Contributor

I'm not sure Meta is an stdlib either (it's not listed in the dropdown in the docs, and only mentioned as a submodule of Base).

It's just easier to maintain only one list of keywords instead of having to keep two definitions that don't know about each other in sync 🤷 I wasn't aware that JuliaSyntax is only considered an implementation detail.

@KristofferC
Copy link
Member

I'm not sure Meta is an stdlib either

Who said it was?? The point is that JuliaSyntax is not an stdlib nor a Base module nor anything...

@LilithHafner
Copy link
Member

@prashantrahul141, @mbauman made some interesting and convincing points about how isreserved isn't actually necessary anymore in the cases where people said it was needed in 2018. So we are not going to add this function for now. Thanks for the PR, though!

@LilithHafner LilithHafner removed the triage This should be discussed on a triage call label Mar 27, 2025
@prashantrahul141 prashantrahul141 deleted the add-isreserved branch March 28, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isreserved(s::Symbol) -> Bool
5 participants