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

Don't treat primitives as a separate syntactic class #636

Open
camelid opened this issue Oct 24, 2020 · 2 comments
Open

Don't treat primitives as a separate syntactic class #636

camelid opened this issue Oct 24, 2020 · 2 comments
Labels
C-chalk-parse Issues related to the chalk-parse crate

Comments

@camelid
Copy link
Member

camelid commented Oct 24, 2020

Currently types like i32, f32, and str are a separate syntactic class,
which means that code like struct i32 {} produces confusing errors:

error: parse error: Unrecognized token `i32` found at 7:10
Expected one of r#"([A-Za-z]|_)([A-Za-z0-9]|_)*"#

I can't think of a reason off the top of my head why primitives have to be
special-cased in the parser rather than just being declared in libstd.chalk
(or even the IR or something). If there's a reason, I'm curious to here it!

This is probably low-priority, but it might be nice to change.

See the Zulip discussion.

@basil-cow
Copy link
Contributor

They can't be declared in libstd.chalk because i32 is not the same as struct i32 {}, from chalks point of view.

As for declaring them in IR, I don't see any benefit in trying to reparse type names to figure out if they are in fact a primitive type when performing AST lowering. It would just transfer the complexity from the parser to lowering.

@nikomatsakis
Copy link
Contributor

chalk's parser isn't really meant to be "general purpose", it's more for writing tests, so I'm not overly concerned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-chalk-parse Issues related to the chalk-parse crate
Projects
None yet
Development

No branches or pull requests

4 participants