synch
This commit is contained in:
parent
044d455597
commit
e626847e93
@ -3,9 +3,9 @@
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
mod(require(["codemirror/lib/codemirror","codemirror/addon/lint/lint"]));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
define([ "codemirror/lib/codemirror","codemirror/addon/lint/lint" ], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
@ -17,8 +17,7 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
||||
return f(stream, state);
|
||||
}
|
||||
|
||||
var cm_ = null;
|
||||
var document = CodeMirror.doc;
|
||||
var cm_;
|
||||
var curLine;
|
||||
|
||||
/*******************************
|
||||
@ -35,25 +34,9 @@ var document = CodeMirror.doc;
|
||||
parserConfig.groupedIntegers || false; /* tag{k:v, ...} */
|
||||
var unicodeEscape =
|
||||
parserConfig.unicodeEscape || true; /* \uXXXX and \UXXXXXXXX */
|
||||
var multiLineQuoted = parserConfig.multiLineQuotedd || true;
|
||||
var singleQuoted = "atom";
|
||||
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 multiLineQuoted = parserConfig.multiLineQuoted || true; /* "...\n..." */
|
||||
var quoteType = parserConfig.quoteType ||
|
||||
{'"' : "string", "'" : "qatom", "`" : "bqstring"};
|
||||
var singletonVars = new Map();
|
||||
|
||||
var isSingleEscChar = /[abref\\'"nrtsv]/;
|
||||
@ -73,20 +56,21 @@ parserConfig.backQuote === "chars")
|
||||
var exportedMsgs = [];
|
||||
|
||||
function getLine(stream) {
|
||||
if (stream)
|
||||
return stream.lineOracle.line;
|
||||
if (document == null)
|
||||
return 0;
|
||||
return document.getCursor().line;
|
||||
// return cm_.getDoc().getCursor().line;
|
||||
}
|
||||
|
||||
// var ed =
|
||||
// window.document.getElementsByClassName("CodeMirror")[0].CodeMirror.doc.getEditor();
|
||||
|
||||
function rmError(document,stream) {
|
||||
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 = errorFound[i].document.getLineNumber(errorFound[i].line);
|
||||
var elLine = doc.getLineNumber(errorFound[i].line);
|
||||
if (elLine == null || l === elLine) {
|
||||
errorFound.splice(i, 1);
|
||||
i -= 1;
|
||||
@ -97,29 +81,30 @@ if (stream)
|
||||
function mkError(stream, severity, msg) {
|
||||
if (stream.pos == 0)
|
||||
return;
|
||||
var l = getLine(stream);
|
||||
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));
|
||||
console.log( getLine(stream) );
|
||||
errorFound.push({
|
||||
"line" : l,
|
||||
"from" : stream.start,
|
||||
"to" : stream.pos,
|
||||
severity : severity,
|
||||
message : msg,
|
||||
document: document
|
||||
message : msg
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function exportErrors(text) {
|
||||
if (document == null)
|
||||
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 = document.getLineNumber(e.line);
|
||||
var l = doc.getLineNumber(e.line);
|
||||
if (l == null) {
|
||||
errorFound.splice(i, 1);
|
||||
i -= 1;
|
||||
@ -136,27 +121,28 @@ document: document
|
||||
}
|
||||
|
||||
function maybeSingleton( stream, key ) {
|
||||
//console.log(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});
|
||||
singletonVars.set(key, { 'singleton': true,
|
||||
'from': stream.start, to: stream.pos } );
|
||||
|
||||
}
|
||||
//console.log(singletonVars);
|
||||
console.log(singletonVars);
|
||||
}
|
||||
|
||||
function outputSingletonVars(stream) {
|
||||
var key,v;
|
||||
for (var key in singletonVars.keys()) {
|
||||
var v = singletonVars[key];
|
||||
for ( [key,v] of singletonVars.entries()) {
|
||||
if (v!=undefined && v.singleton) {
|
||||
mkError(stream,"warning", key+" singleton variable");
|
||||
}
|
||||
}
|
||||
singletonVars.clear();
|
||||
// console.log("reset");
|
||||
console.log("reset");
|
||||
}
|
||||
|
||||
CodeMirror.registerHelper("lint", "prolog", exportErrors);
|
||||
@ -323,7 +309,6 @@ document: document
|
||||
|
||||
if (ch == "{" && state.lastType == "tag") {
|
||||
state.nesting.push({
|
||||
marker: ch,
|
||||
tag : state.tagName,
|
||||
column : stream.column(),
|
||||
leftCol : state.tagColumn,
|
||||
@ -334,12 +319,8 @@ document: document
|
||||
return ret("dict_open", "bracket");
|
||||
}
|
||||
|
||||
if (ch == "/") {
|
||||
var next = stream.peek();
|
||||
if (next == '*') {
|
||||
if (ch == "/" && stream.eat("*"))
|
||||
return chain(stream, state, plTokenComment);
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == "%") {
|
||||
stream.skipToEnd();
|
||||
@ -351,28 +332,21 @@ if (next == '*') {
|
||||
if (isSoloChar.test(ch)) {
|
||||
switch (ch) {
|
||||
case ")": {
|
||||
if (state.nesting.marker != "(") {
|
||||
mkError(stream, "error", state.nesting.marker + " closed by )");
|
||||
}
|
||||
state.nesting.pop();
|
||||
} break;
|
||||
case "]":
|
||||
if (state.nesting.marker != "[") {
|
||||
mkError(stream, "error", state.nesting.marker + " closed by ]");
|
||||
}
|
||||
|
||||
state.nesting.pop();
|
||||
return ret("list_close", "bracket");
|
||||
case "}": {
|
||||
if (state.nesting.marker != "{") {
|
||||
mkError(stream, "error", state.nesting.marker + " closed by }");
|
||||
}
|
||||
var nest = nesting(state);
|
||||
var type = (nest && nest.tag) ? "dict_close" : "brace_term_close";
|
||||
|
||||
state.nesting.pop();
|
||||
return ret(type, null);
|
||||
} break;
|
||||
case ",": {
|
||||
case ",":
|
||||
{
|
||||
if (stream.eol())
|
||||
state.commaAtEOL = true;
|
||||
nextArg(state);
|
||||
@ -496,13 +470,11 @@ if (state.nesting.marker != "[") {
|
||||
state.nesting = [];
|
||||
}
|
||||
// var start = cm_.getCursor("end");
|
||||
// cm_.setBookmark(start, {"widget" :
|
||||
// document.createTextNode("•")});
|
||||
//cm_.setBookmark(start, {"widget" : document.createTextNode("•")});
|
||||
state.inBody = false;
|
||||
state.goalStart = true;
|
||||
outputSingletonVars(stream);
|
||||
stream.eat(ch);
|
||||
state.headStart = true;
|
||||
return ret("fullstop", "def", atom);
|
||||
|
||||
} else {
|
||||
@ -515,7 +487,7 @@ state.headStart = true;
|
||||
} else if (isNeck.test(atom)) {
|
||||
state.inBody = true;
|
||||
state.goalStart = true;
|
||||
return ret("neck", "def", atom);
|
||||
return ret("neck", "property", atom);
|
||||
} else if (isControl(state) && isControlOp.test(atom)) {
|
||||
state.goalStart = true;
|
||||
return ret("symbol", "meta", atom);
|
||||
@ -523,7 +495,7 @@ state.headStart = true;
|
||||
return ret("symbol", "meta", atom);
|
||||
}
|
||||
}
|
||||
stream.eatWhile(/\w/);
|
||||
stream.eatWhile(/[\w_]/);
|
||||
if (composeGoalWithDots) {
|
||||
while (stream.peek() == ".") {
|
||||
stream.eat('.');
|
||||
@ -532,8 +504,8 @@ state.headStart = true;
|
||||
stream.backUp(1);
|
||||
break;
|
||||
|
||||
} else if (/\w/.test(ch)) {
|
||||
stream.eatWhile(/\w/);
|
||||
} else if (/[\w_]/.test(ch)) {
|
||||
stream.eatWhile(/[\w_]/);
|
||||
} else if (ch == "'") {
|
||||
|
||||
stream.eat();
|
||||
@ -563,19 +535,16 @@ state.headStart = true;
|
||||
maybeSingleton(stream,word);
|
||||
return ret("var", "variable-1", word);
|
||||
}
|
||||
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() == "(") {
|
||||
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);
|
||||
@ -604,6 +573,7 @@ return ret("functor", "atom", word);
|
||||
return ret("atom", "keyword", word);
|
||||
}
|
||||
return ret("atom", "atom", word);
|
||||
|
||||
}
|
||||
|
||||
function plTokenString(quote) {
|
||||
@ -748,7 +718,7 @@ IfTrue
|
||||
|
||||
CodeMirror.defineOption(
|
||||
"prologKeys", true, function(cm, editor, prev) {
|
||||
document = cm.getDoc();
|
||||
cm_ = cm;
|
||||
if (prev && prev != CodeMirror.Init)
|
||||
cm.removeKeyMap("prolog");
|
||||
if (true) {
|
||||
@ -1418,9 +1388,11 @@ IfTrue
|
||||
setArgAlignment(state);
|
||||
return null;
|
||||
}
|
||||
if (state.curLine == null || state.pos == 0)
|
||||
rmError(stream);
|
||||
|
||||
var style = state.tokenize(stream, state);
|
||||
//console.log(state.curToken);
|
||||
console.log(state.curToken);
|
||||
|
||||
if (stream.eol()) {
|
||||
if (stream.pos > 0)
|
||||
|
Reference in New Issue
Block a user