-
Notifications
You must be signed in to change notification settings - Fork 429
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
Keyword swap changes #1539
Keyword swap changes #1539
Conversation
Does this seems like a reasonable approach? I don't have node setup locally so I can't do much in the way of thorough testing until I fix that as it looks like It would be REALLY nice to have this or an equivalent in before the big release, if that's at all possible. |
And there are bad bugs in the |
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.
Thanks for doing this, @hcarty. I agree this would be a good change to get in for the release. I had a question about the change.
src/syntax_util.ml
Outdated
@@ -137,34 +137,68 @@ let syntax_error_extension_node loc message = | |||
in | |||
(str, payload) | |||
|
|||
let string_prefix ~prefix s = |
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.
This could use a comment explaining what string_prefix
does.
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.
And could it ever be the case that s
is smaller in length than prefix
(causing runtime error)? For example, an identifier such as "matc"
. Do you want to do something like:
let matched = ref true in
let n = String.length prefix in
if String.length s >= n then
for i = 0 to n - 1 do
matched := !matched && prefix.[i] = s.[i]
done;
!matched
else
false
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.
Yeah - sorry about that! That's the bug I left a comment about. I realized I hadn't handled that case just after I turned off my computer.
This could also short-circuit by raising and immediately catching an exception when a character doesn't match.
I'll fix these issues and add some comments when I'm in front of a computer again, hopefully tomorrow.
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.
Thanks for taking the time to review!
ba3b281
to
7789f4d
Compare
Bug fixes, better function names, more comments, short-circuiting and rebased. This should be in a much better state now. As @jordwalke noted, the previous version would fail badly if the identifier was shorter than the prefix being tested against. That should be fixed now. A more subtle but still quite bad bug was that the |
| x when ( | ||
potentially_conflicts_with ~keyword:"switch_" x | ||
|| potentially_conflicts_with ~keyword:"pub_" x | ||
|| potentially_conflicts_with ~keyword:"pri_" x) -> string_drop_suffix x |
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.
This is doing quite a few checks. Shouldn't it be calculated once then have the result pattern-matched on, in a nested match?
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 are a lot of checks there. What do you mean by calculated once?
Tested and works. I'll put up some more comments and better tests. The current ones aren't indicative anymore. Thanks! |
Thanks everyone! |
Fixes #1361 -- with the exception that it doesn't update any tests yet and has received minimal testing aside from some quick checks: