more jupytr fixes
This commit is contained in:
@@ -65,32 +65,34 @@ blankc(' ').
|
||||
blankc('\n').
|
||||
blankc('\t').
|
||||
|
||||
:- dynamic cell_stream/1.
|
||||
|
||||
streams(false) :-
|
||||
nb_setval(jupyter_cell, false),
|
||||
flush_output,
|
||||
retract(cell_stream(S)),
|
||||
close(S),
|
||||
fail.
|
||||
streams(false).
|
||||
streams(true) :-
|
||||
streams( false ),
|
||||
nb_setval(jupyter_cell, true),
|
||||
\+ current_stream('/python/input',_,_),
|
||||
% \+ current_stream('/python/input',_,_),
|
||||
open('/python/input', read, Input, [alias(user_input),bom(false),script(false)]),
|
||||
assert( cell_stream( Input) ),
|
||||
set_prolog_flag(user_input,Input),
|
||||
fail.
|
||||
streams(true) :-
|
||||
\+ current_stream('/python/sys.stdout',_,_),
|
||||
open('/python/sys.stdout', append, Output, [alias(user_output)]),
|
||||
assert( cell_stream( Output) ),
|
||||
fail.
|
||||
% \+ current_stream('/python/sys.stdout',_,_),
|
||||
open('/python/sys.stdout', append, Output, [alias(user_output)]),
|
||||
set_prolog_flag(user_output, Output),
|
||||
assert( cell_stream( Output) ),
|
||||
fail.
|
||||
streams(true) :-
|
||||
\+ current_stream('/python/sys.stderr',_,_),
|
||||
% \+ current_stream('/python/sys.stderr',_,_),
|
||||
open('/python/sys.stderr', append, Error, [alias(user_error)]),
|
||||
assert( cell_stream( Error) ),
|
||||
set_prolog_flag(user_error, Error),
|
||||
fail.
|
||||
fail.
|
||||
streams(true).
|
||||
|
||||
ready(_Self, Line ) :-
|
||||
|
@@ -1,26 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import abc
|
||||
import math
|
||||
import itertools
|
||||
import trace
|
||||
|
||||
|
||||
from typing import Iterator, List, Tuple, Iterable, Union
|
||||
from traitlets import Bool, Enum, observe, Int
|
||||
from typing import List
|
||||
from traitlets import Bool
|
||||
|
||||
|
||||
from yap4py.yapi import *
|
||||
from yap_ipython.core.completer import Completer, Completion
|
||||
from yap_ipython.utils.strdispatch import StrDispatch
|
||||
from yap_ipython.core.completer import Completer
|
||||
# import yap_ipython.core
|
||||
from traitlets import Instance
|
||||
from yap_ipython.core.inputsplitter import *
|
||||
from yap_ipython.core.inputtransformer import *
|
||||
from yap_ipython.core.interactiveshell import *
|
||||
from pygments import highlight
|
||||
from pygments.lexers.prolog import PrologLexer
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
from yap_ipython.core import interactiveshell
|
||||
|
||||
@@ -38,6 +29,7 @@ exit_cell = namedtuple('exit_cell', 'self' )
|
||||
completions = namedtuple('completions', 'txt self' )
|
||||
errors = namedtuple('errors', 'self text' )
|
||||
streams = namedtuple('streams', ' text' )
|
||||
nostreams = namedtuple('nostreams', ' text' )
|
||||
|
||||
global engine
|
||||
|
||||
@@ -50,7 +42,6 @@ def tracefunc(frame, event, arg, indent=[0]):
|
||||
indent[0] -= 2
|
||||
return tracefunc
|
||||
|
||||
import sys
|
||||
|
||||
class YAPInputSplitter(InputSplitter):
|
||||
"""An input splitter that recognizes all of iyap's special syntax."""
|
||||
@@ -560,8 +551,6 @@ class YAPRun:
|
||||
pg = jupyter_query( self, program, squery)
|
||||
self.query = self.yapeng.query(pg)
|
||||
self.query.answer = {}
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
self.yapeng.mgoal(streams(True),"user", True)
|
||||
while self.query.next():
|
||||
answer = self.query.answer
|
||||
found = True
|
||||
@@ -570,7 +559,6 @@ class YAPRun:
|
||||
if self.query.port == "exit":
|
||||
self.os = None
|
||||
sys.stderr.writeln('Done, with', self.bindings)
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
return True,self.bindings
|
||||
if stop or howmany == self.iterations:
|
||||
return True, self.bindings
|
||||
@@ -579,9 +567,8 @@ class YAPRun:
|
||||
else:
|
||||
self.os = None
|
||||
self.query.close()
|
||||
`` self.query = None
|
||||
self.query = None
|
||||
sys.stderr.write('Fail\n')
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
return True,self.bindings
|
||||
except Exception as e:
|
||||
sys.stderr.write('Exception after', self.bindings, '\n')
|
||||
@@ -738,9 +725,10 @@ class YAPRun:
|
||||
# run the new command using the given tracer
|
||||
#
|
||||
# tracer.runfunc(f,self,cell,state)
|
||||
self.yapeng.mgoal(streams(True),"user", True)
|
||||
self.jupyter_query( cell )
|
||||
# state = tracer.runfunc(jupyter_query( self, cell ) )
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
# state = tracer.runfunc(jupyter_query( self, cell ) )
|
||||
self.shell.last_execution_succeeded = True
|
||||
self.result.result = (True, dicts)
|
||||
|
||||
@@ -786,7 +774,6 @@ class YAPRun:
|
||||
s = s[:i-1]
|
||||
if n:
|
||||
its = 0
|
||||
j = 0
|
||||
for ch in n:
|
||||
if not ch.isdigit():
|
||||
raise SyntaxError()
|
||||
|
Reference in New Issue
Block a user