| | 113 | |
|---|
| | 114 | TESTS: |
|---|
| | 115 | |
|---|
| | 116 | We get a nice minimal error message for syntax errors, that still |
|---|
| | 117 | points to the location of the error (in the input string): |
|---|
| | 118 | |
|---|
| | 119 | sage: sage_eval('RR(22/7]') |
|---|
| | 120 | Traceback (most recent call last): |
|---|
| | 121 | ... |
|---|
| | 122 | File "<string>", line 1 |
|---|
| | 123 | RR(Integer(22)/Integer(7)] |
|---|
| | 124 | ^ |
|---|
| | 125 | SyntaxError: unexpected EOF while parsing |
|---|
| | 126 | |
|---|
| | 127 | sage: sage_eval('None', cmds='$x = $y[3] # Does Perl syntax work?') |
|---|
| | 128 | Traceback (most recent call last): |
|---|
| | 129 | ... |
|---|
| | 130 | File "<string>", line 1 |
|---|
| | 131 | $x = $y[Integer(3)] # Does Perl syntax work? |
|---|
| | 132 | ^ |
|---|
| | 133 | SyntaxError: invalid syntax |
|---|
| 134 | | try: |
|---|
| 135 | | if len(cmds): |
|---|
| 136 | | exec cmd_seq in sage.all.__dict__, locals |
|---|
| 137 | | return locals['_sage_eval_returnval_'] |
|---|
| 138 | | else: |
|---|
| 139 | | return eval(source, sage.all.__dict__, locals) |
|---|
| 140 | | except SyntaxError, msg: |
|---|
| 141 | | raise SyntaxError, "%s\nError using SAGE to evaluate '%s'"%(msg, cmd_seq if len(cmds) else source) |
|---|
| | 155 | |
|---|
| | 156 | if len(cmds): |
|---|
| | 157 | exec cmd_seq in sage.all.__dict__, locals |
|---|
| | 158 | return locals['_sage_eval_returnval_'] |
|---|
| | 159 | else: |
|---|
| | 160 | return eval(source, sage.all.__dict__, locals) |
|---|