notebook
This commit is contained in:
parent
94a826efcc
commit
19fef7d6ac
12
os/format.c
12
os/format.c
@ -1114,7 +1114,7 @@ static Int with_output_to(USES_REGS1) {
|
||||
static Int format(Term tf, Term tas, Term tout USES_REGS) {
|
||||
Int out;
|
||||
Functor f;
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
int output_stream;
|
||||
bool mem_stream = false;
|
||||
|
||||
if (IsVarTerm(tout)) {
|
||||
@ -1122,17 +1122,17 @@ static Int format(Term tf, Term tas, Term tout USES_REGS) {
|
||||
return false;
|
||||
}
|
||||
yhandle_t hl = Yap_StartHandles(), yo = Yap_PushHandle(tout);
|
||||
if (IsApplTerm(tout) && (f = FunctorOfTerm(tout))) {
|
||||
if (f == FunctorAtom || f == FunctorString1 || f == FunctorCodes1 ||
|
||||
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars){
|
||||
if (IsApplTerm(tout) && (f = FunctorOfTerm(tout)) &&
|
||||
(f == FunctorAtom || f == FunctorString1 || f == FunctorCodes1 ||
|
||||
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars) ){
|
||||
output_stream = Yap_OpenBufWriteStream(PASS_REGS1);
|
||||
mem_stream = true;
|
||||
}
|
||||
if (!mem_stream) {
|
||||
if (output_stream <0 ||!mem_stream) {
|
||||
UNLOCK(GLOBAL_Stream[output_stream].streamlock);
|
||||
/* needs to change LOCAL_c_output_stream for write */
|
||||
output_stream = Yap_CheckStream(tout, Output_Stream_f, "format/3");
|
||||
}
|
||||
}
|
||||
if (output_stream == -1) {
|
||||
UNLOCK(GLOBAL_Stream[output_stream].streamlock);
|
||||
return false;
|
||||
|
36
os/iopreds.c
36
os/iopreds.c
@ -1761,6 +1761,42 @@ int Yap_CheckTextStream__(const char *file, const char *f, int line, Term arg,
|
||||
return sno;
|
||||
}
|
||||
|
||||
int Yap_CheckTextWriteStream__(const char *file, const char *f, int line, Term arg,
|
||||
const char *msg) {
|
||||
int sno, kind = Output_Stream_f;
|
||||
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
|
||||
return -1;
|
||||
if ((GLOBAL_Stream[sno].status & Binary_Stream_f)) {
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
if (kind & Output_Stream_f)
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_INPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
else
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_OUTPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
return -1;
|
||||
}
|
||||
return sno;
|
||||
}
|
||||
|
||||
int Yap_CheckTextReadStream__(const char *file, const char *f, int line, Term arg,
|
||||
const char *msg) {
|
||||
int sno, kind = Input_Stream_f;
|
||||
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
|
||||
return -1;
|
||||
if ((GLOBAL_Stream[sno].status & Binary_Stream_f)) {
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
if (kind & Input_Stream_f)
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_INPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
else
|
||||
PlIOError__(file, f, line, PERMISSION_ERROR_OUTPUT_BINARY_STREAM, arg,
|
||||
msg);
|
||||
return -1;
|
||||
}
|
||||
return sno;
|
||||
}
|
||||
|
||||
int Yap_CheckBinaryStream__(const char *file, const char *f, int line, Term arg,
|
||||
int kind, const char *msg) {
|
||||
int sno;
|
||||
|
11
os/iopreds.h
11
os/iopreds.h
@ -43,7 +43,16 @@ extern int Yap_CheckStream__(const char *, const char *, int, Term, int,
|
||||
extern int Yap_CheckTextStream__(const char *, const char *, int, Term, int,
|
||||
const char *);
|
||||
|
||||
#define Yap_CheckBinaryStream(arg, kind, msg) \
|
||||
#define Yap_CheckTextReadStream(arg, msg) \
|
||||
Yap_CheckTextReadStream__(__FILE__, __FUNCTION__, __LINE__, arg, msg)
|
||||
extern int Yap_CheckTextReadStream__(const char *, const char *, int, Term,
|
||||
const char *);
|
||||
#define Yap_CheckTextWriteStream(arg, msg) \
|
||||
Yap_CheckTextWriteStream__(__FILE__, __FUNCTION__, __LINE__, arg, msg)
|
||||
extern int Yap_CheckTextWriteStream__(const char *, const char *, int, Term,
|
||||
const char *);
|
||||
|
||||
#define Yap_CheckBinaryStream(arg, kind, msg) \
|
||||
Yap_CheckBinaryStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
||||
extern int Yap_CheckBinaryStream__(const char *, const char *, int, Term, int,
|
||||
const char *);
|
||||
|
@ -280,7 +280,7 @@ set (RENAMED_RESOURCES
|
||||
# yap_kernel/resources/codemirror/mode/prolog/prolog.js
|
||||
)
|
||||
|
||||
set (PL_SOURCES yap_ipython/prolog/jupyter.yap
|
||||
set (PL_SOURCES yap_ipython/prolog/jupyter.yap yap_ipython/prolog/complete.yap
|
||||
)
|
||||
|
||||
set(FILES ${PYTHON_SOURCES} ${PL_SOURCES} ${EXTRAS} ${RESOURCES})
|
||||
|
123
packages/python/yap_kernel/yap_ipython/prolog/complete.yap
Normal file
123
packages/python/yap_kernel/yap_ipython/prolog/complete.yap
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* @file complete.yap
|
||||
*
|
||||
* @brief Prolog completer.
|
||||
*/
|
||||
|
||||
:- module( completer,
|
||||
[
|
||||
completions/2.
|
||||
]).
|
||||
|
||||
:- use_module(library(lists)).
|
||||
:- use_module(library(maplist)).
|
||||
:- use_module(library(python)).
|
||||
|
||||
%% completions( +Text, +PythonCell )
|
||||
%
|
||||
% Tries to complete the current text. The list with the set of completions
|
||||
% is stored in the
|
||||
% `matches` field of the python object.
|
||||
%
|
||||
completions(S, Self) :-
|
||||
open_mem_read_stream(S, St),
|
||||
scan_to_list(St, Tokens),
|
||||
close(St),
|
||||
reverse(Tokens, RTokens),
|
||||
strip_final_tokens(RTokens, MyTokens),
|
||||
setof( Completion, complete(MyTokens, Completion), Cs),
|
||||
Self.matches := Cs.
|
||||
|
||||
|
||||
strip_final_tokens(['EOT'|Ts], Ts) :- !.
|
||||
strip_final_tokens( Ts, Ts ).
|
||||
|
||||
complete([E,l,C,l,A|More],
|
||||
isconsult(A),
|
||||
%B = l,
|
||||
library(C,Lib),
|
||||
%D=l,
|
||||
E=atom(Prefix),
|
||||
\+ arg( Rest ),
|
||||
check_library( Prefix, Lib, C).
|
||||
complete([E,l,C,l,-,'['|More],
|
||||
isconsult(A),
|
||||
%B = l,
|
||||
library(C,Lib),
|
||||
%D=l,
|
||||
E=atom(Prefix),
|
||||
\+ arg( Rest ),
|
||||
check_library( Prefix, Lib, C).
|
||||
complete([C,l,A|More],
|
||||
isconsult(A),
|
||||
%B = l,
|
||||
C=atom(Prefix),
|
||||
\+ arg( Rest ),
|
||||
file_or_library( Prefix, C).
|
||||
complete([C,l,-,'['|More],
|
||||
isconsult(A),
|
||||
%B = l,
|
||||
C=atom(Prefix),
|
||||
\+ arg( Rest ),
|
||||
file_or_library( Prefix, C).
|
||||
complete( [atom(F)|Rest], C) :-
|
||||
\+ arg( Rest ),
|
||||
predicate( F, Pred, Arity ),
|
||||
cont( Arity, F, Pred, C).
|
||||
|
||||
isconsult( atom(use_module) ).
|
||||
isconsult( atom(ensure_loaded) ).
|
||||
isconsult( atom(compile) ).
|
||||
isconsult( atom(consult) ).
|
||||
isconsult( atom(reconsult) ).
|
||||
isconsult( atom(load_files) ).
|
||||
isconsult( '[' ).
|
||||
|
||||
arg([']'|_]).
|
||||
arg([l|_]).
|
||||
|
||||
file_or_library(F,C) :-
|
||||
libsym(C0),
|
||||
atom_cooncat(F,C,C0).
|
||||
file_or_library(F,C) :-
|
||||
check_file(F,C).
|
||||
|
||||
check_file(F0,C) :-
|
||||
atom_concat('\'',F,F0),
|
||||
!,
|
||||
absolute_file_name( F, FF, [access(none)] ),
|
||||
atom_concat( FF, '*' , Pat),
|
||||
absolute_file_name( Pat, C0, [glob(true)] ),
|
||||
atom_concat(Pat,C00,C0),
|
||||
atom_conct(C00,'\'',C).
|
||||
check_file(F0,C) :-
|
||||
atom_concat( F0, '*' , Pat),
|
||||
absolute_file_name( Pat, C0, [glob(true)] ),
|
||||
atom_concat(Pat,C,C0).
|
||||
|
||||
check_library( Lib, F, C) :-
|
||||
atom_concat( F, '*' , Pat),
|
||||
LibF =.. [Lib(Pat)],
|
||||
absolute_file_name( LibF, Lib, [glob(true)] ),
|
||||
file_directory_name( Lib, Name),
|
||||
( atom_concat(C, '.yap', Name) -> true ;
|
||||
atom_concat(C, '.ypp', Name) -> true ;
|
||||
atom_concat(C, '.prolog', Name) -> true
|
||||
).
|
||||
|
||||
predicate(N,P,A) :-
|
||||
system_predicate(P0/A),
|
||||
atom_concat(N,P,P0).
|
||||
predicate(N,P,A) :-
|
||||
current_predicate(P0/A),
|
||||
atom_concat(N,P,P0).
|
||||
|
||||
cont(0, F, P, P0) :-
|
||||
atom_concat( F, P, P0 ).
|
||||
cont( _, F, P, PB ):-
|
||||
atom_concat( [F, P, '( )'], PB ).
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
:- use_module(library(python)).
|
||||
:- use_module(library(yapi)).
|
||||
:- use_module(library(complete)).
|
||||
|
||||
:- python_import(sys).
|
||||
|
||||
|
@ -579,7 +579,7 @@ 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
|
||||
|
Reference in New Issue
Block a user