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

Keyword swap changes #1539

Merged
merged 2 commits into from
Oct 24, 2017
Merged

Keyword swap changes #1539

merged 2 commits into from
Oct 24, 2017

Conversation

hcarty
Copy link
Contributor

@hcarty hcarty commented Oct 22, 2017

Fixes #1361 -- with the exception that it doesn't update any tests yet and has received minimal testing aside from some quick checks:

$ echo 'let pub = 5' | ./refmt_impl.native --parse=ml --print=re
let pub_ = 5;
$ echo 'let pub_ = 5' | ./refmt_impl.native --parse=re --print=ml
let pub = 5

@hcarty
Copy link
Contributor Author

hcarty commented Oct 22, 2017

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 make test requires node now.

It would be REALLY nice to have this or an equivalent in before the big release, if that's at all possible.

@hcarty
Copy link
Contributor Author

hcarty commented Oct 22, 2017

And there are bad bugs in the string_prefix function which I'll fix as soon as I'm in front of a computer again.

Copy link
Member

@jordwalke jordwalke left a 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.

@@ -137,34 +137,68 @@ let syntax_error_extension_node loc message =
in
(str, payload)

let string_prefix ~prefix s =
Copy link
Member

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.

Copy link
Member

@jordwalke jordwalke Oct 22, 2017

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

@hcarty hcarty force-pushed the keyword-swap-changes branch from ba3b281 to 7789f4d Compare October 23, 2017 04:05
@hcarty
Copy link
Contributor Author

hcarty commented Oct 23, 2017

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 _ suffix meddling was applied for any identifier starting with a keyword. So both pub and publish would have been modified when translating between syntaxes even though publish does not have a conflict. This has been fixed so that only keywords with zero or more _ trailing characters are affected by the name substitution.

| x when (
potentially_conflicts_with ~keyword:"switch_" x
|| potentially_conflicts_with ~keyword:"pub_" x
|| potentially_conflicts_with ~keyword:"pri_" x) -> string_drop_suffix x
Copy link
Member

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?

Copy link
Contributor Author

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?

@chenglou
Copy link
Member

Tested and works. I'll put up some more comments and better tests. The current ones aren't indicative anymore.

Thanks!

@chenglou chenglou merged commit 38ac8a5 into reasonml:master Oct 24, 2017
@hcarty hcarty deleted the keyword-swap-changes branch October 24, 2017 05:45
chenglou added a commit to chenglou/reason that referenced this pull request Oct 24, 2017
chenglou added a commit that referenced this pull request Oct 24, 2017
@jordwalke
Copy link
Member

Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants