Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
repl: better REPL commands detection#2254
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
Fishrock123 commented Jul 27, 2015
thefourtheye commented Jul 28, 2015
Right now I am thinking about using a different character instead of |
Fishrock123 commented Jul 28, 2015
|
thefourtheye commented Jul 28, 2015
@Fishrock123 You mean like |
Fishrock123 commented Jul 28, 2015
Doh, true, |
cjihrig commented Jul 28, 2015
I think starting with EDIT: Oh, and the modulus operator |
thefourtheye commented Jul 28, 2015
Oh yeah. That is also correct. |
cjihrig commented Jul 28, 2015
I don't think changing characters is necessarily the best idea. We've already committed to |
thefourtheye commented Jul 28, 2015
Hmmm, true. So, breakage is unavoidable, no matter what we actually choose as the REPL command identifier. |
targos commented Jul 28, 2015
@cjihrig We cannot just ignore REPL commands in an expression, especially .break that is here to get out of an unfinished expression AFAIK |
cjihrig commented Jul 28, 2015
I think you can, you just need the correct context, much like you must be able to determine the context of the |
targos commented Jul 28, 2015
If course, but don't we need to introduce some kind of JS parsing to do that ? |
cjihrig commented Jul 28, 2015
I don't think we need a full blown parser, grammar and all. I think we just need to maintain a bit more state (like the existing |
thefourtheye commented Jul 28, 2015
I can take that up, but I am not sure if it is really necessary. As of now, I am just happy with this RegEx (though I have a feeling that this might break if the filename has |
Fishrock123 commented Jul 28, 2015
Sounds like a test case! |
thefourtheye commented Jul 28, 2015
@Fishrock123 Oh yeah :-) I'll include that, but is it okay to land this fix with that known limitation? |
Fixes the problem shown in nodejs#2246 The REPL module, treats any line which starts with a dot character as a REPL command and this limits the ability to use function calls in the next lines to improve readability. This patch checks if the current line starts with `.` and then a series of lowercase letters and then any characters. For example: > process.version 'v2.4.0' > function sum(arr){... return arr ... .reduce(function(c, x){return x + c}); Invalid REPL keyword undefined but then, this patches allows this: > process.version 'v2.4.1-pre' > function sum(arr){... return arr ... .reduce(function(c, x){return x + c}); ... } undefined
553fd51 to 893ab37Comparethefourtheye commented Aug 11, 2015
Rebased and incorporated the test case suggested by @Fishrock123 :-) CI Run: node-test-pull-request/70 |
thefourtheye commented Aug 11, 2015
And the CI is green (failing cases are not related to this change) :-) |
thefourtheye commented Aug 22, 2015
Bump! |
thefourtheye commented Aug 27, 2015
@Fishrock123 Ping! |
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.
I think the parse regex is far too lenient to begin with, and that we could probably only use one regex. Furthermore, why don't we just put this within if (!wasWithinStrLiteral && !isWithinStrLiteral){ above? That way we can catch it before anything is trimmed.
I'm suggesting something like:
if(!wasWithinStrLiteral&&!isWithinStrLiteral){if(cmd&&isNaN(parseFloat(cmd)){constmatches=/^\.[a-z-_]+\s*[^(){}[];=|&]*$/.exec(cmd); ... }cmd=cmd.trim();}as an aside, we should probably just check before everything if (\^\s*$\.test(cmd)) (or (cmd.trim() === '')
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.
/^\.[a-z-_]+\s*[^(){}[];=|&]*$/ doesn't allow file names with the special characters^(){}[];=|&. I can live that. Also _ and - are not necessary in it, because the REPL commands don't have them.
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.
Also
_and-are not necessary in it, because the REPL commands don't have them.
The defaults don't currently, correct. But they could eventually. Also I think the repl can be extended to add more commands? If so, those characters seem like likely candidates to exist in a custom command. While we are at it we should add A-Z to the match too.
Given the above, it's possible this would technically be a breaking change then? I'm not so sure, or concerned either.
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.
Hmmm, looks like this would be very tricky to fix and will still break from time to time :'(
Fixes the problem shown in #2246
The REPL module, treats any line which starts with a dot character as
a REPL command and this limits the ability to use function calls in
the next lines to improve readability.
This patch checks if the current line starts with
.and then a seriesof lowercase letters and then any characters.
For example:
but then, this patches allows this: