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

Handling of comma at the end of the line in REPL #28506

Closed
bkamins opened this issue Aug 7, 2018 · 3 comments

Comments

2 participants
@bkamins
Copy link
Contributor

commented Aug 7, 2018

If you enter an expression in REPL that terminates with a comma , then it is parsed immediately after newline , e.g.

julia> x = 1,
(1,)

julia> 1, 2, 3,
(1, 2, 3)

However in Julia script after , Julia tries to read continuation of the expression from a new line, e.g.

julia> function f()
1,
1, 2, 3
end

julia> f()
(1, 1, 2, 3)

This is inconsistent. The problem is apparent when you have a code and you copy paste it into REPL.

E.g. in the example above copy-pasting only the body of f() into REPL produces:

julia> 1,
(1,)

julia> 1, 2, 3
(1, 2, 3)

I guess it is not intended as I would expect consistency between REPL?
I know that 100% consistency is not guaranteed - e.g. when multiple empty lines are present, but this case seems that it should give the same result

@JeffBezanson

This comment has been minimized.

Copy link
Member

commented Aug 7, 2018

This is probably related to whether it's waiting for a closing token, similar to how 1\n is accepted but (1\n waits for more input.

@JeffBezanson JeffBezanson added the parser label Aug 7, 2018

@bkamins

This comment has been minimized.

Copy link
Contributor Author

commented Aug 7, 2018

To my understanding the reason is that in REPL Base.parse_input_line treats e.g. x = 1, as a complete expression so it does not put :incomplete in ast.head and in consequence REPL decides that the expression is complete and parses it. Similarly Meta.parse("x = 1,") returns a one element tuple.

However, e.g. this Base.parse_input_line("begin x = 1, end") and this Meta.parse("begin x = 1, end") raises an error.

@JeffBezanson

This comment has been minimized.

Copy link
Member

commented Sep 5, 2018

Good news: this only seems to arise if x = 1, is followed directly by end-of-input. For example you can type this:

julia> 1,
       1, 2, 3
(1, 1, 2, 3)

I don't think any source files are likely to end in a comma, so we can fix this without breaking anything. For example we even have:

julia> include_string(Main, "1,")
(1,)

julia> include_string(Main, "1,\n")
ERROR: LoadError: syntax: incomplete: premature end of input

JeffBezanson added a commit that referenced this issue Sep 5, 2018

JeffBezanson added a commit that referenced this issue Oct 19, 2018

JeffBezanson added a commit that referenced this issue Oct 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.