diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
index d7187670d..526e72e00 100644
--- a/docs/CMakeLists.txt
+++ b/docs/CMakeLists.txt
@@ -90,8 +90,8 @@ endforeach(i ${DOCS_EXCLUDE_})
add_subdirectory(../packages/raptor/doc ${CMAKE_BINARY_DIR}/packages/raptor/doc)
SET(DOC_INPUT_FILES_
- ${CMAKE_SOURCE_DIR}/pl
${CMAKE_SOURCE_DIR}/docs/md
+ ${CMAKE_SOURCE_DIR}/pl
${CMAKE_SOURCE_DIR}/CXX
${CMAKE_SOURCE_DIR}/OPTYap
${CMAKE_SOURCE_DIR}/C
diff --git a/docs/md/builtins.md b/docs/md/builtins.md
index 0ccb3ecfc..10dd33d6b 100644
--- a/docs/md/builtins.md
+++ b/docs/md/builtins.md
@@ -20,4 +20,6 @@ notation will be used:
+ an argument with no preceding symbol can be used in both ways.
-@{
\ No newline at end of file
+[TOC]
+
+@}
diff --git a/docs/md/fli.md b/docs/md/fli.md
index 7bd0b5e61..453f9bb64 100644
--- a/docs/md/fli.md
+++ b/docs/md/fli.md
@@ -127,8 +127,8 @@ The rest of this appendix describes exhaustively how to interface C to YAP.
@}
@defgroup Manipulating_Terms Terms
-@{
@ingroup ChYInterface
+@{
This section provides information about the primitives available to the C
programmer for manipulating Prolog terms.
@@ -504,8 +504,8 @@ code. Slots can also be used if there is small state.
@}
@defgroup Unifying_Terms Unification
-@{
@ingroup ChYInterface
+@{
YAP provides a single routine to attempt the unification of two Prolog
terms. The routine may succeed or fail:
@@ -522,8 +522,8 @@ otherwise.
@}
@defgroup CallYAP Using the compiler:
-@{
@ingroup Manipulating_Strings Strings
+@{
The YAP C-interface now includes an utility routine to copy a string
@@ -608,8 +608,8 @@ and -1 on error.
@}
@defgroup Memory_Allocation Memory Allocation
-@{
@ingroup ChYInterface
+@{
The next routine can be used to ask space from the Prolog data-base:
@@ -638,8 +638,8 @@ area.
@}
@defgroup Controlling_Streams Controlling YAP Streams from `C`
-@{
@ingroup ChYInterface
+@{
The C-Interface also provides the C-application with a measure of
control over the YAP Input/Output system. The first routine allows one
@@ -698,8 +698,8 @@ the name by which YAP should know the new stream.
@}
@defgroup Utility_Functions Utility Functions in `C
-@{
@ingroup ChYInterface
+@{
The C-Interface provides the C-application with a a number of utility
functions that are useful.
@@ -794,9 +794,8 @@ ignore the variable.
@}
@defgroup Calling_YAP_From_C From `C` back to Prolog
-@{
@ingroup ChYInterface
-### From `C` back to Prolog {#Calling_YAP_From_C}
+@{
There are several ways to call Prolog code from C-code. By default, the
`YAP_RunGoal()` should be used for this task. It assumes the engine
@@ -967,8 +966,8 @@ have moved the terms
@}
@defgroup CallYAP Using the compiler:
-@{
@ingroup Module_Manipulation_in_C Module Manipulation in C
+@{
YAP allows one to create a new module from C-code. To create the new
code it is sufficient to call:
@@ -998,8 +997,8 @@ Notice that this function returns a term, and not an atom. You can
@}
@defgroup Miscellaneous_ChYFunctions Miscellaneous C Functions
-@{
@ingroup ChYInterface
+@{
- `void` YAP_Throw(`YAP_Term exception`)
@@ -1064,9 +1063,8 @@ of such arguments.
@}
@defgroup Writing_C Writing predicates in C
-@{
@ingroup ChYInterface
-### Writing predicates in C {#Writing_C}
+@{
We will distinguish two kinds of predicates:
@@ -1321,8 +1319,8 @@ in this case no code is executed at cut time.
@}
@defgroup YAP4_Notes Changes to the C-Interface in YAP4
-@{
@ingroup ChYInterface
+@{
YAP4 includes several changes over the previous `load_foreign_files/3`
interface. These changes were required to support the new binary code
@@ -1361,8 +1359,8 @@ arguments to the backtrackable procedure.
@}
@defgroup YAPAsLibrary Using YAP as a Library
-@{
@ingroup ChYInterface
+@{
YAP can be used as a library to be called from other
programs. To do so, you must first create the YAP library:
diff --git a/docs/md/library.md b/docs/md/library.md
index 0523ef553..df4c683e2 100644
--- a/docs/md/library.md
+++ b/docs/md/library.md
@@ -6,4 +6,6 @@
`LIBDIR` variable in the Makefile for YAP). Several files in the
library are originally from the public-domain Edinburgh Prolog library.
+[TOC]
+
@}
diff --git a/docs/md/programming.md b/docs/md/programming.md
index e454649b7..fab7f501d 100644
--- a/docs/md/programming.md
+++ b/docs/md/programming.md
@@ -141,7 +141,7 @@ We present the main predicates and directives available to load
their public predicates into the current type-in module. It is
implemented as if by:
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.yap}
use_module(F) :-
load_files(F, [if(not_loaded),must_be_module(true)]).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/misc/editors/prolog.js b/misc/editors/prolog.js
index 566b3851b..a9c36aba1 100644
--- a/misc/editors/prolog.js
+++ b/misc/editors/prolog.js
@@ -2,1282 +2,1394 @@
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
- if (typeof exports == "object" && typeof module == "object") // CommonJS
- mod(require("codemirror/lib/codemirror"));
- else if (typeof define == "function" && define.amd) // AMD
- define(["codemirror/lib/codemirror"], mod);
- else // Plain browser env
- mod(CodeMirror);
+if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("codemirror/lib/codemirror"));
+else if (typeof define == "function" && define.amd) // AMD
+ define([ "codemirror/lib/codemirror" ], mod);
+else // Plain browser env
+ mod(CodeMirror);
})(function(CodeMirror) {
- "use strict";
-
- CodeMirror.defineMode("prolog", function(cmConfig, modeConfig) {
-
- function chain(stream, state, f) {
- state.tokenize = f;
- return f(stream, state);
- }
-
- /*******************************
- * CONFIG DATA *
- *******************************/
-
- var config = { quasiQuotations: false, /* {|Syntax||Quotation|} */
- indot: true, /* a.b */
- dicts: false, /* tag{k:v, ...} */
- unicodeEscape: true, /* \uXXXX and \UXXXXXXXX */
- multiLineQuoted: true, /* "...\n..." */
- groupedIntegers: false /* 10 000 or 10_000 */
- };
-v
- var quoteType = { '"': "string",
- "'": "qatom",
- "`": "bqstring"
- };
-
- var isSingleEscChar = /[abref\\'"nrtsv]/;
- var isOctalDigit = /[0-7]/;
- var isHexDigit = /[0-9a-fA-F]/;
-
- var isSymbolChar = /[-#$&*+./:<=>?@\\^~]/; /* Prolog glueing symbols chars */
- var isSoloChar = /[[\]{}(),;|!]/; /* Prolog solo chars */
- var isNeck = /^(:-|-->)$/;
- var isControlOp = /^(,|;|->|\*->|\\+|\|)$/;
-
-
- /*******************************
- * CHARACTER ESCAPES *
- *******************************/
-
- function readDigits(stream, re, count) {
- if ( count > 0 ) {
- while( count-- > 0 ) {
- if ( !re.test(stream.next()) )
- return false;
- }
- } else {
- while ( re.test(stream.peek()) )
- stream.next();
- }
- return true;
- }
-
- function readEsc(stream) {
- var next = stream.next();
- if ( isSingleEscChar.test(next) )
- return true;
- switch( next )
- { case "u":
- if ( config.unicodeEscape )
- return readDigits(stream, isHexDigit, 4); /* SWI */
- return false;
- case "U":
- if ( config.unicodeEscape )
- return readDigits(stream, isHexDigit, 8); /* SWI */
- return false;
- case null: return true; /* end of line */
- case "c": stream.eatSpace(); return true;
- case "x": return readDigits(stream, isHexDigit, 2);
- }
- if ( isOctalDigit.test(next) ) {
- if ( !readDigits(stream, isOctalDigit, -1) )
- return false;
- if ( stream.peek() == "\\" ) /* SWI: optional closing \ */
- stream.next();
- return true;
- }
- return false;
- }
-
- function nextUntilUnescaped(stream, state, end) {
- var next;
- while ((next = stream.next()) != null) {
- if ( next == end && end != stream.peek() )
- { state.nesting.pop();
- return false;
- }
- if ( next == "\\" )
- { if ( !readEsc(stream) )
- return false;
- }
- }
- return config.multiLineQuoted;
- }
-
- /*******************************
- * CONTEXT NESTING *
- *******************************/
-
- function nesting(state) {
- return state.nesting.slice(-1)[0];
- }
-
- /* Called on every non-comment token */
- function setArg1(state) {
- var nest = nesting(state);
- if ( nest ) {
- if ( nest.arg == 0 ) /* nested in a compound */
- nest.arg = 1;
- else if ( nest.type == "control" )
- state.goalStart = false;
- } else
- state.goalStart = false;
- }
-
- function setArgAlignment(state) {
- var nest = nesting(state);
- if ( nest && !nest.alignment && nest.arg != undefined ) {
- if ( nest.arg == 0 )
- nest.alignment = nest.leftCol ? nest.leftCol+4 : nest.column+4;
- else
- nest.alignment = nest.column+1;
- }
- }
-
- function nextArg(state) {
- var nest = nesting(state);
- if ( nest ) {
- if ( nest.arg ) /* nested in a compound */
- nest.arg++;
- else if ( nest.type == "control" )
- state.goalStart = true; /* FIXME: also needed for ; and -> */
- } else
- state.goalStart = true;
- }
-
- function isControl(state) { /* our terms are goals */
- var nest = nesting(state);
- if ( nest ) {
- if ( nest.type == "control" ) {
- return true;
- }
- return false;
- } else
- return state.inBody;
- }
-
- // Used as scratch variables to communicate multiple values without
- // consing up tons of objects.
- var type, content;
- function ret(tp, style, cont) {
- type = tp; content = cont;
- return style;
- }
-
- function peekSpace(stream) { /* TBD: handle block comment as space */
- if ( stream.eol() ||
- /[\s%]/.test(stream.peek()) )
- return true;
- return false;
- }
-
-
- /*******************************
- * SUB TOKENISERS *
- *******************************/
-
- function plTokenBase(stream, state) {
- var ch = stream.next();
-
- if ( ch == "(" ) {
- if ( state.lastType == "functor" ) {
- state.nesting.push({ functor: state.functorName,
- column: stream.column(),
- leftCol: state.functorColumn,
- arg: 0
- });
- delete state.functorName;
- delete state.functorColumn;
- } else {
- state.nesting.push({ type: "control",
- closeColumn: stream.column(),
- alignment: stream.column()+4
- });
- }
- return ret("solo", null, "(");
- }
-
- if ( ch == "{" && state.lastType == "tag" ) {
- state.nesting.push({ tag: state.tagName,
- column: stream.column(),
- leftCol: state.tagColumn,
- arg: 0
- });
- delete state.tagName;
- delete state.tagColumn;
- return ret("dict_open", null);
- }
-
- if ( ch == "/" && stream.eat("*") )
- return chain(stream, state, plTokenComment);
-
- if ( ch == "%" ) {
- stream.skipToEnd();
- return ret("comment", "comment");
- }
-
- setArg1(state);
-
- if ( isSoloChar.test(ch) ) {
- switch ( ch )
- { case ")":
- state.nesting.pop();
- break;
- case "]":
- state.nesting.pop();
- return ret("list_close", null);
- case "}":
- { var nest = nesting(state);
- var type = (nest && nest.tag) ? "dict_close" : "brace_term_close";
-
- state.nesting.pop();
- return ret(type, null);
- }
- case ",":
- if ( stream.eol() )
- state.commaAtEOL = true;
- nextArg(state);
- /*FALLTHROUGH*/
- case ";":
- if ( isControl(state) )
- state.goalStart = true;
- break;
- case "[":
- state.nesting.push({ type: "list",
- closeColumn: stream.column(),
- alignment: stream.column()+2
- });
- return ret("list_open", null);
- break;
- case "{":
- if ( config.quasiQuotations && stream.eat("|") ) {
- state.nesting.push({ type: "quasi-quotation",
- alignment: stream.column()+1
- });
- return ret("qq_open", "qq_open");
- } else {
- state.nesting.push({ type: "curly",
- closeColumn: stream.column(),
- alignment: stream.column()+2
- });
- return ret("brace_term_open", null);
- }
- break;
- case "|":
- if ( config.quasiQuotations ) {
- if ( stream.eat("|") ) {
- state.tokenize = plTokenQuasiQuotation;
- return ret("qq_sep", "qq_sep");
- } else if ( stream.eat("}") ) {
- state.nesting.pop();
- return ret("qq_close", "qq_close");
- }
- }
- if ( isControl(state) )
- state.goalStart = true;
- break;
- }
- return ret("solo", null, ch);
- }
-
- if (ch == '"' || ch == "'" || ch == "`")
- { state.nesting.push({ type: "quoted",
- alignment: stream.column()+1
- });
- return chain(stream, state, plTokenString(ch));
- }
-
- if ( ch == "0" ) {
- if ( stream.eat(/x/i)) {
- stream.eatWhile(/[\da-f]/i);
- return ret("number", "number");
- }
- if ( stream.eat(/o/i)) {
- stream.eatWhile(/[0-7]/i);
- return ret("number", "number");
- }
- if ( stream.eat(/'/) ) { /* 0' */
- var next = stream.next();
- if ( next == "\\" ) {
- if ( !readEsc(stream) )
- return ret("error", "error");
- }
- return ret("code", "code");
- }
- }
-
- if ( /\d/.test(ch) || /[+-]/.test(ch) && stream.eat(/\d/)) {
- if ( config.groupedIntegers )
- stream.match(/^\d*((_|\s+)\d+)*(?:\.\d+)?(?:[eE][+\-]?\d+)?/);
- else
- stream.match(/^\d*(?:\.\d+)?(?:[eE][+\-]?\d+)?/);
- return ret(ch == "-" ? "neg-number" :
- ch == "+" ? "pos-number" :
- "number");
- }
-
- if ( isSymbolChar.test(ch) ) {
- stream.eatWhile(isSymbolChar);
- var atom = stream.current();
- if ( atom == "." && peekSpace(stream) ) {
- if ( nesting(state) ) {
- return ret("fullstop", "error", atom);
- } else {
- } return ret("fullstop", "fullstop", atom);
- } else if ( isNeck.test(atom) ) {
- return ret("neck", "neck", atom);
- } else if ( isControl(state) && isControlOp.test(atom) ) {
- state.goalStart = true;
- return ret("symbol", "operator", atom);
- } else
- return ret("symbol", "operator", atom);
- }
-
- stream.eatWhile(/[\w_]/);
- var word = stream.current();
- if ( stream.peek() == "{" && config.dicts ) {
- state.tagName = word; /* tmp state extension */
- state.tagColumn = stream.column();
- return ret("tag", "tag", word);
- } else if ( ch == "_" ) {
- if ( word.length == 1 ) {
- return ret("var", "anon", word);
- } else {
- var sec = word.charAt(1);
- if ( sec == sec.toUpperCase() )
- return ret("var", "var-2", word);
- }
- return ret("var", "var", word);
- } else if ( ch == ch.toUpperCase() ) {
- return ret("var", "var", word);
- } else if ( stream.peek() == "(" ) {
- state.functorName = word; /* tmp state extension */
- state.functorColumn = stream.column();
- return ret("functor", "functor", word);
- } else
- return ret("atom", "atom", word);
- }
-
- function plTokenString(quote) {
- return function(stream, state) {
- if (!nextUntilUnescaped(stream, state, quote)) {
- state.tokenize = plTokenBase;
- if ( stream.peek() == "(" ) { /* 'quoted functor'() */
- var word = stream.current();
- state.functorName = word; /* tmp state extension */
- return ret("functor", "functor", word);
- }
- if ( stream.peek() == "{" && config.dicts ) { /* 'quoted tag'{} */
- var word = stream.current();
- state.tagName = word; /* tmp state extension */
- return ret("tag", "tag", word);
- }
- }
- return ret(quoteType[quote], quoteType[quote]);
- };
- }
-
- function plTokenQuasiQuotation(stream, state) {
- var maybeEnd = false, ch;
- while (ch = stream.next()) {
- if (ch == "}" && maybeEnd) {
- state.tokenize = plTokenBase;
- stream.backUp(2);
- break;
- }
- maybeEnd = (ch == "|");
- }
- return ret("qq_content", "qq_content");
- }
-
- function plTokenComment(stream, state) {
- var maybeEnd = false, ch;
- while (ch = stream.next()) {
- if (ch == "/" && maybeEnd) {
- state.tokenize = plTokenBase;
- break;
- }
- maybeEnd = (ch == "*");
- }
- return ret("comment", "comment");
- }
-
-
- // /*******************************
- // * ACTIVE KEYS *
- // *******************************/
-
- // /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // Support if-then-else layout like this:
-
- // goal :-
- // ( Condition
- // -> IfTrue
- // ; IfFalse
- // ).
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-
-
- // CodeMirror.commands.prologStartIfThenElse = function(cm) {
- // var start = cm.getCursor("start");
- // var token = cm.getTokenAt(start, true);
-
- // if ( token.state.goalStart == true )
- // { cm.replaceSelection("( ", "end");
- // return;
- // }
-
- // return CodeMirror.Pass;
- // }
-
- // CodeMirror.commands.prologStartThen = function(cm) {
- // var start = cm.getCursor("start");
- // var token = cm.getTokenAt(start, true);
-
- // /* FIXME: These functions are copied from prolog.js. How
- // can we reuse these?
- // */
- // function nesting(state) {
- // var len = state.nesting.length;
- // if ( len > 0 )
- // return state.nesting[len-1];
- // return null;
- // }
-
- // function isControl(state) { /* our terms are goals */
- // var nest = nesting(state);
- // if ( nest ) {
- // if ( nest.type == "control" ) {
- // return true;
- // }
- // return false;
- // } else
- // return state.inBody;
- // }
-
- // if ( start.ch == token.end &&
- // token.type == "operator" &&
- // token.string == "-" &&
- // isControl(token.state) )
- // { cm.replaceSelection("> ", "end");
- // return;
- // }
-
- // return CodeMirror.Pass;
- // }
-
- // CodeMirror.commands.prologStartElse = function(cm) {
- // var start = cm.getCursor("start");
- // var token = cm.getTokenAt(start, true);
-
- // if ( token.start == 0 && start.ch == token.end &&
- // !/\S/.test(token.string) )
- // { cm.replaceSelection("; ", "end");
- // return;
- // }
-
- // return CodeMirror.Pass;
- // }
-
- // CodeMirror.defineOption("prologKeys", null, function(cm, val, prev) {
- // if (prev && prev != CodeMirror.Init)
- // cm.removeKeyMap("prolog");
- // if ( val ) {
- // var map = { name: "prolog",
- // "'('": "prologStartIfThenElse",
- // "'>'": "prologStartThen",
- // "';'": "prologStartElse",
- // "Ctrl-L": "refreshHighlight"
- // };
- // cm.addKeyMap(map);
- // }
- // });
-
- // });
- //Default (SWI-)Prolog operator table. To be used later to enhance the
- //offline experience.
-
- var ops = { "-->": { p:1200, t:"xfx" },
- ":-": [ { p:1200, t:"xfx" },
- { p:1200, t:"fx" }
- ],
- "?-": { p:1200, t:"fx" },
-
- "dynamic": { p:1150, t:"fx" },
- "discontiguous": { p:1150, t:"fx" },
- "initialization": { p:1150, t:"fx" },
- "meta_predicate": { p:1150, t:"fx" },
- "module_transparent": { p:1150, t:"fx" },
- "multifile": { p:1150, t:"fx" },
- "thread_local": { p:1150, t:"fx" },
- "volatile": { p:1150, t:"fx" },
-
- ";": { p:1100, t:"xfy" },
- "|": { p:1100, t:"xfy" },
-
- "->": { p:1050, t:"xfy" },
- "*->": { p:1050, t:"xfy" },
-
- ",": { p:1000, t:"xfy" },
-
- "\\+": { p:900, t:"fy" },
-
- "~": { p:900, t:"fx" },
-
- "<": { p:700, t:"xfx" },
- "=": { p:700, t:"xfx" },
- "=..": { p:700, t:"xfx" },
- "=@=": { p:700, t:"xfx" },
- "=:=": { p:700, t:"xfx" },
- "=<": { p:700, t:"xfx" },
- "==": { p:700, t:"xfx" },
- "=\\=": { p:700, t:"xfx" },
- ">": { p:700, t:"xfx" },
- ">=": { p:700, t:"xfx" },
- "@<": { p:700, t:"xfx" },
- "@=<": { p:700, t:"xfx" },
- "@>": { p:700, t:"xfx" },
- "@>=": { p:700, t:"xfx" },
- "\\=": { p:700, t:"xfx" },
- "\\==": { p:700, t:"xfx" },
- "is": { p:700, t:"xfx" },
-
- ":": { p:600, t:"xfy" },
-
- "+": [ { p:500, t:"yfx" },
- { p:200, t:"fy" }
- ],
- "-": [ { p:500, t:"yfx" },
- { p:200, t:"fy" }
- ],
- "/\\": { p:500, t:"yfx" },
- "\\/": { p:500, t:"yfx" },
- "xor": { p:500, t:"yfx" },
-
- "?": { p:500, t:"fx" },
-
- "*": { p:400, t:"yfx" },
- "/": { p:400, t:"yfx" },
- "//": { p:400, t:"yfx" },
- "rdiv": { p:400, t:"yfx" },
- "<<": { p:400, t:"yfx" },
- ">>": { p:400, t:"yfx" },
- "mod": { p:400, t:"yfx" },
- "rem": { p:400, t:"yfx" },
-
- "**": { p:200, t:"xfx" },
- "^": { p:200, t:"xfy" },
-
- "\\": { p:200, t:"fy" }
- };
-
- var translType = {
- "comment": "comment",
- "var": "variable-2", /* JavaScript Types */
- "atom": "atom",
- "qatom": "atom",
- "bqstring": "string",
- "symbol": "atom",
- "functor": "keyword",
- "tag": "tag",
- "number": "number",
- "string": "string",
- "code": "number",
- "neg-number": "number",
- "pos-number": "number",
- "list_open": "bracket",
- "list_close": "bracket",
- "qq_open": "bracket",
- "qq_sep": "operator",
- "qq_close": "bracket",
- "dict_open": "bracket",
- "dict_close": "bracket",
- "brace_term_open": "bracket",
- "brace_term_close": "bracket",
- "neck": "keyword",
- "fullstop": "keyword"
- };
-
- var builtins = {
- "asserta": "prolog",
- "atomic_list_concat": "prolog",
- "char_type": "prolog",
- "compile_expressions": "prolog",
- "compile": "prolog",
- "create_prolog_flag": "prolog",
- "current_module": "prolog",
- "current_op": "prolog",
- "del_attrs": "prolog",
- "depth_bound_call": "prolog",
- "dule": "prolog",
- "exo_files": "prolog",
- "export_list": "prolog",
- "foreign_directory": "prolog",
- "garbage_collect_atoms": "prolog",
- "garbage_collect": "prolog",
- "get_attrs": "prolog",
- "hread_signal": "prolog",
- "ignore": "prolog",
- "incore": "prolog",
- "initialization": "prolog",
- "int_message": "prolog",
- "message_to_string": "prolog",
- "module_property": "prolog",
- "msort": "prolog",
- "mutex_unlock_all": "prolog",
- "no_style_check": "prolog",
- "nospy": "prolog",
- "notrace": "prolog",
- "ortray_clause": "prolog",
- "otherwise": "prolog",
- "predsort": "prolog",
- "prolog_initialization": "prolog",
- "qend_program": "prolog",
- "qsave_file": "prolog",
- "recordaifnot": "prolog",
- "set_base_module": "prolog",
- "sformat": "prolog",
- "source_file": "prolog",
- "split_path_file": "prolog",
- "stream_position": "prolog",
- "system_error": "prolog",
- "system_module": "prolog",
- "t_head": "prolog",
- "table_statistics": "prolog",
- "tabling_mode": "prolog",
- "tabling_statistics": "prolog",
- "thread_defaults": "prolog",
- "thread_local": "prolog",
- "thread_set_defaults": "prolog",
- "thread_statistics": "prolog",
- "unix": "prolog",
- "use_system_module": "prolog",
- "user_defined_directive": "prolog",
- "version": "prolog",
- "C": "prolog",
- "abolish_all_tables": "prolog",
- "abolish_frozen_choice_points": "prolog",
- "abolish_module": "prolog",
- "abolish_table": "prolog",
- "abolish": "prolog",
- "abort": "prolog",
- "absolute_file_name": "prolog",
- "absolute_file_system_path": "prolog",
- "access_file": "prolog",
- "access": "prolog",
- "acyclic_term": "prolog",
- "add_import_module": "prolog",
- "add_to_array_element": "prolog",
- "add_to_path": "prolog",
- "alarm": "prolog",
- "all": "prolog",
- "always_prompt_user": "prolog",
- "arena_size": "prolog",
- "arg": "prolog",
- "array_element": "prolog",
- "array": "prolog",
- "assert_static": "prolog",
- "asserta_static": "prolog",
- "assertz_static": "prolog",
- "assertz": "prolog",
- "assert": "prolog",
- "at_end_of_line": "prolog",
- "at_end_of_stream_0": "prolog",
- "at_end_of_stream": "prolog",
- "at_halt": "prolog",
- "atom_chars": "prolog",
- "atom_codes": "prolog",
- "atom_concat": "prolog",
- "atom_length": "prolog",
- "atom_number": "prolog",
- "atom_string": "prolog",
- "atom_to_term": "prolog",
- "atomic_concat": "prolog",
- "atomic_length": "prolog",
- "atomic_list_concat": "prolog",
- "atomics_to_string": "prolog",
- "atomic": "prolog",
- "atom": "prolog",
- "attvar": "prolog",
- "b_getval": "prolog",
- "b_setval": "prolog",
- "bagof": "prolog",
- "bb_delete": "prolog",
- "bb_get": "prolog",
- "bb_put": "prolog",
- "bb_update": "prolog",
- "between": "prolog",
- "bootstrap": "prolog",
- "break": "prolog",
- "call_cleanup": "prolog",
- "call_count_data": "prolog",
- "call_count_reset": "prolog",
- "call_count": "prolog",
- "call_residue_vars": "prolog",
- "call_residue": "prolog",
- "call_shared_object_function": "prolog",
- "call_with_args": "prolog",
- "callable": "prolog",
- "call": "prolog",
- "catch_ball": "prolog",
- "catch": "prolog",
- "cd": "prolog",
- "cfile_search_path": "prolog",
- "char_code": "prolog",
- "char_conversion": "prolog",
- "char_type": "prolog",
- "clause_property": "prolog",
- "clause": "prolog",
- "close_shared_object": "prolog",
- "close_static_array": "prolog",
- "close": "prolog",
- "code_type": "prolog",
- "commons_directory": "prolog",
- "commons_library": "prolog",
- "compare": "prolog",
- "compile_expressions": "prolog",
- "compile_predicates": "prolog",
- "compile": "prolog",
- "compound": "prolog",
- "consult_depth": "prolog",
- "consult": "prolog",
- "context_module": "prolog",
- "copy_term_nat": "prolog",
- "copy_term": "prolog",
- "create_mutable": "prolog",
- "create_prolog_flag": "prolog",
- "creep_allowed": "prolog",
- "current_atom": "prolog",
- "current_char_conversion": "prolog",
- "current_host": "prolog",
- "current_input": "prolog",
- "current_key": "prolog",
- "current_line_number": "prolog",
- "current_module": "prolog",
- "current_mutex": "prolog",
- "current_op": "prolog",
- "current_output": "prolog",
- "current_predicate": "prolog",
- "current_prolog_flag": "prolog",
- "current_reference_count": "prolog",
- "current_stream": "prolog",
- "current_thread": "prolog",
- "db_files": "prolog",
- "db_reference": "prolog",
- "debugging": "prolog",
- "debug": "prolog",
- "decrease_reference_count": "prolog",
- "del_attrs": "prolog",
- "del_attr": "prolog",
- "delete_import_module": "prolog",
- "depth_bound_call": "prolog",
- "dif": "prolog",
- "discontiguous": "prolog",
- "display": "prolog",
- "do_c_built_in": "prolog",
- "do_c_built_metacall": "prolog",
- "do_not_compile_expressions": "prolog",
- "dump_active_goals": "prolog",
- "dum": "prolog",
- "duplicate_term": "prolog",
- "dynamic_predicate": "prolog",
- "dynamic_update_array": "prolog",
- "dynamic": "prolog",
- "eamconsult": "prolog",
- "eamtrans": "prolog",
- "end_of_file": "prolog",
- "ensure_loaded": "prolog",
- "eraseall": "prolog",
- "erased": "prolog",
- "erase": "prolog",
- "exists_directory": "prolog",
- "exists_file": "prolog",
- "exists_source": "prolog",
- "exists": "prolog",
- "exo_files": "prolog",
- "expand_exprs": "prolog",
- "expand_expr": "prolog",
- "expand_file_name": "prolog",
- "expand_goal": "prolog",
- "expand_term": "prolog",
- "expects_dialect": "prolog",
- "export_list": "prolog",
- "export_resource": "prolog",
- "export": "prolog",
- "extend": "prolog",
- "fail": "prolog",
- "false": "prolog",
- "file_base_name": "prolog",
- "file_directory_name": "prolog",
- "file_exists": "prolog",
- "file_name_extension": "prolog",
- "file_search_path": "prolog",
- "file_size": "prolog",
- "fileerrors": "prolog",
- "findall": "prolog",
- "float": "prolog",
- "flush_output": "prolog",
- "forall": "prolog",
- "foreign_directory": "prolog",
- "format": "prolog",
- "freeze_choice_point": "prolog",
- "freeze": "prolog",
- "frozen": "prolog",
- "functor": "prolog",
- "garbage_collect_atoms": "prolog",
- "garbage_collect": "prolog",
- "gc": "prolog",
- "get0": "prolog",
- "get_attr": "prolog",
- "get_byte": "prolog",
- "get_char": "prolog",
- "get_code": "prolog",
- "get_depth_limit": "prolog",
- "get_mutable": "prolog",
- "get_string_code": "prolog",
- "get_value": "prolog",
- "getcwd": "prolog",
- "getenv": "prolog",
- "get": "prolog",
- "global_trie_statistics": "prolog",
- "ground": "prolog",
- "grow_heap": "prolog",
- "grow_stack": "prolog",
- "halt": "prolog",
- "heap_space_info": "prolog",
- "hide_atom": "prolog",
- "hide_predicate": "prolog",
- "hostname_address": "prolog",
- "hread_get_message": "prolog",
- "if": "prolog",
- "ignore": "prolog",
- "import_module": "prolog",
- "incore": "prolog",
- "increase_reference_count": "prolog",
- "init_random_state": "prolog",
- "initialization": "prolog",
- "instance_property": "prolog",
- "instance": "prolog",
- "integer": "prolog",
- "is_absolute_file_name": "prolog",
- "is_list": "prolog",
- "is_mutable": "prolog",
- "is_tabled": "prolog",
- "isinf": "prolog",
- "isnan": "prolog",
- "is": "prolog",
- "key_erased_statistics": "prolog",
- "key_statistics": "prolog",
- "keysort": "prolog",
- "leash": "prolog",
- "length": "prolog",
- "libraries_directories": "prolog",
- "line_count": "prolog",
- "listing": "prolog",
- "load_absolute_foreign_files": "prolog",
- "load_db": "prolog",
- "load_files": "prolog",
- "load_foreign_files": "prolog",
- "log_event": "prolog",
- "logsum": "prolog",
- "ls_imports": "prolog",
- "ls": "prolog",
- "make_directory": "prolog",
- "make_library_index": "prolog",
- "make": "prolog",
- "message_queue_create": "prolog",
- "message_queue_destroy": "prolog",
- "message_queue_property": "prolog",
- "message_to_string": "prolog",
- "mmapped_array": "prolog",
- "module_property": "prolog",
- "module_state": "prolog",
- "module": "prolog",
- "msort": "prolog",
- "multifile": "prolog",
- "must_be_of_type": "prolog",
- "mutex_create": "prolog",
- "mutex_property": "prolog",
- "mutex_unlock_all": "prolog",
- "name": "prolog",
- "nb_create": "prolog",
- "nb_current": "prolog",
- "nb_delete": "prolog",
- "nb_getval": "prolog",
- "nb_linkarg": "prolog",
- "nb_linkval": "prolog",
- "nb_set_bit": "prolog",
- "nb_set_shared_arg": "prolog",
- "nb_set_shared_val": "prolog",
- "nb_setarg": "prolog",
- "nb_setval": "prolog",
- "new_system_module": "prolog",
- "nl": "prolog",
- "no_source": "prolog",
- "no_style_check": "prolog",
- "nodebug": "prolog",
- "nofileeleerrors": "prolog",
- "nogc": "prolog",
- "nonvar": "prolog",
- "nospyall": "prolog",
- "nospy": "prolog",
- "notrace": "prolog",
- "not": "prolog",
- "nth_clause": "prolog",
- "nth_instance": "prolog",
- "number_atom": "prolog",
- "number_chars": "prolog",
- "number_codes": "prolog",
- "number_string": "prolog",
- "numbervars": "prolog",
- "number": "prolog",
- "on_exception": "prolog",
- "on_signal": "prolog",
- "once": "prolog",
- "opaque": "prolog",
- "open_pipe_stream": "prolog",
- "open_shared_object": "prolog",
- "open": "prolog",
- "opt_statistics": "prolog",
- "op": "prolog",
- "or_statistics": "prolog",
- "otherwise": "prolog",
- "parallel_findall": "prolog",
- "parallel_findfirst": "prolog",
- "parallel_once": "prolog",
- "parallel": "prolog",
- "path": "prolog",
- "peek_byte": "prolog",
- "peek_char": "prolog",
- "peek_code": "prolog",
- "peek": "prolog",
- "phrase": "prolog",
- "plus": "prolog",
- "portray_clause": "prolog",
- "predicate_erased_statistics": "prolog",
- "predicate_property": "prolog",
- "predicate_statistics": "prolog",
- "predmerge": "prolog",
- "predsort": "prolog",
- "primitive": "prolog",
- "print_message_lines": "prolog",
- "print_message": "prolog",
- "print": "prolog",
- "private": "prolog",
- "profalt": "prolog",
- "profend": "prolog",
- "profile_data": "prolog",
- "profile_reset": "prolog",
- "profinit": "prolog",
- "profoff": "prolog",
- "profon": "prolog",
- "prolog_current_frame": "prolog",
- "prolog_file_name": "prolog",
- "prolog_file_type": "prolog",
- "prolog_flag_property": "prolog",
- "prolog_flag": "prolog",
- "prolog_initialization": "prolog",
- "prolog_load_context": "prolog",
- "prolog_to_os_filename": "prolog",
- "prolog": "prolog",
- "prompt1": "prolog",
- "prompt": "prolog",
- "put_attrs": "prolog",
- "put_attr": "prolog",
- "put_byte": "prolog",
- "put_char1": "prolog",
- "put_char": "prolog",
- "put_code": "prolog",
- "putenv": "prolog",
- "put": "prolog",
- "pwd": "prolog",
- "qend_program": "prolog",
- "qload_file": "prolog",
- "qload_module": "prolog",
- "qpack_clean_up_to_disjunction": "prolog",
- "qsave_file": "prolog",
- "qsave_module": "prolog",
- "qsave_program": "prolog",
- "raise_exception": "prolog",
- "rational_term_to_tree": "prolog",
- "rational": "prolog",
- "read_clause": "prolog",
- "read_sig": "prolog",
- "read_term_from_atomic": "prolog",
- "read_term_from_atom": "prolog",
- "read_term_from_string": "prolog",
- "read_term": "prolog",
- "read": "prolog",
- "real_path": "prolog",
- "reconsult": "prolog",
- "recorda_at": "prolog",
- "recordaifnot": "prolog",
- "recorda": "prolog",
- "recorded": "prolog",
- "recordz_at": "prolog",
- "recordzifnot": "prolog",
- "recordz": "prolog",
- "release_random_state": "prolog",
- "remove_from_path": "prolog",
- "rename": "prolog",
- "repeat": "prolog",
- "reset_static_array": "prolog",
- "reset_total_choicepoints": "prolog",
- "resize_static_array": "prolog",
- "restore": "prolog",
- "retractall": "prolog",
- "retract": "prolog",
- "rmdir": "prolog",
- "same_file": "prolog",
- "save_program": "prolog",
- "seeing": "prolog",
- "seen": "prolog",
- "see": "prolog",
- "set_base_module": "prolog",
- "set_input": "prolog",
- "set_output": "prolog",
- "set_prolog_flag": "prolog",
- "set_random_state": "prolog",
- "set_stream_position": "prolog",
- "set_stream": "prolog",
- "set_value": "prolog",
- "setarg": "prolog",
- "setenv": "prolog",
- "setof": "prolog",
- "setup_call_catcher_cleanup": "prolog",
- "setup_call_cleanup": "prolog",
- "sformat": "prolog",
- "show_all_local_tables": "prolog",
- "show_all_tables": "prolog",
- "show_global_trieshow_tabled_predicates": "prolog",
- "show_global_trie": "prolog",
- "show_low_level_trace": "prolog",
- "show_tabled_predicates": "prolog",
- "show_table": "prolog",
- "showprofres": "prolog",
- "sh": "prolog",
- "simple": "prolog",
- "skip1": "prolog",
- "skip": "prolog",
- "socket_accept": "prolog",
- "socket_bind": "prolog",
- "socket_close": "prolog",
- "socket_connect": "prolog",
- "socket_listen": "prolog",
- "socket": "prolog",
- "sort2": "prolog",
- "sort": "prolog",
- "source_file_property": "prolog",
- "source_file": "prolog",
- "source_location": "prolog",
- "source_mode": "prolog",
- "source_module": "prolog",
- "source": "prolog",
- "split_path_file": "prolog",
- "spy": "prolog",
- "srandom": "prolog",
- "start_low_level_trace": "prolog",
- "stash_predicate": "prolog",
- "static_array_location": "prolog",
- "static_array_properties": "prolog",
- "static_array_to_term": "prolog",
- "static_array": "prolog",
- "statistics": "prolog",
- "stop_low_level_trace": "prolog",
- "stream_position_data": "prolog",
- "stream_position": "prolog",
- "stream_property": "prolog",
- "stream_select": "prolog",
- "string_chars": "prolog",
- "string_codes": "prolog",
- "string_code": "prolog",
- "string_concat": "prolog",
- "string_length": "prolog",
- "string_number": "prolog",
- "string_to_atomic": "prolog",
- "string_to_atom": "prolog",
- "string_to_list": "prolog",
- "string": "prolog",
- "strip_module": "prolog",
- "style_check": "prolog",
- "sub_atom": "prolog",
- "sub_string": "prolog",
- "subsumes_term": "prolog",
- "succ": "prolog",
- "sys_debug": "prolog",
- "system_error": "prolog",
- "system_library": "prolog",
- "system_module": "prolog",
- "system_predicate": "prolog",
- "system": "prolog",
- "t_body": "prolog",
- "t_head": "prolog",
- "t_hgoal": "prolog",
- "t_hlist": "prolog",
- "t_tidy": "prolog",
- "tab1": "prolog",
- "table_statistics": "prolog",
- "table": "prolog",
- "tabling_mode": "prolog",
- "tabling_statistics": "prolog",
- "tab": "prolog",
- "telling": "prolog",
- "tell": "prolog",
- "term_attvars": "prolog",
- "term_factorized": "prolog",
- "term_to_atom": "prolog",
- "term_to_string": "prolog",
- "term_variables": "prolog",
- "thread_at_exit": "prolog",
- "thread_cancel": "prolog",
- "thread_create": "prolog",
- "thread_defaults": "prolog",
- "thread_default": "prolog",
- "thread_detach": "prolog",
- "thread_exit": "prolog",
- "thread_get_message": "prolog",
- "thread_join": "prolog",
- "thread_local": "prolog",
- "thread_peek_message": "prolog",
- "thread_property": "prolog",
- "thread_self": "prolog",
- "thread_send_message": "prolog",
- "thread_set_defaults": "prolog",
- "thread_set_default": "prolog",
- "thread_signal": "prolog",
- "thread_sleep": "prolog",
- "thread_statistics": "prolog",
- "threads": "prolog",
- "throw": "prolog",
- "time_file64": "prolog",
- "time_file": "prolog",
- "time": "prolog",
- "told": "prolog",
- "tolower": "prolog",
- "total_choicepoints": "prolog",
- "total_erased": "prolog",
- "toupper": "prolog",
- "trace": "prolog",
- "true_file_name": "prolog",
- "true": "prolog",
- "tthread_peek_message": "prolog",
- "ttyget0": "prolog",
- "ttyget": "prolog",
- "ttynl": "prolog",
- "ttyput": "prolog",
- "ttyskip": "prolog",
- "udi": "prolog",
- "unhide_atom": "prolog",
- "unify_with_occurs_check": "prolog",
- "unix": "prolog",
- "unknown": "prolog",
- "unload_file": "prolog",
- "unload_module": "prolog",
- "unnumbervars": "prolog",
- "update_array": "prolog",
- "update_mutable": "prolog",
- "use_module": "prolog",
- "use_system_module": "prolog",
- "user_defined_directive": "prolog",
- "var": "prolog",
- "version": "prolog",
- "volatile": "prolog",
- "wake_choice_point": "prolog",
- "when": "prolog",
- "with_mutex": "prolog",
- "with_output_to": "prolog",
- "working_directory": "prolog",
- "write_canonical": "prolog",
- "write_depth": "prolog",
- "write_term": "prolog",
- "writeln": "prolog",
- "writeq": "prolog",
- "write": "prolog",
- "yap_flag": "prolog"
- };
-
- /*******************************
- * RETURN OBJECT *
- *******************************/
-
- return {
- startState: function() {
- return {
- tokenize: plTokenBase,
- inBody: false,
- goalStart: false,
- lastType: null,
- nesting: new Array(), /* ([{}]) nesting FIXME: copy this */
- curTerm: null, /* term index in metainfo */
- curToken: null /* token in term */
- };
- },
-
-
- token: function(stream, state) {
- var nest;
-
- if ( state.curTerm == null && modeConfig.metainfo ) {
- state.curTerm = 0;
- state.curToken = 0;
- }
-
- if ( stream.sol() )
- delete state.commaAtEOL;
-
- if ( state.tokenize == plTokenBase && stream.eatSpace() ) {
- if ( stream.eol() )
- setArgAlignment(state);
- return null;
- }
-
- var style = state.tokenize(stream, state);
-
- if ( stream.eol() )
- setArgAlignment(state);
-
- if ( type == "neck" ) {
- state.inBody = true;
- state.goalStart = true;
- } else if ( type == "fullstop" ) {
- state.inBody = false;
- state.goalStart = false;
- }
-
- state.lastType = type;
-
-
- if ( builtins[state.curToken] == "prolog")
- return "builtin";
- if ( ops[state.curToken])
- return "operator";
- return translType[type];
- },
-
- indent: function(state, textAfter) {
- if (state.tokenize == plTokenComment) return CodeMirror.Pass;
-
- var nest;
- if ( (nest=nesting(state)) ) {
- if ( nest.closeColumn && !state.commaAtEOL )
- return nest.closeColumn;
- return nest.alignment;
- }
- if ( !state.inBody )
- return 0;
-
- return 4;
- },
-
- // theme: "prolog",
-
- blockCommentStart: "/*", /* continuecomment.js support */
- blockCommentEnd: "*/",
- blockCommentContinue: " * ",
- lineComment: "%",
- };
-
- });
+"use strict";
+
+CodeMirror.defineMode("prolog", function(conf, parserConfig) {
+ function chain(stream, state, f) {
+ state.tokenize = f;
+ return f(stream, state);
+ }
+
+ var cm_;
+ var curLine;
+
+ /*******************************
+ * CONFIG DATA *
+ *******************************/
+
+ var quasiQuotations =
+ parserConfig.quasiQuotations || false; /* {|Syntax||Quotation|} */
+ var dialect = parserConfig.dialect || "yap"; /* {|Syntax||Quotation|} */
+ var composeGoalWithDots =
+ parserConfig.composeGoalWithDots || true; /* {|Syntax||Quotation|} */
+ var dicts = parserConfig.dicts || false; /* tag{k:v, ...} */
+ var groupedIntegers =
+ parserConfig.groupedIntegers || false; /* tag{k:v, ...} */
+ var unicodeEscape =
+ parserConfig.unicodeEscape || true; /* \uXXXX and \UXXXXXXXX */
+ var multiLineQuoted = parserConfig.multiLineQuoted || true; /* "...\n..." */
+ var quoteType = parserConfig.quoteType ||
+ {'"' : "string", "'" : "qatom", "`" : "bqstring"};
+
+ var isSingleEscChar = /[abref\\'"nrtsv]/;
+ var isOctalDigit = /[0-7]/;
+ var isHexDigit = /[0-9a-fA-F]/;
+
+ var isSymbolChar = /[-#$&*+./:<=>?@\\^~]/; /* Prolog glueing symbols chars */
+ var isSoloChar = /[[\]{}(),;|!]/; /* Prolog solo chars */
+ var isNeck = /^(:-|-->)$/;
+ var isControlOp = /^(,|;|->|\*->|\\+|\|)$/;
+
+ /*******************************
+ * Linter Support *
+ *******************************/
+
+ var errorFound = [];
+ var exportedMsgs = [];
+
+ function getLine(stream) {
+ return stream.lineOracle.line;
+ // return cm_.getDoc().getCursor().line;
+ }
+
+ // var ed =
+ // window.document.getElementsByClassName("CodeMirror")[0].CodeMirror.doc.getEditor();
+
+ function rmError(stream) {
+ if (cm_ == null)
+ return;
+ var doc = cm_.getDoc();
+ var l = getLine(stream);
+ // stream.lineOracle.line;
+ for (var i = 0; i < errorFound.length; i++) {
+ var elLine = doc.getLineNumber(errorFound[i].line);
+ if (elLine == null || l === elLine) {
+ errorFound.splice(i, 1);
+ i -= 1;
+ console.log(-elLine);
+ }
+ }
+ }
+
+ function mkError(stream, severity, msg) {
+ if (stream.pos == 0)
+ return;
+ var l = cm_.getDoc().getLineHandle(getLine(stream));
+ var found = errorFound.find(function(
+ element) { return element.line === l && element.to == stream.pos; });
+ if (!found) {
+ console.log( getLine(stream) );
+ errorFound.push({
+ "line" : l,
+ "from" : stream.start,
+ "to" : stream.pos,
+ severity : severity,
+ message : msg
+ });
+ }
+ }
+
+ function exportErrors(text) {
+ if (cm_ == null)
+ return;
+ var doc = cm_.getDoc();
+
+ exportedMsgs.length = 0;
+ for (var i = 0; i < errorFound.length; i += 1) {
+ var e = errorFound[i];
+ var l = doc.getLineNumber(e.line);
+ if (l == null) {
+ errorFound.splice(i, 1);
+ i -= 1;
+ continue;
+ }
+ exportedMsgs.push({
+ "from" : CodeMirror.Pos(l, e.from),
+ "to" : CodeMirror.Pos(l, e.to),
+ "severity" : e.severity,
+ "message" : e.message
+ });
+ }
+ return exportedMsgs;
+ }
+
+ CodeMirror.registerHelper("lint", "prolog", exportErrors);
+
+ /*******************************
+ * CHARACTER ESCAPES *
+ *******************************/
+
+ function readDigits(stream, re, count) {
+ if (count > 0) {
+ while (count-- > 0) {
+ if (!re.test(stream.next()))
+ return false;
+ }
+ } else {
+ while (re.test(stream.peek()))
+ stream.next();
+ }
+ return true;
+ }
+
+ function readEsc(stream) {
+ var next = stream.next();
+ if (isSingleEscChar.test(next))
+ return true;
+ switch (next) {
+ case "u":
+ if (unicodeEscape)
+ return readDigits(stream, isHexDigit, conf.indentUnit); /* SWI */
+ return false;
+ case "U":
+ if (unicodeEscape)
+ return readDigits(stream, isHexDigit, 8); /* SWI */
+ return false;
+ case null:
+ return true; /* end of line */
+ case "c":
+ stream.eatSpace();
+ return true;
+ case "x":
+ return readDigits(stream, isHexDigit, 2);
+ }
+ if (isOctalDigit.test(next)) {
+ if (!readDigits(stream, isOctalDigit, -1))
+ return false;
+ if (stream.peek() == "\\") /* SWI: optional closing \ */
+ stream.next();
+ return true;
+ }
+ return false;
+ }
+
+ function nextUntilUnescaped(stream, state, end) {
+ var next;
+ while ((next = stream.next()) != null) {
+ if (next == end && end != stream.peek()) {
+ state.nesting.pop();
+ return false;
+ }
+ if (next == "\\") {
+ if (!readEsc(stream))
+ return false;
+ }
+ }
+ return multiLineQuoted;
+ }
+
+ /*******************************
+ * CONTEXT NESTING *
+ *******************************/
+
+ function nesting(state) { return state.nesting.slice(-1)[0]; }
+
+ /* Called on every non-comment token */
+ function setArg1(state) {
+ var nest = nesting(state);
+ if (nest) {
+ if (nest.arg == 0) /* nested in a compound */
+ nest.arg = 1;
+ else if (nest.type == "control")
+ state.goalStart = false;
+ } else
+ state.goalStart = false;
+ }
+
+ function setArgAlignment(state) {
+ var nest = nesting(state);
+ if (nest && !nest.alignment && nest.arg != undefined) {
+ if (nest.arg == 0)
+ nest.alignment = nest.leftCol ? nest.leftCol + conf.indentUnit
+ : nest.column + conf.indentUnit;
+ else
+ nest.alignment = nest.column + 1;
+ }
+ }
+
+ function nextArg(state) {
+ var nest = nesting(state);
+ if (nest) {
+ if (nest.arg) /* nested in a compound */
+ nest.arg++;
+ else if (nest.type == "control") {
+ state.goalStart = true; /* FIXME: also needed for ; and -> */
+ }
+ } else {
+ state.goalStart = true;
+ }
+ }
+
+ function isControl(state) { /* our terms are goals */
+ var nest = nesting(state);
+ if (nest) {
+ if (nest.type == "control") {
+ return true;
+ }
+ return false;
+ } else
+ return state.inBody;
+ }
+
+ // Used as scratch variables to communicate multiple values without
+ // consing up tons of objects.
+ var type; //, content;
+ function ret(tp, style, cont) {
+ type = tp;
+ // content = cont;
+ return style;
+ }
+
+ function peekSpace(stream) { /* TBD: handle block comment as space */
+ if (stream.eol() || /[\s%]/.test(stream.peek()))
+ return true;
+ return false;
+ }
+
+ /*******************************
+ * SUB TOKENISERS *
+ *******************************/
+
+ function plTokenBase(stream, state) {
+ var ch = stream.next();
+
+ if (ch == "(") {
+ if (state.lastType == "functor") {
+ state.nesting.push({
+ functor : state.functorName,
+ column : stream.column(),
+ leftCol : state.functorColumn,
+ arg : 0
+ });
+ delete state.functorName;
+ delete state.functorColumn;
+ } else {
+ state.nesting.push({
+ type : "control",
+ closeColumn : stream.column(),
+ alignment : stream.column() + 3
+ });
+ }
+ return ret("solo", "tag", "(");
+ }
+
+ if (ch == "{" && state.lastType == "tag") {
+ state.nesting.push({
+ tag : state.tagName,
+ column : stream.column(),
+ leftCol : state.tagColumn,
+ arg : 0
+ });
+ delete state.tagName;
+ delete state.tagColumn;
+ return ret("dict_open", "bracket");
+ }
+
+ if (ch == "/" && stream.eat("*"))
+ return chain(stream, state, plTokenComment);
+
+ if (ch == "%") {
+ stream.skipToEnd();
+ return ret("comment", "comment");
+ }
+
+ setArg1(state);
+
+ if (isSoloChar.test(ch)) {
+ switch (ch) {
+ case ")": {
+ state.nesting.pop();
+ } break;
+ case "]":
+
+ state.nesting.pop();
+ return ret("list_close", "bracket");
+ case "}": {
+ var nest = nesting(state);
+ var type = (nest && nest.tag) ? "dict_close" : "brace_term_close";
+
+ state.nesting.pop();
+ return ret(type, null);
+ } break;
+ case ",": {
+ if (stream.eol())
+ state.commaAtEOL = true;
+ nextArg(state);
+ /*FALLTHROUGH*/
+ if (isControl(state)) {
+ if (!state.commaAtEOL)
+ stream.eatSpace();
+ if (!stream.peek("[")) {
+ if (state.inBody) {
+ state.goalStart = true;
+ } else {
+ return ret("solo", "error", ",");
+ }
+ }
+ }
+ } break;
+ case ";":
+ if (isControl(state)) {
+ if (!state.inBody)
+ return ret("solo", "error", ";");
+ state.goalStart = true;
+ }
+ break;
+ case "[":
+ state.nesting.push({
+ type : "list",
+ closeColumn : stream.column(),
+ alignment : stream.column() + 3
+ });
+ return ret("list_open", "bracket");
+ break;
+ case "{":
+ if (quasiQuotations && stream.eat("|")) {
+ state.nesting.push(
+ {type : "quasi-quotation", alignment : stream.column() + 1});
+ return ret("qq_open", "bracket");
+ } else {
+ state.nesting.push({
+ type : "curly",
+ closeColumn : stream.column(),
+ alignment : stream.column() + 2
+ });
+ return ret("brace_term_open", "bracket");
+ }
+ break;
+ case "|":
+ if (quasiQuotations) {
+ if (stream.eat("|")) {
+ state.tokenize = plTokenQuasiQuotation;
+ return ret("qq_sep", "bracket");
+ } else if (stream.eat("}")) {
+ state.nesting.pop();
+ return ret("qq_close", "bracket");
+ }
+ }
+ if (isControl(state)) {
+ state.goalStart = true;
+ }
+ break;
+ return ret("solo", "tag", ch);
+ }
+ }
+
+ if (ch == '"' || ch == "'" || ch == "`") {
+ state.nesting.push({type : "quoted", alignment : stream.column() + 1});
+ return chain(stream, state, plTokenString(ch));
+ }
+
+ if (ch == "0") {
+ if (stream.eat(/x/i)) {
+ stream.eatWhile(/[\da-f]/i);
+ return ret("number", "number");
+ }
+ if (stream.eat(/o/i)) {
+ stream.eatWhile(/[0-7]/i);
+ return ret("number", "number");
+ }
+ if (stream.eat(/'/)) { /* 0' */
+ var next = stream.next();
+ if (next == "\\") {
+ if (!readEsc(stream))
+ return ret("error", "error");
+ }
+ return ret("code", "number");
+ }
+ }
+
+ if (/\d/.test(ch) || /[+-]/.test(ch) && stream.eat(/\d/)) {
+ if (groupedIntegers)
+ stream.match(/^\d*((_|\s+)\d+)*(?:\.\d+)?(?:[eE][+\-]?\d+)?/);
+ else
+ stream.match(/^\d*(?:\.\d+)?(?:[eE][+\-]?\d+)?/);
+ return ret(ch == "-" ? "neg-number" : ch == "+" ? "-number" : "number",
+ "number");
+ }
+
+ if (isSymbolChar.test(ch)) {
+ stream.eatWhile(isSymbolChar);
+ var atom = stream.current();
+ if (atom == "." && (stream.eol() || peekSpace(stream))) {
+ if (nesting(state)) {
+ mkError(stream, "error", "Clause over before closing all brackets");
+ state.nesting = [];
+ }
+ // var start = cm_.getCursor("end");
+ //cm_.setBookmark(start, {"widget" : document.createTextNode("•")});
+ state.inBody = false;
+ state.goalStart = true;
+ stream.eat(ch);
+ return ret("fullstop", "def", atom);
+
+ } else {
+ if (atom === ":-" && state.headStart) {
+
+ return ret("directive", "attribute", atom);
+
+ } else if (isNeck.test(atom)) {
+ state.inBody = true;
+ state.goalStart = true;
+ return ret("neck", "property", atom);
+ } else if (isControl(state) && isControlOp.test(atom)) {
+ state.goalStart = true;
+ return ret("symbol", "meta", atom);
+ } else
+ return ret("symbol", "meta", atom);
+ }
+ }
+ stream.eatWhile(/[\w_]/);
+ if (composeGoalWithDots) {
+ while (stream.peek() == ".") {
+ stream.eat('.');
+ // a.b() and friends
+ if ((ch = stream.peek()) == ' ' || stream.eol()) {
+ stream.backUp(1);
+ break;
+
+ } else if (/[\w_]/.test(ch)) {
+ stream.eatWhile(/[\w_]/);
+ } else if (ch == "'") {
+
+ stream.eat();
+
+ stream.eatWhile(/[\w_]/);
+ if (ch == ".") {
+ return ret("atom", "error");
+ }
+ }
+ }
+ }
+ var word = stream.current();
+ var extra = "";
+ if (stream.peek() == "{" && dicts) {
+ state.tagName = word; /* tmp state extension */
+ state.tagColumn = stream.column();
+ return ret("tag", "tag", word);
+ } else if ((ch = word[0]) == "_") {
+ if (word.length == 1) {
+ return ret("var", "variable-2", word);
+ } else {
+ var sec = word.charAt(1);
+ if (sec == sec.toUpperCase())
+ return ret("var", "variable-2", word);
+ }
+ return ret("var", "variable-2", word);
+ } else if (ch == ch.toUpperCase()) {
+ return ret("var", "variable-1", word);
+ } else if (stream.peek() == "(") {
+ state.functorName = word; /* tmp state extension */
+ state.functorColumn = stream.column();
+ if (state.headStart) {
+ state.headStart = false;
+ if (state.headFunctor != word) {
+ state.headFunctor = word;
+ return ret("functor", "def", word);
+ }
+ }
+ if (builtins[word] && isControl(state))
+ return ret("functor", "keyword", word);
+ return ret("functor", "atom", word);
+ } else if ((extra = stream.eatSpace())) {
+ if (state.headStart && (stream.peek() == ":" || stream.peek() == "-")) {
+ state.headStart = false;
+ if (state.headFunctor != word) {
+ state.headFunctor = word;
+ return ret("functor", "def", word);
+ }
+ }
+ state.functorName = word; /* tmp state extension */
+ state.functorColumn = stream.column();
+ var w = stream.current();
+ if (builtins[word] && isControl(state))
+ return ret("functor", "keyword", w);
+ return ret("functor", "atom", w);
+ } else if ((extra = stream.eat(/\/(\/)?\d\d?/) != "")) {
+ state.functorName = word; /* tmp state extension */
+ state.functorColumn = stream.column();
+ var w = stream.current();
+ if (builtins[word] && isControl(state))
+ return ret("functor", "keyword", w);
+ return ret("functor", "atom", w);
+ } else if (builtins[word] && isControl(state))
+ return ret("atom", "keyword", word);
+ return ret("atom", "atom", word);
+ }
+
+ function plTokenString(quote) {
+ return function(stream, state) {
+ if (!nextUntilUnescaped(stream, state, quote)) {
+ state.tokenize = plTokenBase;
+ if (stream.peek() == "(") { /* 'quoted functor'() */
+ var word = stream.current();
+ state.functorName = word; /* tmp state extension */
+ if (state.headStart) {
+ state.headStart = false;
+ if (state.headFunctor != word) {
+ state.headFunctor = word;
+ return ret("functor", "def", word);
+ }
+ }
+ return ret("functor", "atom", word);
+ }
+ if (stream.peek() == "{" && dicts) { /* 'quoted tag'{} */
+ var word = stream.current();
+ state.tagName = word; /* tmp state extension */
+ return ret("tag", "tag", word);
+ }
+ }
+ return ret(quoteType[quote], "string");
+ };
+ }
+
+ function plTokenQuasiQuotation(stream, state) {
+ var maybeEnd = false, ch;
+ while (ch = stream.next()) {
+ if (ch == "}" && maybeEnd) {
+ state.tokenize = plTokenBase;
+ stream.backUp(2);
+ break;
+ }
+ maybeEnd = (ch == "|");
+ }
+ return ret("qq_content", "string");
+ }
+
+ function plTokenComment(stream, state) {
+ var maybeEnd = false, ch;
+ while (ch = stream.next()) {
+ if (ch == "/" && maybeEnd) {
+ state.tokenize = plTokenBase;
+ break;
+ }
+ maybeEnd = (ch == "*");
+ }
+ return ret("comment", "comment");
+ }
+
+ /*******************************
+ * ACTIVE KEYS *
+ *******************************/
+
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ - -
+Support if-then-else layout like this:
+
+goal :-
+(
+ Condition
+->
+IfTrue
+;
+ IfFalse
+).
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+- - */
+
+ CodeMirror.commands.prologStartIfThenElse = function(cm) {
+ var start = cm.getCursor("start");
+ var token = cm.getTokenAt(start, true);
+
+ if (token.state.goalStart == true) {
+ cm.replaceSelection("(\n", "end");
+ return;
+ }
+
+ return CodeMirror.Pass;
+ };
+
+ CodeMirror.commands.prologStartThen =
+ function(cm) {
+ var start = cm.getCursor("start");
+ var token = cm.getTokenAt(start, true);
+
+ /* FIXME: These functions are copied from prolog.js. How
+ can we reuse these?
+ */
+ function nesting(state) {
+ var len = state.nesting.length;
+ if (len > 0)
+ return state.nesting[len - 1];
+ return null;
+ }
+
+ function isControl(state) { /* our terms are goals */
+ var nest = nesting(state);
+ if (nest) {
+ if (nest.type == "control") {
+ return true;
+ }
+ return false;
+ } else
+ return state.inBody;
+ }
+
+ if (start.ch == token.end && token.type == "operator" &&
+ token.string == "-" && isControl(token.state)) {
+ cm.replaceSelection("\n->\n", "end");
+ return;
+ }
+
+ return CodeMirror.Pass;
+ }
+
+ CodeMirror.commands.prologStartElse =
+ function(cm) {
+ var start = cm.getCursor("start");
+ var token = cm.getTokenAt(start, true);
+
+ if (token.start == 0 && start.ch == token.end && !/\S/.test(token.string)) {
+ cm.replaceSelection("\n;\n", "end");
+ return;
+ }
+
+ return CodeMirror.Pass;
+ }
+
+ CodeMirror.commands.prologEndClause =
+ function(cm) {
+ if (!cm.state.nesting() && !isControl(cm.state)) {
+ var start = cm.getCursor("end");
+ cm.setBookmark(start, {widget : document.createTextNode("¶")});
+ return;
+ }
+ return CodeMirror.Pass;
+ }
+
+ CodeMirror.defineOption(
+ "prologKeys", true, function(cm, editor, prev) {
+ cm_ = cm;
+ if (prev && prev != CodeMirror.Init)
+ cm.removeKeyMap("prolog");
+ if (true) {
+ var map = {
+ name : "prolog",
+ "Enter '('" : "prologStartIfThenElse",
+ "Enter '-' '>'" : "prologStartThen",
+ "Enter ';'" : "prologStartElse",
+ "Ctrl-L" : "refreshHighlight",
+ "Tab" : "indent"
+ };
+ cm.addKeyMap(map);
+ }
+ });
+
+ // Default (SWI-)Prolog operator table. To be used later to enhance
+ // the offline experience.
+
+ var ops = {
+ "-->" : {p : 1200, t : "xfx"},
+ ":-" : [ {p : 1200, t : "xfx"}, {p : 1200, t : "fx"} ],
+ "?-" : {p : 1200, t : "fx"},
+
+ "dynamic" : {p : 1150, t : "fx"},
+ "discontiguous" : {p : 1150, t : "fx"},
+ "initialization" : {p : 1150, t : "fx"},
+ "meta_predicate" : {p : 1150, t : "fx"},
+ "module_transparent" : {p : 1150, t : "fx"},
+ "multifile" : {p : 1150, t : "fx"},
+ "thread_local" : {p : 1150, t : "fx"},
+ "volatile" : {p : 1150, t : "fx"},
+
+ ";" : {p : 1100, t : "xfy"},
+ "|" : {p : 1100, t : "xfy"},
+
+ "->" : {p : 1050, t : "xfy"},
+ "*->" : {p : 1050, t : "xfy"},
+
+ "," : {p : 1000, t : "xfy"},
+
+ "\\+" : {p : 900, t : "fy"},
+
+ "~" : {p : 900, t : "fx"},
+
+ "<" : {p : 700, t : "xfx"},
+ "=" : {p : 700, t : "xfx"},
+ "=.." : {p : 700, t : "xfx"},
+ "=@=" : {p : 700, t : "xfx"},
+ "=:=" : {p : 700, t : "xfx"},
+ "=<" : {p : 700, t : "xfx"},
+ "==" : {p : 700, t : "xfx"},
+ "=\\=" : {p : 700, t : "xfx"},
+ ">" : {p : 700, t : "xfx"},
+ ">=" : {p : 700, t : "xfx"},
+ "@<" : {p : 700, t : "xfx"},
+ "@=<" : {p : 700, t : "xfx"},
+ "@>" : {p : 700, t : "xfx"},
+ "@>=" : {p : 700, t : "xfx"},
+ "\\=" : {p : 700, t : "xfx"},
+ "\\==" : {p : 700, t : "xfx"},
+ "is" : {p : 700, t : "xfx"},
+
+ ":" : {p : 600, t : "xfy"},
+
+ "+" : [ {p : 500, t : "yfx"}, {p : 200, t : "fy"} ],
+ "-" : [ {p : 500, t : "yfx"}, {p : 200, t : "fy"} ],
+ "/\\" : {p : 500, t : "yfx"},
+ "\\/" : {p : 500, t : "yfx"},
+ "xor" : {p : 500, t : "yfx"},
+
+ "?" : {p : 500, t : "fx"},
+
+ "*" : {p : 400, t : "yfx"},
+ "/" : {p : 400, t : "yfx"},
+ "//" : {p : 400, t : "yfx"},
+ "rdiv" : {p : 400, t : "yfx"},
+ "<<" : {p : 400, t : "yfx"},
+ ">>" : {p : 400, t : "yfx"},
+ "mod" : {p : 400, t : "yfx"},
+ "rem" : {p : 400, t : "yfx"},
+
+ "**" : {p : 200, t : "xfx"},
+ "^" : {p : 200, t : "xfy"},
+
+ "\\" : {p : 200, t : "fy"}
+ };
+
+ var builtins = {
+ "C" : "prolog",
+ "abolish" : "prolog",
+ "abolish_all_tables" : "prolog",
+ "abolish_frozen_choice_points" : "prolog",
+ "abolish_module" : "prolog",
+ "abolish_table" : "prolog",
+ "abort" : "prolog",
+ "absolute_file_name" : "prolog",
+ "absolute_file_system_path" : "prolog",
+ "access" : "prolog",
+ "access_file" : "prolog",
+ "acyclic_term" : "prolog",
+ "add_import_module" : "prolog",
+ "add_to_array_element" : "prolog",
+ "add_to_path" : "prolog",
+ "alarm" : "prolog",
+ "all" : "prolog",
+ "always_prompt_user" : "prolog",
+ "arena_size" : "prolog",
+ "arg" : "prolog",
+ "array" : "prolog",
+ "array_element" : "prolog",
+ "assert" : "prolog",
+ "assert_static" : "prolog",
+ "asserta" : "prolog",
+ "asserta_static" : "prolog",
+ "assertz" : "prolog",
+ "assertz_static" : "prolog",
+ "at_end_of_line" : "prolog",
+ "at_end_of_stream" : "prolog",
+ "at_end_of_stream_0" : "prolog",
+ "at_halt" : "prolog",
+ "atom" : "prolog",
+ "atom_chars" : "prolog",
+ "atom_codes" : "prolog",
+ "atom_concat" : "prolog",
+ "atom_length" : "prolog",
+ "atom_number" : "prolog",
+ "atom_string" : "prolog",
+ "atom_to_term" : "prolog",
+ "atomic_concat" : "prolog",
+ "atomic_length" : "prolog",
+ "atomic_list_concat" : "prolog",
+ "atomics_to_string" : "prolog",
+ "attvar" : "prolog",
+ "b_getval" : "prolog",
+ "b_setval" : "prolog",
+ "bagof" : "prolog",
+ "bb_delete" : "prolog",
+ "bb_get" : "prolog",
+ "bb_put" : "prolog",
+ "bb_update" : "prolog",
+ "between" : "prolog",
+ "bootstrap" : "prolog",
+ "break" : "prolog",
+ "call" : "prolog",
+ "call_cleanup" : "prolog",
+ "call_count" : "prolog",
+ "call_count_data" : "prolog",
+ "call_count_reset" : "prolog",
+ "call_residue" : "prolog",
+ "call_residue_vars" : "prolog",
+ "call_shared_object_function" : "prolog",
+ "call_with_args" : "prolog",
+ "callable" : "prolog",
+ "catch" : "prolog",
+ "catch_ball" : "prolog",
+ "cd" : "prolog",
+ "cfile_search_path" : "prolog",
+ "char_code" : "prolog",
+ "char_conversion" : "prolog",
+ "char_type" : "prolog",
+ "clause" : "prolog",
+ "clause_property" : "prolog",
+ "close" : "prolog",
+ "close_shared_object" : "prolog",
+ "close_static_array" : "prolog",
+ "code_type" : "prolog",
+ "commons_directory" : "prolog",
+ "commons_library" : "prolog",
+ "compare" : "prolog",
+ "compile" : "prolog",
+ "compile_expressions" : "prolog",
+ "compile_predicates" : "prolog",
+ "compound" : "prolog",
+ "consult" : "prolog",
+ "consult_depth" : "prolog",
+ "context_module" : "prolog",
+ "copy_term" : "prolog",
+ "copy_term_nat" : "prolog",
+ "create_mutable" : "prolog",
+ "create_prolog_flag" : "prolog",
+ "creep_allowed" : "prolog",
+ "current_atom" : "prolog",
+ "current_char_conversion" : "prolog",
+ "current_host" : "prolog",
+ "current_input" : "prolog",
+ "current_key" : "prolog",
+ "current_line_number" : "prolog",
+ "current_module" : "prolog",
+ "current_mutex" : "prolog",
+ "current_op" : "prolog",
+ "current_predicate" : "prolog",
+ "current_prolog_flag" : "prolog",
+ "current_reference_count" : "prolog",
+ "current_stream" : "prolog",
+ "current_thread" : "prolog",
+ "db_files" : "prolog",
+ "db_reference" : "prolog",
+ "debug" : "prolog",
+ "debugging" : "prolog",
+ "decrease_reference_count" : "prolog",
+ "del_attr" : "prolog",
+ "del_attrs" : "prolog",
+ "delete_import_module" : "prolog",
+ "depth_bound_call" : "prolog",
+ "dif" : "prolog",
+ "discontiguous" : "prolog",
+ "display" : "prolog",
+ "do_c_built_in" : "prolog",
+ "do_c_built_metacall" : "prolog",
+ "do_not_compile_expressions" : "prolog",
+ "dule" : "prolog",
+ "dum" : "prolog",
+ "dump_active_goals" : "prolog",
+ "duplicate_term" : "prolog",
+ "dynamic" : "prolog",
+ "dynamic_predicate" : "prolog",
+ "dynamic_update_array" : "prolog",
+ "eamconsult" : "prolog",
+ "eamtrans" : "prolog",
+ "end_of_file" : "prolog",
+ "ensure_loaded" : "prolog",
+ "erase" : "prolog",
+ "eraseall" : "prolog",
+ "erased" : "prolog",
+ "exists" : "prolog",
+ "exists_directory" : "prolog",
+ "exists_file" : "prolog",
+ "exists_source" : "prolog",
+ "exo_files" : "prolog",
+ "expand_expr" : "prolog",
+ "expand_exprs" : "prolog",
+ "expand_file_name" : "prolog",
+ "expand_goal" : "prolog",
+ "expand_term" : "prolog",
+ "expects_dialect" : "prolog",
+ "export" : "prolog",
+ "export_list" : "prolog",
+ "export_resource" : "prolog",
+ "extend" : "prolog",
+ "fail" : "prolog",
+ "false" : "prolog",
+ "file_base_name" : "prolog",
+ "file_directory_name" : "prolog",
+ "file_exists" : "prolog",
+ "file_name_extension" : "prolog",
+ "file_search_path" : "prolog",
+ "file_size" : "prolog",
+ "fileerrors" : "prolog",
+ "findall" : "prolog",
+ "float" : "prolog",
+ "flush_output" : "prolog",
+ "forall" : "prolog",
+ "foreign_directory" : "prolog",
+ "format" : "prolog",
+ "freeze" : "prolog",
+ "freeze_choice_point" : "prolog",
+ "frozen" : "prolog",
+ "functor" : "prolog",
+ "garbage_collect" : "prolog",
+ "garbage_collect_atoms" : "prolog",
+ "gc" : "prolog",
+ "get" : "prolog",
+ "get0" : "prolog",
+ "get_attr" : "prolog",
+ "get_attrs" : "prolog",
+ "get_byte" : "prolog",
+ "get_char" : "prolog",
+ "get_code" : "prolog",
+ "get_depth_limit" : "prolog",
+ "get_mutable" : "prolog",
+ "get_string_code" : "prolog",
+ "get_value" : "prolog",
+ "getcwd" : "prolog",
+ "getenv" : "prolog",
+ "global_trie_statistics" : "prolog",
+ "ground" : "prolog",
+ "grow_heap" : "prolog",
+ "grow_stack" : "prolog",
+ "halt" : "prolog",
+ "heap_space_info" : "prolog",
+ "hide_atom" : "prolog",
+ "hide_predicate" : "prolog",
+ "hostname_address" : "prolog",
+ "hread_get_message" : "prolog",
+ "hread_signal" : "prolog",
+ "if" : "prolog",
+ "ignore" : "prolog",
+ "import_module" : "prolog",
+ "incore" : "prolog",
+ "increase_reference_count" : "prolog",
+ "init_random_state" : "prolog",
+ "initialization" : "prolog",
+ "instance" : "prolog",
+ "instance_property" : "prolog",
+ "int_message" : "prolog",
+ "integer" : "prolog",
+ "is" : "prolog",
+ "is_absolute_file_name" : "prolog",
+ "is_list" : "prolog",
+ "is_mutable" : "prolog",
+ "is_tabled" : "prolog",
+ "isinf" : "prolog",
+ "isnan" : "prolog",
+ "key_erased_statistics" : "prolog",
+ "key_statistics" : "prolog",
+ "keysort" : "prolog",
+ "leash" : "prolog",
+ "length" : "prolog",
+ "libraries_directories" : "prolog",
+ "line_count" : "prolog",
+ "listing" : "prolog",
+ "load_absolute_foreign_files" : "prolog",
+ "load_db" : "prolog",
+ "load_files" : "prolog",
+ "load_foreign_files" : "prolog",
+ "log_event" : "prolog",
+ "logsum" : "prolog",
+ "ls" : "prolog",
+ "ls_imports" : "prolog",
+ "make" : "prolog",
+ "make_directory" : "prolog",
+ "make_library_index" : "prolog",
+ "message_queue_create" : "prolog",
+ "message_queue_destroy" : "prolog",
+ "message_queue_property" : "prolog",
+ "message_to_string" : "prolog",
+ "mmapped_array" : "prolog",
+ "module" : "prolog",
+ "module_property" : "prolog",
+ "module_state" : "prolog",
+ "msort" : "prolog",
+ "multifile" : "prolog",
+ "must_be_of_type" : "prolog",
+ "mutex_create" : "prolog",
+ "mutex_property" : "prolog",
+ "mutex_unlock_all" : "prolog",
+ "name" : "prolog",
+ "nb_create" : "prolog",
+ "nb_current" : "prolog",
+ "nb_delete" : "prolog",
+ "nb_getval" : "prolog",
+ "nb_linkarg" : "prolog",
+ "nb_linkval" : "prolog",
+ "nb_set_bit" : "prolog",
+ "nb_set_shared_arg" : "prolog",
+ "nb_set_shared_val" : "prolog",
+ "nb_setarg" : "prolog",
+ "nb_setval" : "prolog",
+ "new_system_module" : "prolog",
+ "nl" : "prolog",
+ "no_source" : "prolog",
+ "no_style_check" : "prolog",
+ "nodebug" : "prolog",
+ "nofileeleerrors" : "prolog",
+ "nogc" : "prolog",
+ "nonvar" : "prolog",
+ "nospy" : "prolog",
+ "nospyall" : "prolog",
+ "not" : "prolog",
+ "notrace" : "prolog",
+ "nth_clause" : "prolog",
+ "nth_instance" : "prolog",
+ "number" : "prolog",
+ "number_atom" : "prolog",
+ "number_chars" : "prolog",
+ "number_codes" : "prolog",
+ "on_signal" : "prolog",
+ "once" : "prolog",
+ "op" : "prolog",
+ "opaque" : "prolog",
+ "open" : "prolog",
+ "open_pipe_stream" : "prolog",
+ "open_shared_object" : "prolog",
+ "opt_statistics" : "prolog",
+ "or_statistics" : "prolog",
+ "ortray_clause" : "prolog",
+ "otherwise" : "prolog",
+ "parallel" : "prolog",
+ "parallel_findall" : "prolog",
+ "parallel_findfirst" : "prolog",
+ "parallel_once" : "prolog",
+ "path" : "prolog",
+ "peek" : "prolog",
+ "peek_byte" : "prolog",
+ "peek_char" : "prolog",
+ "peek_code" : "prolog",
+ "phrase" : "prolog",
+ "plus" : "prolog",
+ "portray_clause" : "prolog",
+ "predicate_erased_statistics" : "prolog",
+ "predicate_property" : "prolog",
+ "predicate_statistics" : "prolog",
+ "predmerge" : "prolog",
+ "predsort" : "prolog",
+ "primitive" : "prolog",
+ "print" : "prolog",
+ "print_message" : "prolog",
+ "print_message_lines" : "prolog",
+ "private" : "prolog",
+ "profalt" : "prolog",
+ "profend" : "prolog",
+ "profile_data" : "prolog",
+ "profile_reset" : "prolog",
+ "profinit" : "prolog",
+ "profoff" : "prolog",
+ "profon" : "prolog",
+ "prolog" : "prolog",
+ "prolog_current_frame" : "prolog",
+ "prolog_file_name" : "prolog",
+ "prolog_file_type" : "prolog",
+ "prolog_flag" : "prolog",
+ "prolog_flag_property" : "prolog",
+ "prolog_initialization" : "prolog",
+ "prolog_load_context" : "prolog",
+ "prolog_to_os_filename" : "prolog",
+ "prompt" : "prolog",
+ "prompt1" : "prolog",
+ "put" : "prolog",
+ "put_attr" : "prolog",
+ "put_attrs" : "prolog",
+ "put_byte" : "prolog",
+ "put_char" : "prolog",
+ "put_char1" : "prolog",
+ "put_code" : "prolog",
+ "putenv" : "prolog",
+ "pwd" : "prolog",
+ "qend_program" : "prolog",
+ "qload_file" : "prolog",
+ "qload_module" : "prolog",
+ "qpack_clean_up_to_disjunction" : "prolog",
+ "qsave_file" : "prolog",
+ "qsave_module" : "prolog",
+ "qsave_program" : "prolog",
+ "raise_exception" : "prolog",
+ "rational" : "prolog",
+ "rational_term_to_tree" : "prolog",
+ "read" : "prolog",
+ "read_clause" : "prolog",
+ "read_sig" : "prolog",
+ "read_term" : "prolog",
+ "read_term_from_atom" : "prolog",
+ "read_term_from_atomic" : "prolog",
+ "read_term_from_string" : "prolog",
+ "real_path" : "prolog",
+ "reconsult" : "prolog",
+ "recorda" : "prolog",
+ "recorda_at" : "prolog",
+ "recordaifnot" : "prolog",
+ "recorded" : "prolog",
+ "recordz" : "prolog",
+ "recordz_at" : "prolog",
+ "recordzifnot" : "prolog",
+ "release_random_state" : "prolog",
+ "remove_from_path" : "prolog",
+ "rename" : "prolog",
+ "repeat" : "prolog",
+ "reset_static_array" : "prolog",
+ "reset_total_choicepoints" : "prolog",
+ "resize_static_array" : "prolog",
+ "restore" : "prolog",
+ "retract" : "prolog",
+ "retractall" : "prolog",
+ "rmdir" : "prolog",
+ "same_file" : "prolog",
+ "save_program" : "prolog",
+ "see" : "prolog",
+ "seeing" : "prolog",
+ "seen" : "prolog",
+ "set_base_module" : "prolog",
+ "set_input" : "prolog",
+ "set_output" : "prolog",
+ "set_prolog_flag" : "prolog",
+ "set_random_state" : "prolog",
+ "set_stream" : "prolog",
+ "set_stream_position" : "prolog",
+ "set_value" : "prolog",
+ "setarg" : "prolog",
+ "setenv" : "prolog",
+ "setof" : "prolog",
+ "setup_call_catcher_cleanup" : "prolog",
+ "setup_call_cleanup" : "prolog",
+ "sformat" : "prolog",
+ "sh" : "prolog",
+ "show_all_local_tables" : "prolog",
+ "show_all_tables" : "prolog",
+ "show_global_trie" : "prolog",
+ "show_global_trieshow_tabled_predicates" : "prolog",
+ "show_low_level_trace" : "prolog",
+ "show_table" : "prolog",
+ "show_tabled_predicates" : "prolog",
+ "showprofres" : "prolog",
+ "simple" : "prolog",
+ "skip" : "prolog",
+ "skip1" : "prolog",
+ "socket" : "prolog",
+ "socket_accept" : "prolog",
+ "socket_bind" : "prolog",
+ "socket_close" : "prolog",
+ "socket_connect" : "prolog",
+ "socket_listen" : "prolog",
+ "sort" : "prolog",
+ "sort2" : "prolog",
+ "source" : "prolog",
+ "source_file" : "prolog",
+ "source_file_property" : "prolog",
+ "source_location" : "prolog",
+ "source_mode" : "prolog",
+ "source_module" : "prolog",
+ "split_path_file" : "prolog",
+ "spy" : "prolog",
+ "srandom" : "prolog",
+ "start_low_level_trace" : "prolog",
+ "stash_predicate" : "prolog",
+ "static_array" : "prolog",
+ "static_array_location" : "prolog",
+ "static_array_properties" : "prolog",
+ "static_array_to_term" : "prolog",
+ "statistics" : "prolog",
+ "stop_low_level_trace" : "prolog",
+ "stream_position" : "prolog",
+ "stream_position_data" : "prolog",
+ "stream_property" : "prolog",
+ "stream_select" : "prolog",
+ "string" : "prolog",
+ "string_chars" : "prolog",
+ "string_code" : "prolog",
+ "string_codes" : "prolog",
+ "string_concat" : "prolog",
+ "string_length" : "prolog",
+ "string_number" : "prolog",
+ "string_to_atom" : "prolog",
+ "string_to_atomic" : "prolog",
+ "string_to_list" : "prolog",
+ "strip_module" : "prolog",
+ "style_check" : "prolog",
+ "sub_atom" : "prolog",
+ "sub_string" : "prolog",
+ "subsumes_term" : "prolog",
+ "succ" : "prolog",
+ "sys_debug" : "prolog",
+ "system" : "prolog",
+ "system_error" : "prolog",
+ "system_library" : "prolog",
+ "system_module" : "prolog",
+ "system_predicate" : "prolog",
+ "t_body" : "prolog",
+ "t_head" : "prolog",
+ "t_hgoal" : "prolog",
+ "t_hlist" : "prolog",
+ "t_tidy" : "prolog",
+ "tab" : "prolog",
+ "tab1" : "prolog",
+ "table" : "prolog",
+ "table_statistics" : "prolog",
+ "tabling_mode" : "prolog",
+ "tabling_statistics" : "prolog",
+ "tell" : "prolog",
+ "telling" : "prolog",
+ "term_attvars" : "prolog",
+ "term_factorized" : "prolog",
+ "term_to_atom" : "prolog",
+ "term_to_string" : "prolog",
+ "term_variables" : "prolog",
+ "thread_at_exit" : "prolog",
+ "thread_cancel" : "prolog",
+ "thread_create" : "prolog",
+ "thread_default" : "prolog",
+ "thread_defaults" : "prolog",
+ "thread_detach" : "prolog",
+ "thread_exit" : "prolog",
+ "thread_get_message" : "prolog",
+ "thread_join" : "prolog",
+ "thread_local" : "prolog",
+ "thread_peek_message" : "prolog",
+ "thread_property" : "prolog",
+ "thread_self" : "prolog",
+ "thread_send_message" : "prolog",
+ "thread_set_default" : "prolog",
+ "thread_set_defaults" : "prolog",
+ "thread_signal" : "prolog",
+ "thread_sleep" : "prolog",
+ "thread_statistics" : "prolog",
+ "threads" : "prolog",
+ "throw" : "prolog",
+ "time" : "prolog",
+ "time_file" : "prolog",
+ "time_file64" : "prolog",
+ "told" : "prolog",
+ "tolower" : "prolog",
+ "total_choicepoints" : "prolog",
+ "total_erased" : "prolog",
+ "toupper" : "prolog",
+ "trace" : "prolog",
+ "true" : "prolog",
+ "true_file_name" : "prolog",
+ "tthread_peek_message" : "prolog",
+ "ttyget" : "prolog",
+ "ttyget0" : "prolog",
+ "ttynl" : "prolog",
+ "ttyput" : "prolog",
+ "ttyskip" : "prolog",
+ "udi" : "prolog",
+ "unhide_atom" : "prolog",
+ "unify_with_occurs_check" : "prolog",
+ "unix" : "prolog",
+ "unknown" : "prolog",
+ "unload_file" : "prolog",
+ "unload_module" : "prolog",
+ "unnumbervars" : "prolog",
+ "update_array" : "prolog",
+ "update_mutable" : "prolog",
+ "use_module" : "prolog",
+ "use_system_module" : "prolog",
+ "user_defined_directive" : "prolog",
+ "var" : "prolog",
+ "version" : "prolog",
+ "volatile" : "prolog",
+ "wake_choice_point" : "prolog",
+ "when" : "prolog",
+ "with_mutex" : "prolog",
+ "with_output_to" : "prolog",
+ "working_directory" : "prolog",
+ "write" : "prolog",
+ "write_canonical" : "prolog",
+ "write_depth" : "prolog",
+ "write_term" : "prolog",
+ "writeln" : "prolog",
+ "writeq" : "prolog",
+ "yap_flag" : "prolog"
+ };
+
+ /*******************************
+ * RETURN OBJECT *
+ *******************************/
+
+ var external = {
+ startState : function() {
+ return {
+ tokenize : plTokenBase,
+ inBody : false,
+ goalStart : false,
+ headStart : true,
+ headFunctor : "",
+ lastType : null,
+ nesting : new Array(), /* ([{}]) nesting FIXME: copy this */
+ curTerm : null, /* term index in metainfo */
+ curToken : null /* token in term */
+ };
+ },
+ token : function(stream, state) {
+ // var nest;
+
+ if (state.curTerm == null) {
+ if (parserConfig.metainfo) {
+ state.curTerm = 0;
+ state.curToken = 0;
+ }
+ }
+
+ if (stream.eol()) {
+ curLine++;
+ delete state.commaAtEOL;
+ }
+
+ if (state.tokenize == plTokenBase && stream.eatSpace()) {
+ if (stream.eol())
+ setArgAlignment(state);
+ return null;
+ }
+ if (state.curLine == null || state.pos == 0)
+ rmError(stream);
+
+ var style = state.tokenize(stream, state);
+
+ if (stream.eol()) {
+ if (stream.pos > 0)
+ setArgAlignment(state);
+ }
+
+ state.lastType = type;
+
+ if (builtins[state.curToken] == "prolog")
+ return "builtin";
+ if (ops[state.curToken])
+ return "keyword";
+
+ // if (typeof(parserConfig.enrich) == "function")
+ // style = parserConfig.enrich(stream, state, type, content,
+ // style);
+
+ return style;
+ },
+
+ indent : function(state, textAfter) {
+ if (state.tokenize == plTokenComment)
+ return CodeMirror.Pass;
+
+ var nest;
+ if (!state.inBody)
+ return 0;
+ var ctl = isControl(state);
+ if ((nest = nesting(state))) {
+ if (!ctl && nest.closeColumn && !state.commaAtEOL)
+ return nest.closeColumn;
+ if ((textAfter === ']' || textAfter === ')' || textAfter === ').' ||
+ textAfter === '->' || textAfter === ';' || textAfter === '*->') &&
+ ctl)
+ return nest.alignment - 3;
+ return nest.alignment;
+ }
+
+ return conf.indentUnit;
+ },
+
+ electricInput : /^\s*([\}\]\)\;]|\-\>}\*\-\>|\)\.)$/,
+ blockCommentStart : "/*", /* continuecomment.js support */
+ blockCommentEnd : "*/",
+ blockCommentContinue : " * ",
+ comment : "%",
+ fold : "indent"
+ };
+ return external;
+});
CodeMirror.defineMIME("text/x-prolog", "prolog");
});
diff --git a/packages/ProbLog/problog_lbfgs.yap b/packages/ProbLog/problog_lbfgs.yap
index f9abc9129..8dbdc5bb8 100644
--- a/packages/ProbLog/problog_lbfgs.yap
+++ b/packages/ProbLog/problog_lbfgs.yap
@@ -832,10 +832,7 @@ gradient_descent :-
forall(tunable_fact(FactID,GroundTruth),
(XZ is 0.0, X[FactID] <== XZ,sigmoid(XZ,Slope,Pr),set_fact_probability(FactID,Pr))),
problog_flag(sigmoid_slope,Slope),
- lbfgs_run(Solver,BestF),
- format('~2nOptimization done~nWe found a minimum ~4f.~n',[BestF]),
- forall(tunable_fact(FactID,GroundTruth), set_tunable(FactID,Slope,X)),
- set_problog_flag(mse_trainset, BestF),
+ lbfgs_run(Solver,_BestF),
lbfgs_finalize(Solver).
set_tunable(I,Slope,P) :-
@@ -981,6 +978,13 @@ bind_maplist([Node-Pr|MapList], Slope, X) :-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
user:progress(FX,X,_G,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :-
problog_flag(sigmoid_slope,Slope),
+ forall(tunable_fact(FactID,_GroundTruth), set_tunable(FactID,Slope,X)),
+ current_iteration(CurrentIteration),
+ retractall(current_iteration(_)),
+ NextIteration is CurrentIteration+1,
+ assertz(current_iteration(NextIteration)),
+ save_model,
+ set_problog_flag(mse_trainset, FX),
X0 <== X[0], sigmoid(X0,Slope,P0),
X1 <== X[1], sigmoid(X1,Slope,P1),
format('~d. Iteration : (x0,x1)=(~4f,~4f) f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,P0 ,P1,FX,X_Norm,G_Norm,Step,Ls]).
diff --git a/packages/python/yap_kernel/CMakeLists.txt b/packages/python/yap_kernel/CMakeLists.txt
index 369ae53ea..5eb32266e 100644
--- a/packages/python/yap_kernel/CMakeLists.txt
+++ b/packages/python/yap_kernel/CMakeLists.txt
@@ -1,4 +1,4 @@
-set (PYTHON_SOURCES backcall/__init__.py
+set (PYTHON_SOURCES
core/yap_kernel/__init__.py
core/yap_kernel/getipython.py
core/__init__.py
@@ -65,7 +65,6 @@ kernelspec.py
__init__.py
yap_kernel_launcher.py
docs/conf.py
-backcall.py
setup.py
interactiveshell.py
examples/embedding/internal_ipkernel.py
@@ -154,7 +153,6 @@ yap_ipython/core/logger.py
yap_ipython/core/excolors.py
yap_ipython/core/completer.py
yap_ipython/core/ultratb.py
-yap_ipython/core/backcall.py
yap_ipython/core/display.py
yap_ipython/core/prompts.py
yap_ipython/core/debugger.py
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/debugger.py b/packages/python/yap_kernel/yap_ipython/terminal/debugger.py
index f09dea94a..e166d3f39 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/debugger.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/debugger.py
@@ -3,20 +3,19 @@ import sys
from yap_ipython.core.debugger import Pdb
-from yap_ipython.yapi import YAPCompleter
-#from .ptutils import IPythonPTCompleter
+from yap_ipython.core.completer import IPCompleter
+from .ptutils import IPythonPTCompleter
from .shortcuts import suspend_to_bg, cursor_in_leading_ws
from prompt_toolkit.enums import DEFAULT_BUFFER
-from prompt_toolkit.filters import (Condition, HasFocus, HasSelection,
- ViInsertMode, EmacsInsertMode)
-from prompt_toolkit.keys import Keys
-from prompt_toolkit.key_binding.manager import KeyBindingManager
+from prompt_toolkit.filters import (Condition, has_focus, has_selection,
+ vi_insert_mode, emacs_insert_mode)
+from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
-from prompt_toolkit.token import Token
-from prompt_toolkit.shortcuts import create_prompt_application
-from prompt_toolkit.interface import CommandLineInterface
+from pygments.token import Token
+from prompt_toolkit.shortcuts.prompt import PromptSession
from prompt_toolkit.enums import EditingMode
+from prompt_toolkit.formatted_text import PygmentsTokens
class TerminalPdb(Pdb):
@@ -26,46 +25,40 @@ class TerminalPdb(Pdb):
self.pt_init()
def pt_init(self):
- def get_prompt_tokens(cli):
+ def get_prompt_tokens():
return [(Token.Prompt, self.prompt)]
- def patch_stdout(**kwargs):
- return self.pt_cli.patch_stdout_context(**kwargs)
-
if self._ptcomp is None:
compl = IPCompleter(shell=self.shell,
namespace={},
global_namespace={},
parent=self.shell,
)
- self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)
+ self._ptcomp = IPythonPTCompleter(compl)
- kbmanager = KeyBindingManager.for_prompt()
- supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
- kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
- )(suspend_to_bg)
+ kb = KeyBindings()
+ supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))
+ kb.add('c-z', filter=supports_suspend)(suspend_to_bg)
if self.shell.display_completions == 'readlinelike':
- kbmanager.registry.add_binding(Keys.ControlI,
- filter=(HasFocus(DEFAULT_BUFFER)
- & ~HasSelection()
- & ViInsertMode() | EmacsInsertMode()
- & ~cursor_in_leading_ws
- ))(display_completions_like_readline)
- multicolumn = (self.shell.display_completions == 'multicolumn')
+ kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)
+ & ~has_selection
+ & vi_insert_mode | emacs_insert_mode
+ & ~cursor_in_leading_ws
+ ))(display_completions_like_readline)
- self._pt_app = create_prompt_application(
+ self.pt_app = PromptSession(
+ message=(lambda: PygmentsTokens(get_prompt_tokens())),
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
- key_bindings_registry=kbmanager.registry,
+ key_bindings=kb,
history=self.shell.debugger_history,
- completer= self._ptcomp,
+ completer=self._ptcomp,
enable_history_search=True,
mouse_support=self.shell.mouse_support,
- get_prompt_tokens=get_prompt_tokens,
- display_completions_in_columns=multicolumn,
- style=self.shell.style
+ complete_style=self.shell.pt_complete_style,
+ style=self.shell.style,
+ inputhook=self.shell.inputhook,
)
- self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -92,7 +85,7 @@ class TerminalPdb(Pdb):
self._ptcomp.ipy_completer.namespace = self.curframe_locals
self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
try:
- line = self.pt_cli.run(reset_current_buffer=True).text
+ line = self.pt_app.prompt() # reset_current_buffer=True)
except EOFError:
line = 'EOF'
line = self.precmd(line)
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/embed.py b/packages/python/yap_kernel/yap_ipython/terminal/embed.py
index 5e959ec5a..f9b8f575c 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/embed.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/embed.py
@@ -366,6 +366,9 @@ def embed(**kwargs):
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
kwargs['config'] = config
+ using = kwargs.get('using', 'sync')
+ if using :
+ kwargs['config'].update({'TerminalInteractiveShell':{'loop_runner':using, 'colors':'NoColor', 'autoawait': using!='sync'}})
#save ps1/ps2 if defined
ps1 = None
ps2 = None
@@ -383,7 +386,7 @@ def embed(**kwargs):
shell = InteractiveShellEmbed.instance(_init_location_id='%s:%s' % (
frame.f_code.co_filename, frame.f_lineno), **kwargs)
shell(header=header, stack_depth=2, compile_flags=compile_flags,
- _call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno))
+ _call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno))
InteractiveShellEmbed.clear_instance()
#restore previous instance
if saved_shell_instance is not None:
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/interactiveshell.py b/packages/python/yap_kernel/yap_ipython/terminal/interactiveshell.py
index 5a4b0221c..0b91f9555 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/interactiveshell.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/interactiveshell.py
@@ -12,18 +12,19 @@ from yap_ipython.utils.terminal import toggle_set_term_title, set_term_title
from yap_ipython.utils.process import abbrev_cwd
from traitlets import (
Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union,
- Any,
+ Any, validate
)
-from prompt_toolkit.document import Document
from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
from prompt_toolkit.filters import (HasFocus, Condition, IsDone)
+from prompt_toolkit.formatted_text import PygmentsTokens
from prompt_toolkit.history import InMemoryHistory
-from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output
-from prompt_toolkit.interface import CommandLineInterface
-from prompt_toolkit.key_binding.manager import KeyBindingManager
from prompt_toolkit.layout.processors import ConditionalProcessor, HighlightMatchingBracketProcessor
-from prompt_toolkit.styles import PygmentsStyle, DynamicStyle
+from prompt_toolkit.output import ColorDepth
+from prompt_toolkit.patch_stdout import patch_stdout
+from prompt_toolkit.shortcuts import PromptSession, CompleteStyle, print_formatted_text
+from prompt_toolkit.styles import DynamicStyle, merge_styles
+from prompt_toolkit.styles.pygments import style_from_pygments_cls, style_from_pygments_dict
from pygments.styles import get_style_by_name
from pygments.style import Style
@@ -33,8 +34,8 @@ from .debugger import TerminalPdb, Pdb
from .magics import TerminalMagics
from .pt_inputhooks import get_inputhook_name_and_func
from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook
-#from .ptutils import IPythonPTCompleter, IPythonPTLexer
-from .shortcuts import register_ipython_shortcuts
+from .ptutils import IPythonPTCompleter, IPythonPTLexer
+from .shortcuts import create_ipython_shortcuts
DISPLAY_BANNER_DEPRECATED = object()
@@ -57,8 +58,6 @@ _style_overrides_linux = {
Token.OutPromptNum: '#bb0000 bold',
}
-
-
def get_default_editor():
try:
return os.environ['EDITOR']
@@ -90,15 +89,11 @@ _use_simple_prompt = ('IPY_TEST_SIMPLE_PROMPT' in os.environ) or (not _is_tty)
class TerminalInteractiveShell(InteractiveShell):
space_for_menu = Integer(6, help='Number of line at the bottom of the screen '
- 'to reserve for the completion menu'
+ 'to reserve for the completion menu'
).tag(config=True)
- def _space_for_menu_changed(self, old, new):
- self._update_layout()
-
- pt_cli = None
+ pt_app = None
debugger_history = None
- _pt_app = None
simple_prompt = Bool(_use_simple_prompt,
help="""Use `raw_input` for the REPL, without completion and prompt colors.
@@ -136,6 +131,23 @@ class TerminalInteractiveShell(InteractiveShell):
highlighting. To see available styles, run `pygmentize -L styles`."""
).tag(config=True)
+ @validate('editing_mode')
+ def _validate_editing_mode(self, proposal):
+ if proposal['value'].lower() == 'vim':
+ proposal['value']= 'vi'
+ elif proposal['value'].lower() == 'default':
+ proposal['value']= 'emacs'
+
+ if hasattr(EditingMode, proposal['value'].upper()):
+ return proposal['value'].lower()
+
+ return self.editing_mode
+
+
+ @observe('editing_mode')
+ def _editing_mode(self, change):
+ u_mode = change.new.upper()
+ self.pt_app.editing_mode = u_mode
@observe('highlighting_style')
@observe('colors')
@@ -169,9 +181,9 @@ class TerminalInteractiveShell(InteractiveShell):
def _prompts_default(self):
return self.prompts_class(self)
- @observe('prompts')
- def _(self, change):
- self._update_layout()
+# @observe('prompts')
+# def _(self, change):
+# self._update_layout()
@default('displayhook_class')
def _displayhook_class_default(self):
@@ -208,6 +220,10 @@ class TerminalInteractiveShell(InteractiveShell):
"may be changed or removed in later releases."
).tag(config=True)
+ enable_history_search = Bool(True,
+ help="Allows to enable/disable the prompt toolkit history search"
+ ).tag(config=True)
+
@observe('term_title')
def init_term_title(self, change=None):
# Enable or disable the terminal title.
@@ -227,24 +243,19 @@ class TerminalInteractiveShell(InteractiveShell):
def init_prompt_toolkit_cli(self):
if self.simple_prompt:
# Fall back to plain non-interactive output for tests.
- # This is very limited, and only accepts a single line.
+ # This is very limited.
def prompt():
- isp = self.input_splitter
prompt_text = "".join(x[1] for x in self.prompts.in_prompt_tokens())
+ lines = [input(prompt_text)]
prompt_continuation = "".join(x[1] for x in self.prompts.continuation_prompt_tokens())
- while isp.push_accepts_more():
- line = input(prompt_text)
- isp.push(line)
- prompt_text = prompt_continuation
- return isp.source_reset()
+ while self.check_complete('\n'.join(lines))[0] == 'incomplete':
+ lines.append( input(prompt_continuation) )
+ return '\n'.join(lines)
self.prompt_for_code = prompt
return
# Set up keyboard shortcuts
- kbmanager = KeyBindingManager.for_prompt(
- enable_open_in_editor=self.extra_open_editor_shortcuts,
- )
- register_ipython_shortcuts(kbmanager.registry, self)
+ key_bindings = create_ipython_shortcuts(self)
# Pre-populate history from yap_ipython's history database
history = InMemoryHistory()
@@ -254,7 +265,7 @@ class TerminalInteractiveShell(InteractiveShell):
# Ignore blank lines and consecutive duplicates
cell = cell.rstrip()
if cell and (cell != last_cell):
- history.append(cell)
+ history.append_string(cell)
last_cell = cell
self._style = self._make_style_from_name_or_cls(self.highlighting_style)
@@ -262,24 +273,18 @@ class TerminalInteractiveShell(InteractiveShell):
editing_mode = getattr(EditingMode, self.editing_mode.upper())
- def patch_stdout(**kwargs):
- return self.pt_cli.patch_stdout_context(**kwargs)
-
- self._pt_app = create_prompt_application(
+ self.pt_app = PromptSession(
editing_mode=editing_mode,
- key_bindings_registry=kbmanager.registry,
+ key_bindings=key_bindings,
history=history,
- # completer=IPythonPTCompleter(shell=self,
- # patch_stdout=patch_stdout),
- enable_history_search=True,
+ completer=IPythonPTCompleter(shell=self),
+ enable_history_search = self.enable_history_search,
style=self.style,
+ include_default_pygments_style=False,
mouse_support=self.mouse_support,
- **self._layout_options()
- )
- self._eventloop = create_eventloop(self.inputhook)
- self.pt_cli = CommandLineInterface(
- self._pt_app, eventloop=self._eventloop,
- output=create_output(true_color=self.true_color))
+ enable_open_in_editor=self.extra_open_editor_shortcuts,
+ color_depth=(ColorDepth.TRUE_COLOR if self.true_color else None),
+ **self._extra_prompt_options())
def _make_style_from_name_or_cls(self, name_or_cls):
"""
@@ -309,9 +314,9 @@ class TerminalInteractiveShell(InteractiveShell):
Token.Name.Class: 'bold #2080D0',
Token.Name.Namespace: 'bold #2080D0',
Token.Prompt: '#009900',
- Token.PromptNum: '#00ff00 bold',
+ Token.PromptNum: '#ansibrightgreen bold',
Token.OutPrompt: '#990000',
- Token.OutPromptNum: '#ff0000 bold',
+ Token.OutPromptNum: '#ansibrightred bold',
})
# Hack: Due to limited color support on the Windows console
@@ -335,49 +340,66 @@ class TerminalInteractiveShell(InteractiveShell):
style_cls = name_or_cls
style_overrides = {
Token.Prompt: '#009900',
- Token.PromptNum: '#00ff00 bold',
+ Token.PromptNum: '#ansibrightgreen bold',
Token.OutPrompt: '#990000',
- Token.OutPromptNum: '#ff0000 bold',
+ Token.OutPromptNum: '#ansibrightred bold',
}
style_overrides.update(self.highlighting_style_overrides)
- style = PygmentsStyle.from_defaults(pygments_style_cls=style_cls,
- style_dict=style_overrides)
+ style = merge_styles([
+ style_from_pygments_cls(style_cls),
+ style_from_pygments_dict(style_overrides),
+ ])
return style
- def _layout_options(self):
+ @property
+ def pt_complete_style(self):
+ return {
+ 'multicolumn': CompleteStyle.MULTI_COLUMN,
+ 'column': CompleteStyle.COLUMN,
+ 'readlinelike': CompleteStyle.READLINE_LIKE,
+ }[self.display_completions]
+
+ def _extra_prompt_options(self):
"""
Return the current layout option for the current Terminal InteractiveShell
"""
+ def get_message():
+ return PygmentsTokens(self.prompts.in_prompt_tokens())
+
return {
+ 'complete_in_thread': False,
'lexer':IPythonPTLexer(),
'reserve_space_for_menu':self.space_for_menu,
- 'get_prompt_tokens':self.prompts.in_prompt_tokens,
- 'get_continuation_tokens':self.prompts.continuation_prompt_tokens,
- 'multiline':True,
- 'display_completions_in_columns': (self.display_completions == 'multicolumn'),
+ 'message': get_message,
+ 'prompt_continuation': (
+ lambda width, lineno, is_soft_wrap:
+ PygmentsTokens(self.prompts.continuation_prompt_tokens(width))),
+ 'multiline': True,
+ 'complete_style': self.pt_complete_style,
# Highlight matching brackets, but only when this setting is
# enabled, and only when the DEFAULT_BUFFER has the focus.
- 'extra_input_processors': [ConditionalProcessor(
+ 'input_processors': [ConditionalProcessor(
processor=HighlightMatchingBracketProcessor(chars='[](){}'),
filter=HasFocus(DEFAULT_BUFFER) & ~IsDone() &
- Condition(lambda cli: self.highlight_matching_brackets))],
+ Condition(lambda: self.highlight_matching_brackets))],
+ 'inputhook': self.inputhook,
}
- def _update_layout(self):
- """
- Ask for a re computation of the application layout, if for example ,
- some configuration options have changed.
- """
- if self._pt_app:
- self._pt_app.layout = create_prompt_layout(**self._layout_options())
-
def prompt_for_code(self):
- with self.pt_cli.patch_stdout_context(raw=True):
- document = self.pt_cli.run(
- pre_run=self.pre_prompt, reset_current_buffer=True)
- return document.text
+ if self.rl_next_input:
+ default = self.rl_next_input
+ self.rl_next_input = None
+ else:
+ default = ''
+
+ with patch_stdout(raw=True):
+ text = self.pt_app.prompt(
+ default=default,
+# pre_run=self.pre_prompt,# reset_current_buffer=True,
+ **self._extra_prompt_options())
+ return text
def enable_win_unicode_console(self):
if sys.version_info >= (3, 6):
@@ -437,22 +459,6 @@ class TerminalInteractiveShell(InteractiveShell):
rl_next_input = None
- def pre_prompt(self):
- if self.rl_next_input:
- # We can't set the buffer here, because it will be reset just after
- # this. Adding a callable to pre_run_callables does what we need
- # after the buffer is reset.
- s = self.rl_next_input
- def set_doc():
- self.pt_cli.application.buffer.document = Document(s)
- if hasattr(self.pt_cli, 'pre_run_callables'):
- self.pt_cli.pre_run_callables.append(set_doc)
- else:
- # Older version of prompt_toolkit; it's OK to set the document
- # directly here.
- set_doc()
- self.rl_next_input = None
-
def interact(self, display_banner=DISPLAY_BANNER_DEPRECATED):
if display_banner is not DISPLAY_BANNER_DEPRECATED:
@@ -477,7 +483,7 @@ class TerminalInteractiveShell(InteractiveShell):
# An extra layer of protection in case someone mashing Ctrl-C breaks
# out of our internal code.
if display_banner is not DISPLAY_BANNER_DEPRECATED:
- warn('mainloop `display_banner` argument is deprecated since yap_ipython 5.0. Call `show_banner()` if needed.', DeprecationWarning, stacklevel=2)
+ warn('mainloop `display_banner` argument is deprecated since IPython 5.0. Call `show_banner()` if needed.', DeprecationWarning, stacklevel=2)
while True:
try:
self.interact()
@@ -515,8 +521,9 @@ class TerminalInteractiveShell(InteractiveShell):
return
tokens = self.prompts.rewrite_prompt_tokens()
- if self.pt_cli:
- self.pt_cli.print_tokens(tokens)
+ if self.pt_app:
+ print_formatted_text(PygmentsTokens(tokens), end='',
+ style=self.pt_app.app.style)
print(cmd)
else:
prompt = ''.join(s for t, s in tokens)
@@ -531,7 +538,7 @@ class TerminalInteractiveShell(InteractiveShell):
elif self._prompts_before:
self.prompts = self._prompts_before
self._prompts_before = None
- self._update_layout()
+# self._update_layout()
InteractiveShellABC.register(TerminalInteractiveShell)
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/ipapp.py b/packages/python/yap_kernel/yap_ipython/terminal/ipapp.py
old mode 100644
new mode 100755
index 89db35052..1fa0b434a
--- a/packages/python/yap_kernel/yap_ipython/terminal/ipapp.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/ipapp.py
@@ -18,7 +18,7 @@ from traitlets.config.loader import Config
from traitlets.config.application import boolean_flag, catch_config_error
from yap_ipython.core import release
from yap_ipython.core import usage
-from yap_ipython.yapi import YAPCompleter
+from yap_ipython.core.completer import IPCompleter
from yap_ipython.core.crashhandler import CrashHandler
from yap_ipython.core.formatters import PlainTextFormatter
from yap_ipython.core.history import HistoryManager
@@ -106,7 +106,7 @@ addflag('simple-prompt', 'TerminalInteractiveShell.simple_prompt',
"Use a rich interactive prompt with prompt_toolkit",
)
-addflag('banner', 'TerminalIPythonApp.display_banner',
+addflag('banner', 'Terminalyap_ipythonApp.display_banner',
"Display a banner upon starting yap_ipython.",
"Don't display a banner upon starting yap_ipython."
)
@@ -141,12 +141,12 @@ frontend_flags['classic']=(
#
# # quick is harder to implement
frontend_flags['quick']=(
- {'TerminalIPythonApp' : {'quick' : True}},
+ {'Terminalyap_ipythonApp' : {'quick' : True}},
"Enable quick startup with no config files."
)
frontend_flags['i'] = (
- {'TerminalIPythonApp' : {'force_interact' : True}},
+ {'Terminalyap_ipythonApp' : {'force_interact' : True}},
"""If running code from the command line, become interactive afterwards.
It is often useful to follow this with `--` to treat remaining flags as
script arguments.
@@ -162,7 +162,7 @@ aliases.update(shell_aliases)
#-----------------------------------------------------------------------------
-class LocateIPythonApp(BaseYAPApplication):
+class Locateyap_ipythonApp(BaseYAPApplication):
description = """print the path to the yap_ipython dir"""
subcommands = dict(
profile=('yap_ipython.core.profileapp.ProfileLocate',
@@ -176,8 +176,8 @@ class LocateIPythonApp(BaseYAPApplication):
print(self.ipython_dir)
-class TerminalIPythonApp(BaseYAPApplication, InteractiveShellApp):
- name = u'yap'
+class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
+ name = u'ipython'
description = usage.cl_usage
crash_handler_class = IPAppCrashHandler
examples = _examples
@@ -194,7 +194,7 @@ class TerminalIPythonApp(BaseYAPApplication, InteractiveShellApp):
@default('classes')
def _classes_default(self):
- """This has to be in a method, for TerminalIPythonApp to be available."""
+ """This has to be in a method, for Terminalyap_ipythonApp to be available."""
return [
InteractiveShellApp, # ShellApp comes before TerminalApp, because
self.__class__, # it will also affect subclasses (e.g. QtConsole)
@@ -202,7 +202,7 @@ class TerminalIPythonApp(BaseYAPApplication, InteractiveShellApp):
HistoryManager,
ProfileDir,
PlainTextFormatter,
- YAPCompleter,
+ IPCompleter,
ScriptMagics,
LoggingMagics,
StoreMagics,
@@ -215,7 +215,7 @@ class TerminalIPythonApp(BaseYAPApplication, InteractiveShellApp):
notebook=('notebook.notebookapp.NotebookApp',
"""DEPRECATED, Will be removed in yap_ipython 6.0 : Launch the Jupyter HTML Notebook Server."""
),
- console=('jupyter_console.app.ZMQTerminalIPythonApp',
+ console=('jupyter_console.app.ZMQTerminalyap_ipythonApp',
"""DEPRECATED, Will be removed in yap_ipython 6.0 : Launch the Jupyter terminal-based Console."""
),
nbconvert=('nbconvert.nbconvertapp.NbConvertApp',
@@ -232,11 +232,11 @@ class TerminalIPythonApp(BaseYAPApplication, InteractiveShellApp):
profile = ("yap_ipython.core.profileapp.ProfileApp",
"Create and manage yap_ipython profiles."
),
- kernel = ("yap_kernel.kernelapp.YAPKernelApp",
+ kernel = ("ipykernel.kernelapp.IPKernelApp",
"Start a kernel without an attached frontend."
),
- locate=('yap_ipython.terminal.ipapp.LocateIPythonApp',
- LocateIPythonApp.description
+ locate=('yap_ipython.terminal.ipapp.Locateyap_ipythonApp',
+ Locateyap_ipythonApp.description
),
history=('yap_ipython.core.historyapp.HistoryApp',
"Manage the yap_ipython history database."
@@ -300,12 +300,12 @@ class TerminalIPythonApp(BaseYAPApplication, InteractiveShellApp):
" Use `--matplotlib ` and import pylab manually.")
argv[idx] = '--pylab'
- return super(TerminalIPythonApp, self).parse_command_line(argv)
-
+ return super(Terminalyap_ipythonApp, self).parse_command_line(argv)
+
@catch_config_error
def initialize(self, argv=None):
"""Do actions after construct, but before starting the app."""
- super(TerminalIPythonApp, self).initialize(argv)
+ super(Terminalyap_ipythonApp, self).initialize(argv)
if self.subapp is not None:
# don't bother initializing further, starting subapp
return
@@ -368,12 +368,12 @@ def load_default_config(ipython_dir=None):
ipython_dir = get_ipython_dir()
profile_dir = os.path.join(ipython_dir, 'profile_default')
- app = TerminalIPythonApp()
+ app = Terminalyap_ipythonApp()
app.config_file_paths.append(profile_dir)
app.load_config_file()
return app.config
-launch_new_instance = TerminalIPythonApp.launch_instance
+launch_new_instance = Terminalyap_ipythonApp.launch_instance
if __name__ == '__main__':
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/magics.py b/packages/python/yap_kernel/yap_ipython/terminal/magics.py
index 284447113..dd8dfea8f 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/magics.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/magics.py
@@ -9,7 +9,6 @@ import os
import sys
from yap_ipython.core.error import TryNext, UsageError
-from yap_ipython.core.inputsplitter import IPythonInputSplitter
from yap_ipython.core.magic import Magics, magics_class, line_magic
from yap_ipython.lib.clipboard import ClipboardEmpty
from yap_ipython.utils.text import SList, strip_email_quotes
@@ -40,7 +39,6 @@ def get_pasted_lines(sentinel, l_input=py3compat.input, quiet=False):
class TerminalMagics(Magics):
def __init__(self, shell):
super(TerminalMagics, self).__init__(shell)
- self.input_splitter = IPythonInputSplitter()
def store_or_execute(self, block, name):
""" Execute a block, or store it in a variable, per the user's request.
@@ -82,8 +80,6 @@ class TerminalMagics(Magics):
@line_magic
def autoindent(self, parameter_s = ''):
"""Toggle autoindent on/off (deprecated)"""
- print("%autoindent is deprecated since yap_ipython 5: you can now paste "
- "multiple lines without turning autoindentation off.")
self.shell.set_autoindent()
print("Automatic indentation is:",['OFF','ON'][self.shell.autoindent])
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/prompts.py b/packages/python/yap_kernel/yap_ipython/terminal/prompts.py
index 2e7c8f660..35fb7a427 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/prompts.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/prompts.py
@@ -5,23 +5,34 @@ import sys
from yap_ipython.core.displayhook import DisplayHook
-from prompt_toolkit.layout.utils import token_list_width
+from prompt_toolkit.formatted_text import fragment_list_width, PygmentsTokens
+from prompt_toolkit.shortcuts import print_formatted_text
+
class Prompts(object):
def __init__(self, shell):
self.shell = shell
- def in_prompt_tokens(self, cli=None):
+ def vi_mode(self):
+ if not hasattr(self.shell.pt_app, 'editing_mode'):
+ return ''
+ if self.shell.pt_app.editing_mode == 'VI':
+ return '['+str(self.shell.pt_app.app.vi_state.input_mode)[3:6]+'] '
+ return ''
+
+
+ def in_prompt_tokens(self):
return [
+ (Token.Prompt, self.vi_mode() ),
(Token.Prompt, 'In ['),
(Token.PromptNum, str(self.shell.execution_count)),
(Token.Prompt, ']: '),
]
def _width(self):
- return token_list_width(self.in_prompt_tokens())
+ return fragment_list_width(self.in_prompt_tokens())
- def continuation_prompt_tokens(self, cli=None, width=None):
+ def continuation_prompt_tokens(self, width=None):
if width is None:
width = self._width()
return [
@@ -42,12 +53,12 @@ class Prompts(object):
]
class ClassicPrompts(Prompts):
- def in_prompt_tokens(self, cli=None):
+ def in_prompt_tokens(self):
return [
(Token.Prompt, '>>> '),
]
- def continuation_prompt_tokens(self, cli=None, width=None):
+ def continuation_prompt_tokens(self, width=None):
return [
(Token.Prompt, '... ')
]
@@ -73,7 +84,9 @@ class RichPromptDisplayHook(DisplayHook):
# Ask for a newline before multiline output
self.prompt_end_newline = False
- if self.shell.pt_cli:
- self.shell.pt_cli.print_tokens(tokens)
+ if self.shell.pt_app:
+ print_formatted_text(PygmentsTokens(tokens),
+ style=self.shell.pt_app.app.style, end='',
+ )
else:
sys.stdout.write(prompt_txt)
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/__init__.py b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/__init__.py
index 331328e0a..3766973e8 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/__init__.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/__init__.py
@@ -45,5 +45,5 @@ def get_inputhook_name_and_func(gui):
os.environ['QT_API'] = 'pyqt5'
gui_mod = 'qt'
- mod = importlib.import_module('yap_ipython.terminal.pt_inputhooks.'+gui_mod)
+ mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod)
return gui, mod.inputhook
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/glut.py b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/glut.py
index e3e8b4bc6..f6d54a55b 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/glut.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/glut.py
@@ -3,7 +3,7 @@
# GLUT is quite an old library and it is difficult to ensure proper
-# integration within yap_ipython since original GLUT does not allow to handle
+# integration within IPython since original GLUT does not allow to handle
# events one by one. Instead, it requires for the mainloop to be entered
# and never returned (there is not even a function to exit he
# mainloop). Fortunately, there are alternatives such as freeglut
@@ -16,7 +16,7 @@
# being first created. We choose to make this window invisible. This means that
# display mode options are set at this level and user won't be able to change
# them later without modifying the code. This should probably be made available
-# via yap_ipython options system.
+# via IPython options system.
import sys
import time
@@ -26,11 +26,11 @@ import OpenGL.platform as platform
from timeit import default_timer as clock
# Frame per second : 60
-# Should probably be an yap_ipython option
+# Should probably be an IPython option
glut_fps = 60
# Display mode : double buffeed + rgba + depth
-# Should probably be an yap_ipython option
+# Should probably be an IPython option
glut_display_mode = (glut.GLUT_DOUBLE |
glut.GLUT_RGBA |
glut.GLUT_DEPTH)
@@ -99,7 +99,7 @@ def inputhook(context):
needed, otherwise, CPU usage is at 100%. This sleep time should be tuned
though for best performance.
"""
- # We need to protect against a user pressing Control-C when yap_ipython is
+ # We need to protect against a user pressing Control-C when IPython is
# idle and this is running. We trap KeyboardInterrupt and pass.
signal.signal(signal.SIGINT, glut_int_handler)
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/pyglet.py b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/pyglet.py
index c51ba9071..49ec86d22 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/pyglet.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/pyglet.py
@@ -1,4 +1,4 @@
-"""Enable pyglet to be used interacively with prompt_toolkit
+"""Enable pyglet to be used interactively with prompt_toolkit
"""
import sys
@@ -29,7 +29,7 @@ def inputhook(context):
needed, otherwise, CPU usage is at 100%. This sleep time should be tuned
though for best performance.
"""
- # We need to protect against a user pressing Control-C when yap_ipython is
+ # We need to protect against a user pressing Control-C when IPython is
# idle and this is running. We trap KeyboardInterrupt and pass.
try:
t = clock()
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/qt.py b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/qt.py
index d5997a21f..2ceda6bdc 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/qt.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/qt.py
@@ -1,15 +1,29 @@
import sys
-from yap_ipython.external.qt_for_kernel import QtCore, QtGui
+import os
+from IPython.external.qt_for_kernel import QtCore, QtGui
# If we create a QApplication, keep a reference to it so that it doesn't get
# garbage collected.
_appref = None
-
+_already_warned = False
def inputhook(context):
global _appref
app = QtCore.QCoreApplication.instance()
if not app:
+ if sys.platform == 'linux':
+ if not os.environ.get('DISPLAY') \
+ and not os.environ.get('WAYLAND_DISPLAY'):
+ import warnings
+ global _already_warned
+ if not _already_warned:
+ _already_warned = True
+ warnings.warn(
+ 'The DISPLAY or WAYLAND_DISPLAY environment variable is '
+ 'not set or empty and Qt5 requires this environment '
+ 'variable. Deactivate Qt5 code.'
+ )
+ return
_appref = app = QtGui.QApplication([" "])
event_loop = QtCore.QEventLoop(app)
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/wx.py b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/wx.py
index ab14ac6af..2f416d10a 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/wx.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/pt_inputhooks/wx.py
@@ -90,7 +90,7 @@ def inputhook_wx3(context):
time.sleep is inserted. This is needed, otherwise, CPU usage is at 100%.
This sleep time should be tuned though for best performance.
"""
- # We need to protect against a user pressing Control-C when yap_ipython is
+ # We need to protect against a user pressing Control-C when IPython is
# idle and this is running. We trap KeyboardInterrupt and pass.
try:
app = wx.GetApp()
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/ptshell.py b/packages/python/yap_kernel/yap_ipython/terminal/ptshell.py
index a8d1387a5..666d3c5b5 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/ptshell.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/ptshell.py
@@ -1,8 +1,8 @@
raise DeprecationWarning("""DEPRECATED:
After Popular request and decision from the BDFL:
-`yap_ipython.terminal.ptshell` has been moved back to `yap_ipython.terminal.interactiveshell`
-during the beta cycle (after yap_ipython 5.0.beta3) Sorry about that.
+`IPython.terminal.ptshell` has been moved back to `IPython.terminal.interactiveshell`
+during the beta cycle (after IPython 5.0.beta3) Sorry about that.
This file will be removed in 5.0 rc or final.
""")
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/ptutils.py b/packages/python/yap_kernel/yap_ipython/terminal/ptutils.py
index 257044663..f7367526b 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/ptutils.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/ptutils.py
@@ -1,21 +1,22 @@
"""prompt-toolkit utilities
Everything in this module is a private API,
-not to be used outside yap_ipython.
+not to be used outside IPython.
"""
-# Copyright (c) yap_ipython Development Team.
+# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import unicodedata
from wcwidth import wcwidth
-from yap_ipython.core.completer import (
+from IPython.core.completer import (
provisionalcompleter, cursor_to_position,
_deduplicate_completions)
from prompt_toolkit.completion import Completer, Completion
-from prompt_toolkit.layout.lexers import Lexer
-from prompt_toolkit.layout.lexers import PygmentsLexer
+from prompt_toolkit.lexers import Lexer
+from prompt_toolkit.lexers import PygmentsLexer
+from prompt_toolkit.patch_stdout import patch_stdout
import pygments.lexers as pygments_lexers
@@ -51,15 +52,12 @@ def _adjust_completion_text_based_on_context(text, body, offset):
class IPythonPTCompleter(Completer):
- """Adaptor to provide yap_ipython completions to prompt_toolkit"""
- def __init__(self, ipy_completer=None, shell=None, patch_stdout=None):
+ """Adaptor to provide IPython completions to prompt_toolkit"""
+ def __init__(self, ipy_completer=None, shell=None):
if shell is None and ipy_completer is None:
raise TypeError("Please pass shell=an InteractiveShell instance.")
self._ipy_completer = ipy_completer
self.shell = shell
- if patch_stdout is None:
- raise TypeError("Please pass patch_stdout")
- self.patch_stdout = patch_stdout
@property
def ipy_completer(self):
@@ -75,7 +73,7 @@ class IPythonPTCompleter(Completer):
# is imported). This context manager ensures that doesn't interfere with
# the prompt.
- with self.patch_stdout(), provisionalcompleter():
+ with patch_stdout(), provisionalcompleter():
body = document.text
cursor_row = document.cursor_position_row
cursor_col = document.cursor_position_col
@@ -143,7 +141,7 @@ class IPythonPTLexer(Lexer):
'latex': PygmentsLexer(l.TexLexer),
}
- def lex_document(self, cli, document):
+ def lex_document(self, document):
text = document.text.lstrip()
lexer = self.python_lexer
@@ -157,4 +155,4 @@ class IPythonPTLexer(Lexer):
lexer = l
break
- return lexer.lex_document(cli, document)
+ return lexer.lex_document(document)
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/shortcuts.py b/packages/python/yap_kernel/yap_ipython/terminal/shortcuts.py
index a9e2e948e..28aa5b4eb 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/shortcuts.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/shortcuts.py
@@ -1,9 +1,9 @@
"""
-Module to define and register Terminal yap_ipython shortcuts with
+Module to define and register Terminal IPython shortcuts with
:mod:`prompt_toolkit`
"""
-# Copyright (c) yap_ipython Development Team.
+# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import warnings
@@ -12,91 +12,78 @@ import sys
from typing import Callable
+from prompt_toolkit.application.current import get_app
from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER
-from prompt_toolkit.filters import (HasFocus, HasSelection, Condition,
- ViInsertMode, EmacsInsertMode, HasCompletions)
-from prompt_toolkit.filters.cli import ViMode, ViNavigationMode
-from prompt_toolkit.keys import Keys
+from prompt_toolkit.filters import (has_focus, has_selection, Condition,
+ vi_insert_mode, emacs_insert_mode, has_completions, vi_mode)
from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
+from prompt_toolkit.key_binding import KeyBindings
-from yap_ipython.utils.decorators import undoc
+from IPython.utils.decorators import undoc
@undoc
@Condition
-def cursor_in_leading_ws(cli):
- before = cli.application.buffer.document.current_line_before_cursor
+def cursor_in_leading_ws():
+ before = get_app().current_buffer.document.current_line_before_cursor
return (not before) or before.isspace()
-def register_ipython_shortcuts(registry, shell):
- """Set up the prompt_toolkit keyboard shortcuts for yap_ipython"""
- insert_mode = ViInsertMode() | EmacsInsertMode()
+
+def create_ipython_shortcuts(shell):
+ """Set up the prompt_toolkit keyboard shortcuts for IPython"""
+
+ kb = KeyBindings()
+ insert_mode = vi_insert_mode | emacs_insert_mode
if getattr(shell, 'handle_return', None):
return_handler = shell.handle_return(shell)
else:
return_handler = newline_or_execute_outer(shell)
- # Ctrl+J == Enter, seemingly
- registry.add_binding(Keys.ControlJ,
- filter=(HasFocus(DEFAULT_BUFFER)
- & ~HasSelection()
- & insert_mode
+ kb.add('enter', filter=(has_focus(DEFAULT_BUFFER)
+ & ~has_selection
+ & insert_mode
))(return_handler)
- registry.add_binding(Keys.ControlBackslash)(force_exit)
+ kb.add('c-\\')(force_exit)
- registry.add_binding(Keys.ControlP,
- filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)
- ))(previous_history_or_previous_completion)
+ kb.add('c-p', filter=(vi_insert_mode & has_focus(DEFAULT_BUFFER))
+ )(previous_history_or_previous_completion)
- registry.add_binding(Keys.ControlN,
- filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)
- ))(next_history_or_next_completion)
+ kb.add('c-n', filter=(vi_insert_mode & has_focus(DEFAULT_BUFFER))
+ )(next_history_or_next_completion)
- registry.add_binding(Keys.ControlG,
- filter=(HasFocus(DEFAULT_BUFFER) & HasCompletions()
- ))(dismiss_completion)
+ kb.add('c-g', filter=(has_focus(DEFAULT_BUFFER) & has_completions)
+ )(dismiss_completion)
- registry.add_binding(Keys.ControlC, filter=HasFocus(DEFAULT_BUFFER)
- )(reset_buffer)
+ kb.add('c-c', filter=has_focus(DEFAULT_BUFFER))(reset_buffer)
- registry.add_binding(Keys.ControlC, filter=HasFocus(SEARCH_BUFFER)
- )(reset_search_buffer)
+ kb.add('c-c', filter=has_focus(SEARCH_BUFFER))(reset_search_buffer)
- supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
- registry.add_binding(Keys.ControlZ, filter=supports_suspend
- )(suspend_to_bg)
+ supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))
+ kb.add('c-z', filter=supports_suspend)(suspend_to_bg)
# Ctrl+I == Tab
- registry.add_binding(Keys.ControlI,
- filter=(HasFocus(DEFAULT_BUFFER)
- & ~HasSelection()
- & insert_mode
- & cursor_in_leading_ws
+ kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)
+ & ~has_selection
+ & insert_mode
+ & cursor_in_leading_ws
))(indent_buffer)
+ kb.add('c-o', filter=(has_focus(DEFAULT_BUFFER) & emacs_insert_mode)
+ )(newline_autoindent_outer(shell.input_transformer_manager))
- registry.add_binding(Keys.ControlO,
- filter=(HasFocus(DEFAULT_BUFFER)
- & EmacsInsertMode()))(newline_autoindent_outer(shell.input_splitter))
-
- registry.add_binding(Keys.F2,
- filter=HasFocus(DEFAULT_BUFFER)
- )(open_input_in_editor)
+ kb.add('f2', filter=has_focus(DEFAULT_BUFFER))(open_input_in_editor)
if shell.display_completions == 'readlinelike':
- registry.add_binding(Keys.ControlI,
- filter=(HasFocus(DEFAULT_BUFFER)
- & ~HasSelection()
- & insert_mode
- & ~cursor_in_leading_ws
- ))(display_completions_like_readline)
+ kb.add('c-i', filter=(has_focus(DEFAULT_BUFFER)
+ & ~has_selection
+ & insert_mode
+ & ~cursor_in_leading_ws
+ ))(display_completions_like_readline)
if sys.platform == 'win32':
- registry.add_binding(Keys.ControlV,
- filter=(
- HasFocus(
- DEFAULT_BUFFER) & ~ViMode()
- ))(win_paste)
+ kb.add('c-v', filter=(has_focus(DEFAULT_BUFFER) & ~vi_mode))(win_paste)
+
+ return kb
def newline_or_execute_outer(shell):
@@ -119,18 +106,24 @@ def newline_or_execute_outer(shell):
check_text = d.text
else:
check_text = d.text[:d.cursor_position]
- status, indent = shell.input_splitter.check_complete(check_text + '\n')
+ status, indent = shell.check_complete(check_text)
if not (d.on_last_line or
d.cursor_position_row >= d.line_count - d.empty_line_count_at_the_end()
):
- b.insert_text('\n' + (' ' * (indent or 0)))
+ if shell.autoindent:
+ b.insert_text('\n' + indent)
+ else:
+ b.insert_text('\n')
return
- if (status != 'incomplete') and b.accept_action.is_returnable:
- b.accept_action.validate_and_handle(event.cli, b)
+ if (status != 'incomplete') and b.accept_handler:
+ b.validate_and_handle()
else:
- b.insert_text('\n' + (' ' * (indent or 0)))
+ if shell.autoindent:
+ b.insert_text('\n' + indent)
+ else:
+ b.insert_text('\n')
return newline_or_execute
@@ -170,10 +163,10 @@ def reset_search_buffer(event):
if event.current_buffer.document.text:
event.current_buffer.reset()
else:
- event.cli.push_focus(DEFAULT_BUFFER)
+ event.app.layout.focus(DEFAULT_BUFFER)
def suspend_to_bg(event):
- event.cli.suspend_to_background()
+ event.app.suspend_to_background()
def force_exit(event):
"""
@@ -187,14 +180,14 @@ def indent_buffer(event):
@undoc
def newline_with_copy_margin(event):
"""
- DEPRECATED since yap_ipython 6.0
+ DEPRECATED since IPython 6.0
See :any:`newline_autoindent_outer` for a replacement.
Preserve margin and cursor position when using
Control-O to insert a newline in EMACS mode
"""
- warnings.warn("`newline_with_copy_margin(event)` is deprecated since yap_ipython 6.0. "
+ warnings.warn("`newline_with_copy_margin(event)` is deprecated since IPython 6.0. "
"see `newline_autoindent_outer(shell)(event)` for a replacement.",
DeprecationWarning, stacklevel=2)
@@ -232,13 +225,13 @@ def newline_autoindent_outer(inputsplitter) -> Callable[..., None]:
def open_input_in_editor(event):
- event.cli.current_buffer.tempfile_suffix = ".py"
- event.cli.current_buffer.open_in_editor(event.cli)
+ event.app.current_buffer.tempfile_suffix = ".py"
+ event.app.current_buffer.open_in_editor()
if sys.platform == 'win32':
- from yap_ipython.core.error import TryNext
- from yap_ipython.lib.clipboard import (ClipboardEmpty,
+ from IPython.core.error import TryNext
+ from IPython.lib.clipboard import (ClipboardEmpty,
win32_clipboard_get,
tkinter_clipboard_get)
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/tests/test_embed.py b/packages/python/yap_kernel/yap_ipython/terminal/tests/test_embed.py
index d90e1b934..de5b1e348 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/tests/test_embed.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/tests/test_embed.py
@@ -1,7 +1,7 @@
-"""Test embedding of yap_ipython"""
+"""Test embedding of IPython"""
#-----------------------------------------------------------------------------
-# Copyright (C) 2013 The yap_ipython Development Team
+# Copyright (C) 2013 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
@@ -15,8 +15,8 @@ import os
import subprocess
import sys
import nose.tools as nt
-from yap_ipython.utils.tempdir import NamedFileInTemporaryDirectory
-from yap_ipython.testing.decorators import skip_win32
+from IPython.utils.tempdir import NamedFileInTemporaryDirectory
+from IPython.testing.decorators import skip_win32
#-----------------------------------------------------------------------------
# Tests
@@ -24,13 +24,13 @@ from yap_ipython.testing.decorators import skip_win32
_sample_embed = b"""
-import yap_ipython
+import IPython
a = 3
b = 14
print(a, '.', b)
-yap_ipython.embed()
+IPython.embed()
print('bye!')
"""
@@ -38,7 +38,7 @@ print('bye!')
_exit = b"exit\r"
def test_ipython_embed():
- """test that `yap_ipython.embed()` works"""
+ """test that `IPython.embed()` works"""
with NamedFileInTemporaryDirectory('file_with_embed.py') as f:
f.write(_sample_embed)
f.flush()
@@ -58,26 +58,27 @@ def test_ipython_embed():
nt.assert_in('3 . 14', std)
if os.name != 'nt':
# TODO: Fix up our different stdout references, see issue gh-14
- nt.assert_in('yap_ipython', std)
+ nt.assert_in('IPython', std)
nt.assert_in('bye!', std)
@skip_win32
def test_nest_embed():
- """test that `yap_ipython.embed()` is nestable"""
+ """test that `IPython.embed()` is nestable"""
import pexpect
ipy_prompt = r']:' #ansi color codes give problems matching beyond this
env = os.environ.copy()
env['IPY_TEST_SIMPLE_PROMPT'] = '1'
- child = pexpect.spawn(sys.executable, ['-m', 'yap_ipython', '--colors=nocolor'],
+ child = pexpect.spawn(sys.executable, ['-m', 'IPython', '--colors=nocolor'],
env=env)
+ child.timeout = 5
child.expect(ipy_prompt)
- child.sendline("import yap_ipython")
+ child.sendline("import IPython")
child.expect(ipy_prompt)
child.sendline("ip0 = get_ipython()")
#enter first nested embed
- child.sendline("yap_ipython.embed()")
+ child.sendline("IPython.embed()")
#skip the banner until we get to a prompt
try:
prompted = -1
@@ -86,15 +87,16 @@ def test_nest_embed():
except pexpect.TIMEOUT as e:
print(e)
#child.interact()
- child.sendline("embed1 = get_ipython()"); child.expect(ipy_prompt)
+ child.sendline("embed1 = get_ipython()")
+ child.expect(ipy_prompt)
child.sendline("print('true' if embed1 is not ip0 else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
- child.sendline("print('true' if yap_ipython.get_ipython() is embed1 else 'false')")
+ child.sendline("print('true' if IPython.get_ipython() is embed1 else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
#enter second nested embed
- child.sendline("yap_ipython.embed()")
+ child.sendline("IPython.embed()")
#skip the banner until we get to a prompt
try:
prompted = -1
@@ -103,11 +105,12 @@ def test_nest_embed():
except pexpect.TIMEOUT as e:
print(e)
#child.interact()
- child.sendline("embed2 = get_ipython()"); child.expect(ipy_prompt)
+ child.sendline("embed2 = get_ipython()")
+ child.expect(ipy_prompt)
child.sendline("print('true' if embed2 is not embed1 else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
- child.sendline("print('true' if embed2 is yap_ipython.get_ipython() else 'false')")
+ child.sendline("print('true' if embed2 is IPython.get_ipython() else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
child.sendline('exit')
@@ -116,7 +119,7 @@ def test_nest_embed():
child.sendline("print('true' if get_ipython() is embed1 else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
- child.sendline("print('true' if yap_ipython.get_ipython() is embed1 else 'false')")
+ child.sendline("print('true' if IPython.get_ipython() is embed1 else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
child.sendline('exit')
@@ -125,7 +128,7 @@ def test_nest_embed():
child.sendline("print('true' if get_ipython() is ip0 else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
- child.sendline("print('true' if yap_ipython.get_ipython() is ip0 else 'false')")
+ child.sendline("print('true' if IPython.get_ipython() is ip0 else 'false')")
assert(child.expect(['true\r\n', 'false\r\n']) == 0)
child.expect(ipy_prompt)
child.sendline('exit')
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/tests/test_help.py b/packages/python/yap_kernel/yap_ipython/terminal/tests/test_help.py
index e0ee90f02..ec5bf6f9f 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/tests/test_help.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/tests/test_help.py
@@ -1,9 +1,9 @@
-"""Test help output of various yap_ipython entry points"""
+"""Test help output of various IPython entry points"""
-# Copyright (c) yap_ipython Development Team.
+# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
-import yap_ipython.testing.tools as tt
+import IPython.testing.tools as tt
def test_ipython_help():
diff --git a/packages/python/yap_kernel/yap_ipython/terminal/tests/test_interactivshell.py b/packages/python/yap_kernel/yap_ipython/terminal/tests/test_interactivshell.py
index 37ef622d7..9651a224d 100644
--- a/packages/python/yap_kernel/yap_ipython/terminal/tests/test_interactivshell.py
+++ b/packages/python/yap_kernel/yap_ipython/terminal/tests/test_interactivshell.py
@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-
"""Tests for the TerminalInteractiveShell and related pieces."""
-# Copyright (c) yap_ipython Development Team.
+# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import sys
import unittest
-from yap_ipython.core.inputtransformer import InputTransformer
-from yap_ipython.testing import tools as tt
-from yap_ipython.utils.capture import capture_output
+from IPython.core.inputtransformer import InputTransformer
+from IPython.testing import tools as tt
+from IPython.utils.capture import capture_output
-from yap_ipython.terminal.ptutils import _elide, _adjust_completion_text_based_on_context
+from IPython.terminal.ptutils import _elide, _adjust_completion_text_based_on_context
import nose.tools as nt
class TestElide(unittest.TestCase):
@@ -67,7 +67,7 @@ class mock_input_helper(object):
def mock_input(testfunc):
"""Decorator for tests of the main interact loop.
- Write the test as a generator, yield-ing the input strings, which yap_ipython
+ Write the test as a generator, yield-ing the input strings, which IPython
will see as if they were typed in at the prompt.
"""
def test_method(self):
@@ -96,9 +96,7 @@ class InteractiveShellTestCase(unittest.TestCase):
@mock_input
def test_inputtransformer_syntaxerror(self):
ip = get_ipython()
- transformer = SyntaxErrorTransformer()
- ip.input_splitter.python_line_transforms.append(transformer)
- ip.input_transformer_manager.python_line_transforms.append(transformer)
+ ip.input_transformers_post.append(syntax_error_transformer)
try:
#raise Exception
@@ -112,8 +110,7 @@ class InteractiveShellTestCase(unittest.TestCase):
yield u'print(4*4)'
finally:
- ip.input_splitter.python_line_transforms.remove(transformer)
- ip.input_transformer_manager.python_line_transforms.remove(transformer)
+ ip.input_transformers_post.remove(syntax_error_transformer)
def test_plain_text_only(self):
ip = get_ipython()
@@ -135,7 +132,7 @@ class InteractiveShellTestCase(unittest.TestCase):
class Test2(Test):
def _ipython_display_(self):
- from yap_ipython.display import display
+ from IPython.display import display
display('')
# verify that _ipython_display_ shortcut isn't called
@@ -146,20 +143,17 @@ class InteractiveShellTestCase(unittest.TestCase):
self.assertEqual(data, {'text/plain': repr(obj)})
assert captured.stdout == ''
-
-
-class SyntaxErrorTransformer(InputTransformer):
- def push(self, line):
+def syntax_error_transformer(lines):
+ """Transformer that throws SyntaxError if 'syntaxerror' is in the code."""
+ for line in lines:
pos = line.find('syntaxerror')
if pos >= 0:
e = SyntaxError('input contains "syntaxerror"')
e.text = line
e.offset = pos + 1
raise e
- return line
+ return lines
- def reset(self):
- pass
class TerminalMagicsTestCase(unittest.TestCase):
def test_paste_magics_blankline(self):
diff --git a/packages/yap-lbfgs/lbfgs.pl b/packages/yap-lbfgs/lbfgs.pl
index fe46b3661..1d5e39452 100644
--- a/packages/yap-lbfgs/lbfgs.pl
+++ b/packages/yap-lbfgs/lbfgs.pl
@@ -197,7 +197,7 @@ Prints a table with the current parameters. See the