Skip to content

Implemented tkn! macro for syntax kinds #1257

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

Merged
merged 1 commit into from
May 13, 2019
Merged

Conversation

pasa
Copy link
Contributor

@pasa pasa commented May 8, 2019

Implementation of #1248

@pasa pasa force-pushed the issue_1248 branch 2 times, most recently from 3b7c996 to 54c0bb8 Compare May 8, 2019 16:14
@@ -134,8 +136,8 @@ fn pick_best<'a>(l: SyntaxToken<'a>, r: SyntaxToken<'a>) -> SyntaxToken<'a> {
return if priority(r) > priority(l) { r } else { l };
fn priority(n: SyntaxToken) -> usize {
match n.kind() {
WHITESPACE => 0,
IDENT | SELF_KW | SUPER_KW | CRATE_KW | LIFETIME => 2,
tkn![' '] => 0,
Copy link
Member

Choose a reason for hiding this comment

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

For whitespace, I think we should just use the name WHITESPACE, withot macro

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

@@ -241,6 +241,102 @@ pub enum SyntaxKind {
}
use self::SyntaxKind::*;

#[macro_export]
macro_rules! tkn {
Copy link
Member

Choose a reason for hiding this comment

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

Let's name this TOKEN: this generates a const, so it makes sense for this to be capitalized

So that one would use TOKEN![,]

Copy link
Member

Choose a reason for hiding this comment

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

Hm, it'll be to screamy for short tokens though... Let's make it just

T![,]

?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe T! is too short? TKN![,] ?

Copy link
Member

Choose a reason for hiding this comment

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

I like TKN less than either of T and TOKEN. Dropping vowels is not very readable to me.

My personal preference would be

T, TOKEN # somewhat equivalent
TOK  
TKN

though, I don't have a strong opinion here and changing later would be easy

Copy link
Member

@edwin0cheng edwin0cheng May 9, 2019

Choose a reason for hiding this comment

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

TOKEN![,] is good for me, as IDE should be able to auto-complete the remain “KEN” after i type in “TO”.😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like T! most of all too. I've made so.

@@ -20,6 +20,7 @@ jemallocator = { version = "0.1.9", optional = true }
jemalloc-ctl = { version = "0.2.0", optional = true }

ra_syntax = { path = "../ra_syntax" }
ra_parser = { path = "../ra_parser" }
Copy link
Member

Choose a reason for hiding this comment

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

The macro should be re-exported in ra_syntax, such that no direct dependency on ra_parser is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't figure out how to do this last time. It's correct right now

@matklad
Copy link
Member

matklad commented May 13, 2019

bors r+

Thanks!

bors bot added a commit that referenced this pull request May 13, 2019
1257: Implemented tkn! macro for syntax kinds r=matklad a=pasa

Implementation of #1248

Co-authored-by: Sergey Parilin <sergey.parilin@fxdd.com>
@bors
Copy link
Contributor

bors bot commented May 13, 2019

Build succeeded

@bors bors bot merged commit 57bb618 into rust-lang:master May 13, 2019
@matklad
Copy link
Member

matklad commented May 13, 2019

Might be a good idea to try to use this macro more across the codebase

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.

3 participants