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 |
| in | ||
| (str, payload) | ||
|
|
||
| let string_prefix ~prefix s = |
There was a problem hiding this comment.
This could use a comment explaining what string_prefix does.
There was a problem hiding this comment.
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.
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.
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.
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.
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: