yapi
This commit is contained in:
parent
1797e5132e
commit
18e437f038
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
(function(mod) {
|
(function(mod) {
|
||||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
mod(require("codemirror/lib/codemirror"));
|
mod(require([ "codemirror/lib/codemirror", "codemirror/addon/lint/lint" ]));
|
||||||
else if (typeof define == "function" && define.amd) // AMD
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
define([ "codemirror/lib/codemirror" ], mod);
|
define([ "codemirror/lib/codemirror", "codemirror/addon/lint/lint" ], mod);
|
||||||
else // Plain browser env
|
else // Plain browser env
|
||||||
mod(CodeMirror);
|
mod(CodeMirror);
|
||||||
})(function(CodeMirror) {
|
})(function(CodeMirror) {
|
||||||
@ -34,9 +34,26 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
parserConfig.groupedIntegers || false; /* tag{k:v, ...} */
|
parserConfig.groupedIntegers || false; /* tag{k:v, ...} */
|
||||||
var unicodeEscape =
|
var unicodeEscape =
|
||||||
parserConfig.unicodeEscape || true; /* \uXXXX and \UXXXXXXXX */
|
parserConfig.unicodeEscape || true; /* \uXXXX and \UXXXXXXXX */
|
||||||
var multiLineQuoted = parserConfig.multiLineQuoted || true; /* "...\n..." */
|
var multiLineQuoted = parserConfig.multiLineQuotedd || true;
|
||||||
var quoteType = parserConfig.quoteType ||
|
var singleQuoted = "atom";
|
||||||
{'"' : "string", "'" : "qatom", "`" : "bqstring"};
|
if (parserConfig.singleQuote === "string" ||
|
||||||
|
parserConfig.singleQuote === "codes" ||
|
||||||
|
parserConfig.singleQuote === "chars")
|
||||||
|
singleQuoted = parserConfig.singleQuote;
|
||||||
|
var doubleQuoted = "string";
|
||||||
|
if (parserConfig.doubleQuote === "atom" ||
|
||||||
|
parserConfig.doubleQuote === "codes" ||
|
||||||
|
parserConfig.doubleQuote === "chars")
|
||||||
|
doubleQuoted = parserConfig.doubleQuote;
|
||||||
|
var backQuoted = "atom";
|
||||||
|
if (parserConfig.backQuote === "string" ||
|
||||||
|
parserConfig.backQuote === "codes" ||
|
||||||
|
parserConfig.backQuote === "chars")
|
||||||
|
backQuoted = parserConfig.backQuote;
|
||||||
|
|
||||||
|
var quoteType = {"\"" : doubleQuoted, "`" : backQuoted, "'" : singleQuoted};
|
||||||
|
|
||||||
|
var singletonVars = new Map();
|
||||||
|
|
||||||
var isSingleEscChar = /[abref\\'"nrtsv]/;
|
var isSingleEscChar = /[abref\\'"nrtsv]/;
|
||||||
var isOctalDigit = /[0-7]/;
|
var isOctalDigit = /[0-7]/;
|
||||||
@ -64,7 +81,7 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
|
|
||||||
function rmError(stream) {
|
function rmError(stream) {
|
||||||
if (cm_ == null)
|
if (cm_ == null)
|
||||||
return;
|
return;
|
||||||
var doc = cm_.getDoc();
|
var doc = cm_.getDoc();
|
||||||
var l = getLine(stream);
|
var l = getLine(stream);
|
||||||
// stream.lineOracle.line;
|
// stream.lineOracle.line;
|
||||||
@ -73,7 +90,6 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (elLine == null || l === elLine) {
|
if (elLine == null || l === elLine) {
|
||||||
errorFound.splice(i, 1);
|
errorFound.splice(i, 1);
|
||||||
i -= 1;
|
i -= 1;
|
||||||
console.log(-elLine);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,8 +101,8 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
var found = errorFound.find(function(
|
var found = errorFound.find(function(
|
||||||
element) { return element.line === l && element.to == stream.pos; });
|
element) { return element.line === l && element.to == stream.pos; });
|
||||||
if (!found) {
|
if (!found) {
|
||||||
console.log( getLine(stream) );
|
//console.log(getLine(stream));
|
||||||
errorFound.push({
|
errorFound.push({
|
||||||
"line" : l,
|
"line" : l,
|
||||||
"from" : stream.start,
|
"from" : stream.start,
|
||||||
"to" : stream.pos,
|
"to" : stream.pos,
|
||||||
@ -120,6 +136,30 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
return exportedMsgs;
|
return exportedMsgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeSingleton(stream, key) {
|
||||||
|
//console.log(key);
|
||||||
|
var v = singletonVars.get(key);
|
||||||
|
if (v != undefined) {
|
||||||
|
v.singleton = false;
|
||||||
|
} else {
|
||||||
|
singletonVars.set(
|
||||||
|
key, {'singleton' : true, 'from' : stream.start, to : stream.pos});
|
||||||
|
}
|
||||||
|
//console.log(singletonVars);
|
||||||
|
}
|
||||||
|
|
||||||
|
function outputSingletonVars(stream) {
|
||||||
|
var key, v;
|
||||||
|
for (var key in singletonVars.keys()) {
|
||||||
|
var v = singletonVars[key];
|
||||||
|
if (v != undefined && v.singleton) {
|
||||||
|
mkError(stream, "warning", key + " singleton variable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
singletonVars.clear();
|
||||||
|
// console.log("reset");
|
||||||
|
}
|
||||||
|
|
||||||
CodeMirror.registerHelper("lint", "prolog", exportErrors);
|
CodeMirror.registerHelper("lint", "prolog", exportErrors);
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
@ -260,6 +300,8 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
function plTokenBase(stream, state) {
|
function plTokenBase(stream, state) {
|
||||||
var ch = stream.next();
|
var ch = stream.next();
|
||||||
|
|
||||||
|
state.curToken = ch;
|
||||||
|
|
||||||
if (ch == "(") {
|
if (ch == "(") {
|
||||||
if (state.lastType == "functor") {
|
if (state.lastType == "functor") {
|
||||||
state.nesting.push({
|
state.nesting.push({
|
||||||
@ -323,22 +365,38 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
state.commaAtEOL = true;
|
state.commaAtEOL = true;
|
||||||
nextArg(state);
|
nextArg(state);
|
||||||
/*FALLTHROUGH*/
|
/*FALLTHROUGH*/
|
||||||
|
if (!state.commaAtEOL)
|
||||||
|
stream.eatSpace();
|
||||||
|
var nch = stream.peek();
|
||||||
|
if (nch == ';' || nch == ',') {
|
||||||
|
mkError(stream, "error", "\",\" followed by " + stream.peek());
|
||||||
|
return ret("solo", "error", ",");
|
||||||
|
}
|
||||||
if (isControl(state)) {
|
if (isControl(state)) {
|
||||||
if (!state.commaAtEOL)
|
if ("[" != ch) {
|
||||||
stream.eatSpace();
|
|
||||||
if (!stream.peek("[")) {
|
|
||||||
if (state.inBody) {
|
if (state.inBody) {
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
} else {
|
} else {
|
||||||
|
mkError(stream, "error", "\",\" followed by " + stream.peek());
|
||||||
return ret("solo", "error", ",");
|
return ret("solo", "error", ",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ret('solo', 'tag', ",");
|
||||||
} break;
|
} break;
|
||||||
case ";":
|
case ";":
|
||||||
|
if (!state.commaAtEOL)
|
||||||
|
stream.eatSpace();
|
||||||
|
ch = stream.peek();
|
||||||
|
if (ch == ';' || ch == ',') {
|
||||||
|
mkError(stream, "error", "\",\" followed by " + stream.peek());
|
||||||
|
return ret("solo", "error", ";");
|
||||||
|
}
|
||||||
if (isControl(state)) {
|
if (isControl(state)) {
|
||||||
if (!state.inBody)
|
if (!state.inBody) {
|
||||||
|
mkError(stream, "error", "unexpected ;");
|
||||||
return ret("solo", "error", ";");
|
return ret("solo", "error", ";");
|
||||||
|
}
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -399,8 +457,10 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (stream.eat(/'/)) { /* 0' */
|
if (stream.eat(/'/)) { /* 0' */
|
||||||
var next = stream.next();
|
var next = stream.next();
|
||||||
if (next == "\\") {
|
if (next == "\\") {
|
||||||
if (!readEsc(stream))
|
if (!readEsc(stream)) {
|
||||||
|
mkError(stream, "error", "bad escape");
|
||||||
return ret("error", "error");
|
return ret("error", "error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret("code", "number");
|
return ret("code", "number");
|
||||||
}
|
}
|
||||||
@ -423,16 +483,20 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
mkError(stream, "error", "Clause over before closing all brackets");
|
mkError(stream, "error", "Clause over before closing all brackets");
|
||||||
state.nesting = [];
|
state.nesting = [];
|
||||||
}
|
}
|
||||||
// var start = cm_.getCursor("end");
|
// var start = cm_.getCursor("end");
|
||||||
//cm_.setBookmark(start, {"widget" : document.createTextNode("•")});
|
// cm_.setBookmark(start, {"widget" :
|
||||||
|
// document.createTextNode("•")});
|
||||||
state.inBody = false;
|
state.inBody = false;
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
|
outputSingletonVars(stream);
|
||||||
stream.eat(ch);
|
stream.eat(ch);
|
||||||
return ret("fullstop", "def", atom);
|
return ret("fullstop", "def", atom);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (atom === ":-" && state.headStart) {
|
if (atom === ":-" && state.headStart) {
|
||||||
|
state.headStart = false;
|
||||||
|
state.inBody = true;
|
||||||
|
state.goalStart = true;
|
||||||
return ret("directive", "attribute", atom);
|
return ret("directive", "attribute", atom);
|
||||||
|
|
||||||
} else if (isNeck.test(atom)) {
|
} else if (isNeck.test(atom)) {
|
||||||
@ -463,12 +527,14 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
|
|
||||||
stream.eatWhile(/[\w_]/);
|
stream.eatWhile(/[\w_]/);
|
||||||
if (ch == ".") {
|
if (ch == ".") {
|
||||||
|
mkError(stream, "error", "bad dotted name");
|
||||||
return ret("atom", "error");
|
return ret("atom", "error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var word = stream.current();
|
var word = stream.current();
|
||||||
|
state.curToken = word;
|
||||||
var extra = "";
|
var extra = "";
|
||||||
if (stream.peek() == "{" && dicts) {
|
if (stream.peek() == "{" && dicts) {
|
||||||
state.tagName = word; /* tmp state extension */
|
state.tagName = word; /* tmp state extension */
|
||||||
@ -478,14 +544,13 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (word.length == 1) {
|
if (word.length == 1) {
|
||||||
return ret("var", "variable-2", word);
|
return ret("var", "variable-2", word);
|
||||||
} else {
|
} else {
|
||||||
var sec = word.charAt(1);
|
return ret("var", "variable-2", word);
|
||||||
if (sec == sec.toUpperCase())
|
|
||||||
return ret("var", "variable-2", word);
|
|
||||||
}
|
}
|
||||||
return ret("var", "variable-2", word);
|
} else if (ch.match(/[A-Z]/)) {
|
||||||
} else if (ch == ch.toUpperCase()) {
|
maybeSingleton(stream, word);
|
||||||
return ret("var", "variable-1", word);
|
return ret("var", "variable-1", word);
|
||||||
} else if (stream.peek() == "(") {
|
}
|
||||||
|
if (stream.peek() == "(") {
|
||||||
state.functorName = word; /* tmp state extension */
|
state.functorName = word; /* tmp state extension */
|
||||||
state.functorColumn = stream.column();
|
state.functorColumn = stream.column();
|
||||||
if (state.headStart) {
|
if (state.headStart) {
|
||||||
@ -519,8 +584,9 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (builtins[word] && isControl(state))
|
if (builtins[word] && isControl(state))
|
||||||
return ret("functor", "keyword", w);
|
return ret("functor", "keyword", w);
|
||||||
return ret("functor", "atom", w);
|
return ret("functor", "atom", w);
|
||||||
} else if (builtins[word] && isControl(state))
|
} else if (builtins[word] && isControl(state)) {
|
||||||
return ret("atom", "keyword", word);
|
return ret("atom", "keyword", word);
|
||||||
|
}
|
||||||
return ret("atom", "atom", word);
|
return ret("atom", "atom", word);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1340,6 +1406,7 @@ IfTrue
|
|||||||
rmError(stream);
|
rmError(stream);
|
||||||
|
|
||||||
var style = state.tokenize(stream, state);
|
var style = state.tokenize(stream, state);
|
||||||
|
//console.log(state.curToken);
|
||||||
|
|
||||||
if (stream.eol()) {
|
if (stream.eol()) {
|
||||||
if (stream.pos > 0)
|
if (stream.pos > 0)
|
||||||
@ -1386,7 +1453,7 @@ IfTrue
|
|||||||
blockCommentEnd : "*/",
|
blockCommentEnd : "*/",
|
||||||
blockCommentContinue : " * ",
|
blockCommentContinue : " * ",
|
||||||
comment : "%",
|
comment : "%",
|
||||||
fold : "indent"
|
matchBrackets : true
|
||||||
};
|
};
|
||||||
return external;
|
return external;
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
The Problog-I Language and Learning System {#problog}
|
@defgroup problog The Problog-I Language and Learning System
|
||||||
=====================================
|
|
||||||
|
|
||||||
[TOC]
|
@{
|
||||||
|
|
||||||
This document is intended as a user guide for the users of ProbLog-I.
|
This document is intended as a user guide for the users of ProbLog-I.
|
||||||
ProbLog is a probabilistic Prolog, a probabilistic logic programming
|
ProbLog is a probabilistic Prolog, a probabilistic logic programming
|
||||||
language, which is integrated in YAP-Prolog. Most of the work in ProbLog is now based on(Prolog-II), but we still maintain ProbLog-I in order to experiment with close integration of probabilistic nd logical systems.
|
language, which is integrated in YAP-Prolog. Most of the work in ProbLog is now based on(Prolog-II), but we still maintain ProbLog-I in order to experiment with close integration of probabilistic nd logical systems.
|
||||||
|
|
||||||
|
[TOC]
|
||||||
|
|
||||||
@section InstallingProbLog Installing ProbLog
|
@section InstallingProbLog Installing ProbLog
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @file python.c
|
||||||
|
*
|
||||||
|
* @brief data structures and init for Py4YAP library
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup PY4YAP
|
||||||
|
* @ingroup python
|
||||||
|
* @brief make Python talk to YAP
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
#include "py4yap.h"
|
#include "py4yap.h"
|
||||||
#include <VFS.h>
|
#include <VFS.h>
|
||||||
@ -127,3 +139,5 @@ X_API bool do_init_python(void) {
|
|||||||
// python_output();
|
// python_output();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @}
|
||||||
|
@ -88,11 +88,11 @@ blank(Text) :-
|
|||||||
|
|
||||||
|
|
||||||
streams(false) :-
|
streams(false) :-
|
||||||
close(user_input),
|
%close(user_input),
|
||||||
close(user_output),
|
close(user_output),
|
||||||
close(user_error).
|
close(user_error).
|
||||||
streams( true) :-
|
streams( true) :-
|
||||||
open('/python/input', read, _Input, [alias(user_input),bom(false),script(false)]),
|
%open('/python/input', read, _Input, [alias(user_input),bom(false),script(false)]),
|
||||||
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
|
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
|
||||||
open('/python/sys.stderr', append, _Error, [alias(user_error)]).
|
open('/python/sys.stderr', append, _Error, [alias(user_error)]).
|
||||||
|
|
||||||
|
@ -704,7 +704,6 @@ class YAPRun(InteractiveShell):
|
|||||||
else:
|
else:
|
||||||
linec = True
|
linec = True
|
||||||
rcell = cell[1:].strip()
|
rcell = cell[1:].strip()
|
||||||
print(cell)
|
|
||||||
try:
|
try:
|
||||||
[magic,cell] = rcell.split(maxsplit = 1, sep = '\n')
|
[magic,cell] = rcell.split(maxsplit = 1, sep = '\n')
|
||||||
except:
|
except:
|
||||||
|
Reference in New Issue
Block a user