jupyter
This commit is contained in:
parent
c0f7dfe3c3
commit
7383ff79cc
@ -661,7 +661,7 @@ class YAPRun(InteractiveShell):
|
|||||||
self.cell_name = str( self.shell.execution_count)
|
self.cell_name = str( self.shell.execution_count)
|
||||||
self.shell.displayhook.exec_result= result
|
self.shell.displayhook.exec_result= result
|
||||||
cell = raw_cell.strip()
|
cell = raw_cell.strip()
|
||||||
while cell[0] == '%':
|
while cell and cell[0] == '%':
|
||||||
if cell[1] == '%':
|
if cell[1] == '%':
|
||||||
## cell magic
|
## cell magic
|
||||||
txt0 = cell[2:].split(maxsplit = 1, sep = '\n')
|
txt0 = cell[2:].split(maxsplit = 1, sep = '\n')
|
||||||
@ -756,75 +756,75 @@ class YAPRun(InteractiveShell):
|
|||||||
|
|
||||||
|
|
||||||
def prolog_cell(self, s):
|
def prolog_cell(self, s):
|
||||||
"""
|
return pcell(s)
|
||||||
Trasform a text into program+query. A query is the
|
|
||||||
last line if the last line is non-empty and does not terminate
|
|
||||||
on a dot. You can also finish with
|
|
||||||
|
|
||||||
- `*`: you request all solutions
|
|
||||||
- ';'[N]: you want an answer; optionally you want N answers
|
|
||||||
|
|
||||||
If the line terminates on a `*/` or starts on a `%` we assume the line
|
def pcell(s):
|
||||||
is a comment.
|
"""
|
||||||
"""
|
Trasform a text into program+query. A query is the
|
||||||
try:
|
last line if the last line is non-empty and does not terminate
|
||||||
sl = s.splitlines()
|
on a dot. You can also finish with
|
||||||
l = len(sl)
|
|
||||||
i = 0
|
- `*`: you request all solutions
|
||||||
while i<l:
|
- ';'[N]: you want an answer; optionally you want N answers
|
||||||
line = sl[-i-1]
|
|
||||||
if line.strip() != '' and line[0] != '':
|
If the line terminates on a `*/` or starts on a `%` we assume the line
|
||||||
break
|
is a comment.
|
||||||
i+=1
|
"""
|
||||||
if i == l:
|
try:
|
||||||
return ('','','',0)
|
sl = s.splitlines()
|
||||||
if line[-1] == '.':
|
l = len(sl)
|
||||||
return (s,'','.',0)
|
i = 0
|
||||||
query = ''
|
while i<l:
|
||||||
while i<l:
|
line = sl[-i-1]
|
||||||
line = sl[-i-1]
|
if line.strip() != '' and line[0] != '':
|
||||||
if line.strip() == '':
|
break
|
||||||
break
|
i+=1
|
||||||
query = line+'\n\n'+query
|
if i == l:
|
||||||
i+=1
|
return ('','','',0)
|
||||||
reps = 1
|
if line[-1] == '.':
|
||||||
if query:
|
return (s,'','.',0)
|
||||||
q = query.strip()
|
query = ''
|
||||||
c= q.rpartition('*')
|
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()
|
c2 = c[2].strip()
|
||||||
if c[1] != '*' or (c2!='' and not c2.isdecimal()):
|
else:
|
||||||
c = q.rpartition('?')
|
c=(query,'','')
|
||||||
c2 = c[2].strip()
|
[q,loop,repeats] = c
|
||||||
if c[1] == '?' and(c2=='' or c2.isdecimal()):
|
if q:
|
||||||
c = q.rpartition(';')
|
query=q
|
||||||
c2 = c[2].strip()
|
if repeats.strip().isdecimal():
|
||||||
else:
|
reps = int(repeats)
|
||||||
c=('','',query)
|
elif loop == '?':
|
||||||
[q,loop,repeats] = c
|
reps = 10000000
|
||||||
if q:
|
while i<l:
|
||||||
query=q
|
line = sl[-i-1]
|
||||||
if repeats.strip().isdecimal():
|
if line.strip() != '':
|
||||||
reps = int(repeats)
|
break
|
||||||
sep = sepator
|
i+=1
|
||||||
elif loop == '*':
|
program = ''
|
||||||
reps = -1
|
while i<l:
|
||||||
elif loop == '?':
|
line = sl[-i-1]
|
||||||
reps = 10
|
program = line+'\n'+program
|
||||||
while i<l:
|
i+=1
|
||||||
line = sl[-i-1]
|
return (program, query, loop, reps)
|
||||||
if line.strip() != '':
|
except Exception as e:
|
||||||
break
|
try:
|
||||||
i+=1
|
(etype, value, tb) = e
|
||||||
program = ''
|
traceback.print_exception(etype, value, tb)
|
||||||
while i<l:
|
except:
|
||||||
line = sl[-i-1]
|
print(e)
|
||||||
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