Opened 11 years ago

Last modified 18 months ago

#11621 new enhancement

Preparser could accomodate multiline input and continuation lines

Reported by: Rob Beezer Owned by: William Stein
Priority: minor Milestone: sage-6.4
Component: user interface Keywords:
Cc: Leif Leonhardy Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

It would be an improvement to have the preparser recognize when an input line follows Python conventions for multiline input via Python's rules for continuation lines and mechanisms for indicating continuation lines in doctests, etc (namely "..." and perhaps soon "....:"). If you paste the following into a command-line session:

T(r, t) = [r^2,
...        t^2]

the result is:

sage: T(r, t) = [r^2,
------------------------------------------------------------
   File "<ipython console>", line 1
     __tmp__=var("r,t"); T = symbolic_expression([r**Integer(2),).function(r,t)
                                                                ^
SyntaxError: invalid syntax

sage: ...        t^2]
------------------------------------------------------------
   File "<ipython console>", line 1
     ...        t**Integer(2)]
     ^
SyntaxError: invalid syntax

Some discussion at

http://groups.google.com/group/sage-devel/browse_thread/thread/81a3cce1ebfefd0e

See related #10458.

Change History (7)

comment:1 Changed 11 years ago by Leif Leonhardy

Cc: Leif Leonhardy added

comment:2 Changed 11 years ago by Jason Grout

Notice also this inconsistency dealing with multiline statements starting with comments, caused by an early-abort statement in the preparser:

sage: preparse("""x^2\n# test\nx^2""")
'x**Integer(2)\n# test\nx**Integer(2)'
sage: preparse("""# test\nx^2""")
'# test\nx^2'

Note that if the string starts with a comment, everything is ignored after the comment. However, if the statement does not start with a comment, things are preparsed even after the comment.

comment:3 Changed 9 years ago by Jeroen Demeyer

Milestone: sage-5.11sage-5.12

comment:4 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:5 Changed 8 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:6 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:7 in reply to:  2 Changed 18 months ago by Samuel Lelièvre

Replying to jason:

Notice also this inconsistency dealing with multiline statements starting with comments, caused by an early-abort statement in the preparser:

sage: preparse("""x^2\n# test\nx^2""")
'x**Integer(2)\n# test\nx**Integer(2)'
sage: preparse("""# test\nx^2""")
'# test\nx^2'

Note that if the string starts with a comment, everything is ignored after the comment. However, if the statement does not start with a comment, things are preparsed even after the comment.

That particular aspect is fixed by #31043.

Sage still chokes on pasted or typed input such as

T(r, t) = [r^2,
           t^2]

or

sage: T(r, t) = [r^2,
....:            t^2]

or

sage: sage: T(r, t) = [r^2,
....: ....:            t^2]

while it correctly handles:

sage: sage: sage: sage: 1 + 1
Note: See TracTickets for help on using tickets.