Opened 4 years ago

multi-line doctests fail when using angle notation (preparser)

Reported by: Owned by: dkrenn major sage-6.9 misc N/A

Description

The following fails

```        sage: A.<n> = AsymptoticRing(growth_group='QQ^x * x^QQ * log(n)^QQ',
....:                         coefficient_ring=QQ); A
```

One gets:

```    A.<n> = AsymptoticRing(growth_group='QQ^x * x^QQ * log(n)^QQ',
coefficient_ring=QQ); A
Exception raised:
Traceback (most recent call last):
...
A = AsymptoticRing(growth_group='QQ^x * x^QQ * log(n)^QQ',; (n,) = A._first_ngens(1)
^
SyntaxError: invalid syntax
```

comment:1 Changed 4 years ago by nbruin

Perhaps a simpler example: compare

```sage: preparse("""A.<a,b,c>=PolynomialRing(QQ)""")
"A = PolynomialRing(QQ, names=('a', 'b', 'c',)); (a, b, c,) = A._first_ngens(3)"
sage: preparse("""A.<a,b,c>=PolynomialRing(QQ\n)""")
'A = PolynomialRing(QQ; (a, b, c,) = A._first_ngens(3)\n)'
sage: preparse("A.<x>=QQ[]")
"A = QQ['x']; (x,) = A._first_ngens(1)"
sage: preparse("A.<x>=QQ[\n]")
'A = QQ[; (x,) = A._first_ngens(1)\n]'
```

As you can see, the newline completely throws off the substitution:

• no "names" attribute is inserted
• the binding of generators to given identifiers is inserted in the wrong spot (at the end of the first line instead of at the end of the command)

This is a tricky one: Usually in python, a newline terminates a command, so the place of insertion would usually be safe. However, if there is an unbalanced bracket, then the newline is just a whitespace. This is a condition that cannot be detected with a regex in general.

comment:2 Changed 3 years ago by jdemeyer

• Component changed from doctest framework to misc
Note: See TracTickets for help on using tickets.