Skip to content

Commit

Permalink
io: change prompt after line continuation
Browse files Browse the repository at this point in the history
This ensures that line continuations inside of e.g. integer and float
expressions properly show a line continuation prompt.

Fixes #1992
  • Loading branch information
fingolfin committed Apr 10, 2018
1 parent 29bb736 commit 3e548e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ Char GET_NEXT_CHAR(void)
// if we see a backlash without a line terminator after it, stop
break;
}

// if we get here, we saw a line continuation; change the prompt to a
// partial prompt from now on
if (!SyQuiet)
STATE(Prompt) = "> ";
else
STATE(Prompt) = "";
}

return *STATE(In);
Expand Down
25 changes: 22 additions & 3 deletions tst/testinstall/linecontinuation.tst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ gap> START_TEST("linecontinuation.tst");
gap> x:="foo\
> bar";
"foobar"
gap> "foo\
> bar";
"foobar"

# in triple quoted string
gap> x:="""haha\
> !""";
"haha!"
gap> x:="""foo\
> bar""";
"foobar"
gap> """foo\
> bar""";
"foobar"

# break keywords and operators like :=, <=, >= etc. in the middle
gap> 1 m\
Expand All @@ -35,6 +41,19 @@ gap> {x.\
> ..}->x;
function( x... ) ... end

# inside float expressions
gap> 1.2e\
> 0;
1.2
gap> 1.1\
> ;
1.1

# inside integer expressions
gap> 12\
> 3;
123

# however, in comments, you cannot use line continuations:
gap> # 1234\
gap> 5;
Expand Down

0 comments on commit 3e548e1

Please sign in to comment.