Commit 5f40012a authored by Franco Pariani's avatar Franco Pariani
Browse files

Adding default functions

parent fe5b4ada
......@@ -8,6 +8,17 @@ let EN_default_sets = [
'R', 'Color', 'Fig', 'A', 'Fig3D'
]
let EN_typed_functions = [
'- :: R -> R', 'round :: R -> R', 'sin :: R -> R', 'cos :: R -> R', 'squareroot :: R -> R',
'rgb :: (R X R X R) -> Color', 'rect :: (R X R) -> Fig', 'circ :: R -> Fig', 'line :: ((R X R) X (R X R)) -> Fig',
'poli :: (R X R)* -> Fig', 'join :: (Fig X Fig) -> Fig', 'color :: (Fig X Color) -> Fig', 'move :: (Fig X (R X R)) -> Fig',
'rotate :: (Fig X R) -> Fig', 'scale :: (Fig X R) -> Fig', 'toFig :: A -> Fig', 'line3D :: ((R X R X R) X (R X R X R)) -> Fig3D',
'sphere :: R -> Fig3D', 'cylinder :: (R X R X R) -> Fig3D', 'cube :: (R X R X R) -> Fig3D', 'ring :: (R X R X R) -> Fig3D',
'join3D :: (Fig3D X Fig3D) -> Fig3D', 'color3D :: (Fig3D X Color) -> Fig3D', 'move3D :: (Fig3D X (R X R X R)) -> Fig3D',
'rotate3D :: (Fig3D X (R X R X R)) -> Fig3D', 'scale3D :: (Fig3D X R) -> Fig3D', 'range :: (R X R X R) -> R*',
'first :: A* -> A', 'rest :: A* -> A*'
]
// Spanish words
let ES_functions = [
......@@ -25,6 +36,9 @@ module.exports = {
EN_functions: function() {
return EN_functions;
},
EN_typed_functions: function() {
return EN_typed_functions;
},
ES_default_sets: function() {
return ES_default_sets;
},
......
......@@ -205,11 +205,14 @@
elt.className = className;
if (cur.render) cur.render(elt, data, cur);
else {
elt.appendChild(ownerDocument.createTextNode("Function typing \n\n"));
var title = ownerDocument.createElement("p");
title.className = "function-definition-title";
title.appendChild(ownerDocument.createTextNode("Function typing \n"));
elt.appendChild(title);
var rexp_name = new RegExp(/(.*\:\:)(.*)/.source, "g");
var m = rexp_name.exec(cur.displayText || getText(cur));
var b_elem = ownerDocument.createElement("b");
b_elem.appendChild(ownerDocument.createTextNode(completion.filename + '.' + m[1]));
b_elem.appendChild(ownerDocument.createTextNode((hintWords.EN_typed_functions().indexOf(m[1] + m[2]) == -1 ? (completion.filename + '.') : "") + m[1]));
elt.appendChild(b_elem);
elt.appendChild(ownerDocument.createTextNode(m[2]));
}
......@@ -409,8 +412,6 @@
if (found.length) return {list: found, from: from, to: to};
});
//CodeMirror.commands.autocomplete = CodeMirror.showHint;
var defaultOptions = {
hint: CodeMirror.hint.auto,
completeSingle: true,
......@@ -422,8 +423,6 @@
customKeys: null,
extraKeys: null
};
//CodeMirror.defineOption("hintOptions", null);
var WORD = /[\w$]+/;
var RANGE = 500;
......@@ -431,7 +430,7 @@
var SET = /set\s+([\w\_\d]+)\s*\=/;
var DOM = /\:\:/;
var FUNS = /([\w\_\d]+)\s+\:\:/;
var COMPLETE_FUNS = /([\w\_\d]+)(\s+\:\:.*)/;
var COMPLETE_FUNS = /([\w\_\d\-]+)(\s+\:\:.*)/;
var FUN = /([\w\_\d]+)\s*\(([\,\w\_\s\d]*)\)\s*\=/;
var ENUMS = /set\s+[\w\_\d]+\s*\=\s*\{(.*?)\}/;
var WRITING_SET = /set\s/;
......@@ -443,7 +442,6 @@
options = parseOptions(this, this.getCursor("start"), options);
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options, filename);
//if (!completion.options.hint) return;
CodeMirror.signal(this, "startFunctionDefinition", this);
completion.update(true);
......@@ -480,29 +478,18 @@
}
}
console.log(list);
// add default functions
var default_functions = hintWords.EN_typed_functions();
for (var i = 0; i < default_functions.length; i++) {
re_funs = new RegExp(COMPLETE_FUNS.source, "g");
var m = re_funs.exec(default_functions[i]);
if (m[1] == curWord) {
list.push(m[1] + m[2]);
}
}
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
}
/*options = parseOptions(this, this.getCursor("start"), options);
var selections = this.listSelections()
if (selections.length > 1) return;
//By default, don't allow completion when something is selected.
//A hint function can have a `supportsSelection` property to
//indicate that it can handle selections.
if (this.somethingSelected()) {
if (!options.hint.supportsSelection) return;
Don't try with cross-line selections
for (var i = 0; i < selections.length; i++)
if (selections[i].head.line != selections[i].anchor.line) return;
}
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options);
if (!completion.options.hint) return;
CodeMirror.signal(this, "startCompletion", this);
completion.update(true);*/
};
// hints
......
......@@ -35,6 +35,10 @@
cursor: default;
}
.function-definition-title {
color: goldenrod;
}
li.CodeMirror-hint-active {
background: rgb(21, 117, 226) !important;
color: white;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment