-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 use symbols in Crystal::Lexer#check_macro_opening_keyword
#13277
Don't use symbols in Crystal::Lexer#check_macro_opening_keyword
#13277
Conversation
src/compiler/crystal/syntax/lexer.cr
Outdated
@@ -1966,7 +1966,7 @@ module Crystal | |||
elsif !delimiter_state && whitespace && (keyword = lookahead { check_macro_opening_keyword(beginning_of_line) }) | |||
char = current_char | |||
|
|||
nest += 1 unless keyword == :abstract_def | |||
nest += 1 unless keyword == {Keyword::ABSTRACT, Keyword::DEF} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that this seems to be the only use of check_macro_opening_keyword
's return value, wouldn't it be sufficient to return true
/false
to indicate whether to increase nesting? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The truthiness is also used, there'll need to be at least 3 distinct return values. And I don't think repurposing Bool?
for this looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be a way
What's the point of replacing symbols with named tuples? |
…cro_opening_keyword
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, after thinking about this again I'm not convinced about using a named tuple here just to signal three states.
IMO Bool?
would be fine. Maybe not ideal for mapping the different values. Perhaps semantics would improve by renaming the method to keyword_at_macro_start_is_abstract_def?
: nil
means there is no keyword at macro start, false
means the keyword is not abstract def
and true
means it is.
More fancy modeling is possible but unnecessary for the current usage.
|
Thanks for clarification. Makes sense. I'm not happy about using a named tuple, though. We're usually preaching their purpose is for named arguments and it's not recommended for anything else. Another alternative would be a singleton value as a second truthy state. |
I disagree with the idea that NamedTuple is only for named args 😅 I think of NamedTuple as an anonymous record, and I don't see a problem with it. |
@beta-ziliani I don't think we're using named tuples anywhere like that (and IMO for good reason). Instead, we have dozends of simple |
What about: private enum MacroKeywordState
AbstractDef
Other
end |
I figure a |
No description provided.