Merge ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap
This commit is contained in:
commit
78473ddd2c
@ -171,7 +171,7 @@ static bool pygetLine(StreamDesc *rl_iostream, int sno) {
|
|||||||
PyObject_GetAttrString(s->u.private_data, "readline");
|
PyObject_GetAttrString(s->u.private_data, "readline");
|
||||||
if (!readl) {
|
if (!readl) {
|
||||||
readl =
|
readl =
|
||||||
PyObject_GetAttrString(s->u.private_data, "read");
|
PyObject_GetAttrString(s->u.private_data, "input");
|
||||||
}
|
}
|
||||||
if (readl)
|
if (readl)
|
||||||
user_line = PyObject_CallFunctionObjArgs(readl,
|
user_line = PyObject_CallFunctionObjArgs(readl,
|
||||||
|
@ -13,7 +13,6 @@ from IPython.core.inputtransformer import *
|
|||||||
from IPython.core.interactiveshell import *
|
from IPython.core.interactiveshell import *
|
||||||
from ipython_genutils.py3compat import builtin_mod
|
from ipython_genutils.py3compat import builtin_mod
|
||||||
|
|
||||||
import copy
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from yap_kernel.displayhook import ZMQShellDisplayHook
|
from yap_kernel.displayhook import ZMQShellDisplayHook
|
||||||
@ -536,14 +535,13 @@ class YAPRun(InteractiveShell):
|
|||||||
self.engine.mgoal(errors(self,text),"user",True)
|
self.engine.mgoal(errors(self,text),"user",True)
|
||||||
return self.errors
|
return self.errors
|
||||||
|
|
||||||
def prolog(self, ccell, result):
|
def prolog(self, program, squery, howmany, result):
|
||||||
|
|
||||||
#
|
#
|
||||||
# construct a self.query from a one-line string
|
# construct a self.query from a one-line string
|
||||||
# self.q is opaque to Python
|
# self.q is opaque to Python
|
||||||
try:
|
try:
|
||||||
# sys.settrace(tracefunc)
|
# sys.settrace(tracefunc)
|
||||||
(program, squery, _, howmany) = ccell
|
|
||||||
if self.q and self.os == (program,squery):
|
if self.q and self.os == (program,squery):
|
||||||
howmany += self.iterations
|
howmany += self.iterations
|
||||||
else:
|
else:
|
||||||
@ -553,6 +551,7 @@ class YAPRun(InteractiveShell):
|
|||||||
self.answers = []
|
self.answers = []
|
||||||
result.result = []
|
result.result = []
|
||||||
self.os = (program,squery)
|
self.os = (program,squery)
|
||||||
|
self.iterations = 0
|
||||||
pg = jupyter_query(self,program,squery)
|
pg = jupyter_query(self,program,squery)
|
||||||
self.q = Query(self.engine, pg)
|
self.q = Query(self.engine, pg)
|
||||||
for v in self.q:
|
for v in self.q:
|
||||||
@ -671,7 +670,6 @@ class YAPRun(InteractiveShell):
|
|||||||
except:
|
except:
|
||||||
magic = cell[2:].strip()
|
magic = cell[2:].strip()
|
||||||
body = ""
|
body = ""
|
||||||
linec = False
|
|
||||||
try:
|
try:
|
||||||
[magic,line] = magic.split(maxsplit=1)
|
[magic,line] = magic.split(maxsplit=1)
|
||||||
except:
|
except:
|
||||||
@ -680,7 +678,6 @@ class YAPRun(InteractiveShell):
|
|||||||
result.result = self.shell.run_cell_magic(magic, line, body)
|
result.result = self.shell.run_cell_magic(magic, line, body)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
linec = True
|
|
||||||
rcell = cell[1:].strip()
|
rcell = cell[1:].strip()
|
||||||
try:
|
try:
|
||||||
[magic,cell] = rcell.split(maxsplit = 1, sep = '\n')
|
[magic,cell] = rcell.split(maxsplit = 1, sep = '\n')
|
||||||
@ -697,9 +694,9 @@ class YAPRun(InteractiveShell):
|
|||||||
# Give the displayhook a reference to our ExecutionResult so it
|
# Give the displayhook a reference to our ExecutionResult so it
|
||||||
# can fill in the output value.
|
# can fill in the output value.
|
||||||
self.shell.displayhook.exec_result = result
|
self.shell.displayhook.exec_result = result
|
||||||
ccell = self.prolog_cell(cell)
|
(program,squery,_ ,howmany) = self.prolog_cell(cell)
|
||||||
(program,squery,_ ,howmany) = ccell
|
print(program, squery, howmany)
|
||||||
if howmany == 0 and not program:
|
if howmany <= 0 and not program:
|
||||||
return result
|
return result
|
||||||
if self.syntaxErrors(program+squery+".\n") :
|
if self.syntaxErrors(program+squery+".\n") :
|
||||||
result.result = []
|
result.result = []
|
||||||
@ -723,7 +720,7 @@ class YAPRun(InteractiveShell):
|
|||||||
# run the new command using the given tracer
|
# run the new command using the given tracer
|
||||||
#
|
#
|
||||||
# tracer.runfunc(f,self,cell,state)
|
# tracer.runfunc(f,self,cell,state)
|
||||||
answers = self.prolog( ccell, result )
|
answers = self.prolog( program, squery, howmany, result )
|
||||||
# state = tracer.runfunc(hist
|
# state = tracer.runfunc(hist
|
||||||
# er_query( self, cell ) )
|
# er_query( self, cell ) )
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -731,6 +728,7 @@ class YAPRun(InteractiveShell):
|
|||||||
try:
|
try:
|
||||||
(etype, value, tb) = e
|
(etype, value, tb) = e
|
||||||
traceback.print_exception(etype, value, tb)
|
traceback.print_exception(etype, value, tb)
|
||||||
|
self.engine.mgoal(streams(False),"user", True)
|
||||||
except:
|
except:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
@ -760,71 +758,74 @@ class YAPRun(InteractiveShell):
|
|||||||
|
|
||||||
|
|
||||||
def pcell(s):
|
def pcell(s):
|
||||||
"""
|
"""
|
||||||
Trasform a text into program+query. A query is the
|
Trasform a text into program+query. A query is the
|
||||||
last line if the last line is non-empty and does not terminate
|
last line if the last line is non-empty and does not terminate
|
||||||
on a dot. You can also finish with
|
on a dot. You can also finish with
|
||||||
|
|
||||||
- `*`: you request all solutions
|
- `*`: you request all solutions
|
||||||
- ';'[N]: you want an answer; optionally you want N answers
|
- ';'[N]: you want an answer; optionally you want N answers
|
||||||
|
|
||||||
If the line terminates on a `*/` or starts on a `%` we assume the line
|
If the line terminates on a `*/` or starts on a `%` we assume the line
|
||||||
is a comment.
|
is a comment.
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
sl = s.splitlines()
|
|
||||||
l = len(sl)
|
|
||||||
i = 0
|
|
||||||
while i<l:
|
|
||||||
line = sl[-i-1]
|
|
||||||
if line.strip() != '' and line[0] != '':
|
|
||||||
break
|
|
||||||
i+=1
|
|
||||||
if i == l:
|
|
||||||
return ('','','',0)
|
|
||||||
if line[-1] == '.':
|
|
||||||
return (s,'','.',0)
|
|
||||||
query = ''
|
|
||||||
while i<l:
|
|
||||||
line = sl[-i-1]
|
|
||||||
if line.strip() == '':
|
|
||||||
break
|
|
||||||
query = line+'\n\n'+query
|
|
||||||
i+=1
|
|
||||||
reps = 1
|
|
||||||
loop = ''
|
|
||||||
if query:
|
|
||||||
q = query.strip()
|
|
||||||
c = q.rpartition('?')
|
|
||||||
c2 = c[2].strip()
|
|
||||||
if c[1] == '?' and(c2=='' or c2.isdecimal()):
|
|
||||||
c = q.rpartition(';')
|
|
||||||
c2 = c[2].strip()
|
|
||||||
else:
|
|
||||||
c=(query,'','')
|
|
||||||
[q,loop,repeats] = c
|
|
||||||
if q:
|
|
||||||
query=q
|
|
||||||
if repeats.strip().isdecimal():
|
|
||||||
reps = int(repeats)
|
|
||||||
elif loop == '?':
|
|
||||||
reps = 10000000
|
|
||||||
while i<l:
|
|
||||||
line = sl[-i-1]
|
|
||||||
if line.strip() != '':
|
|
||||||
break
|
|
||||||
i+=1
|
|
||||||
program = ''
|
|
||||||
while i<l:
|
|
||||||
line = sl[-i-1]
|
|
||||||
program = line+'\n'+program
|
|
||||||
i+=1
|
|
||||||
return (program, query, loop, reps)
|
|
||||||
except Exception as e:
|
|
||||||
try:
|
try:
|
||||||
(etype, value, tb) = e
|
sl = s.splitlines()
|
||||||
traceback.print_exception(etype, value, tb)
|
l = len(sl)
|
||||||
except:
|
i = 0
|
||||||
print(e)
|
while i<l:
|
||||||
|
line = sl[-i-1]
|
||||||
|
if line.strip() != '' and line[0] != '':
|
||||||
|
break
|
||||||
|
i+=1
|
||||||
|
if i == l:
|
||||||
|
return ('','','',0)
|
||||||
|
if line[-1] == '.':
|
||||||
|
return (s,'','.',0)
|
||||||
|
query = ''
|
||||||
|
loop = ''
|
||||||
|
while i<l:
|
||||||
|
line = sl[-i-1]
|
||||||
|
if line.strip() == '':
|
||||||
|
break
|
||||||
|
query = line+'\n\n'+query
|
||||||
|
i+=1
|
||||||
|
reps = 1
|
||||||
|
if query:
|
||||||
|
q = query.strip()
|
||||||
|
c= q.rpartition('?')
|
||||||
|
if not c[1]:
|
||||||
|
c= q.rpartition(';')
|
||||||
|
c2 = c[2].strip()
|
||||||
|
if len(c[1]) == 1 and c[0].strip():
|
||||||
|
c2 = c[2].strip()
|
||||||
|
query = c[0]
|
||||||
|
if c2.isdecimal():
|
||||||
|
reps = int(c2)
|
||||||
|
elif c2:
|
||||||
|
return ('',c[1]+c[2],c[1],-1)
|
||||||
|
elif c[1] == '?':
|
||||||
|
reps = 1
|
||||||
|
else:
|
||||||
|
reps = 10000000000
|
||||||
|
loop = c[1]
|
||||||
|
while i<l:
|
||||||
|
line = sl[-i-1]
|
||||||
|
if line.strip() != '':
|
||||||
|
break
|
||||||
|
i+=1
|
||||||
|
program = ''
|
||||||
|
while i<l:
|
||||||
|
line = sl[-i-1]
|
||||||
|
program = line+'\n\n'+program
|
||||||
|
i+=1
|
||||||
|
return (program, query, loop, reps)
|
||||||
|
except Exception as e:
|
||||||
|
try:
|
||||||
|
(etype, value, tb) = e
|
||||||
|
traceback.print_exception(etype, value, tb)
|
||||||
|
except:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user