Commit d8a72b01 authored by Franco Pariani's avatar Franco Pariani
Browse files

Hints for spanish

parent a5e08d36
......@@ -10,49 +10,12 @@ let EN_default_sets = [
// Spanish words
let ES_default_words = [
'red', 'sen', 'raizcuad', 'rgb', 'rect', 'circ', 'linea', 'poli', 'juntar', 'color', 'mover', 'rotar', 'escalar', 'aFig', 'linea3D', 'esfera', 'cilindro', 'cubo', 'anillo', 'juntar3D', 'color3D', 'mover3D', 'rotar3D', 'escalar3D', 'rango', 'primero', 'resto', 'A'
]
var ES_keywords = [
"incluir"
,"conj","en"
,"si", "o"
,"esVacia"
];
let ES_types = [
"Rojo", "Verde", "Azul", "Negro","Blanco", "Gris","Amarillo", "FigVacia", "[]"
,"R", "Fig", "Color"
let ES_functions = [
'-', 'red', 'sen', 'cos', 'raizcuad', 'rgb', 'rect', 'circ', 'linea', 'poli', 'juntar', 'color', 'mover', 'rotar', 'escalar', 'aFig', 'linea3D', 'esfera', 'cilindro', 'cubo', 'anillo', 'juntar3D', 'color3D', 'mover3D', 'rotar3D', 'escalar3D', 'rango', 'primero', 'resto'
]
let ES_functions = [
"abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
"asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
"compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
"cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
"elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
"enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
"flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
"foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
"fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
"getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
"isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
"lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
"mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
"minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
"otherwise", "pi", "pred", "print", "product", "properFraction",
"putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
"readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
"realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
"round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
"sequence", "sequence_", "show", "showChar", "showList", "showParen",
"showString", "shows", "showsPrec", "significand", "signum", "sin",
"sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
"tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
"toRational", "truncate", "uncurry", "undefined", "unlines", "until",
"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
"zip3", "zipWith", "zipWith3"
let ES_default_sets = [
'R', 'Color', 'Fig', 'A', 'Fig3D'
]
module.exports = {
......@@ -62,7 +25,10 @@ module.exports = {
EN_functions: function() {
return EN_functions;
},
ES_words: function() {
return ES_default_words.concat(ES_keywords).concat(ES_types).concat(ES_functions);
}
ES_default_sets: function() {
return ES_default_sets;
},
ES_functions: function() {
return ES_functions;
}
}
......@@ -27,27 +27,160 @@
const hintWords = require('./hint_words');
var anyWord = CodeMirror.hint.anyword;
CodeMirror.hint.anyword = function(cm) {
var cur = cm.getCursor(), token = cm.getTokenAt(cur)
var term, from = CodeMirror.Pos(cur.line, token.start), to = cur
if (token.start < cur.ch && /[\w\-\_]/.test(token.string.charAt(cur.ch - token.start - 1))) {
term = token.string.substr(0, cur.ch - token.start)
} else {
term = ""
from = cur
}
var inner = anyWord(cm, { word: /[\w$\-\_]+/ }) || {from: from, to: to, list: []};
var filtered_words = hintWords.ES_words().filter(w => w.indexOf(term) === 0);
var WORD = /[\w$]+/;
var SET = /conj\s+([\w\_\d]+)\s*\=/;
var DOM = /\:\:/;
var FUNS = /([\w\_\d]+)\s+\:\:/;
var FUN = /([\w\_\d]+)\s*\(([\,\w\_\s\d]*)\)\s*\=/;
var ENUMS = /conj\s+[\w\_\d]+\s*\=\s*\{(.*?)\}/;
var WRITING_SET = /conj\s/;
var WRITING_COMMENT = /\{\-/;
var RANGE = 500;
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
var word = options && options.word || WORD;
var range = options && options.range || RANGE;
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
var end = cur.ch, start = end;
while (start && word.test(curLine.charAt(start - 1))) --start;
var curWord = start != end && curLine.slice(start, end);
var list = options && options.list || [], seen = {};
var re_digits = new RegExp(/^\d+$/, "g");
// not word = 'Enter'
if (options.key == 'Enter'){
var previous_line = editor.getLine(cur.line - 1);
var re_funs = new RegExp(FUNS.source, "g"), match;
if (previous_line && (match = re_funs.exec(previous_line)) && curLine == ""){
var previous_block = "";
for (var i = 0; i < cur.line; i++){
previous_block += editor.getLine(i) + '\n';
}
var next_block = "";
for (var i = cur.line + 1; i <= editor.lastLine(); i++){
next_block += editor.getLine(i) + '\n';
}
var file = previous_block + match[1] + ' ()';
if (next_block != ""){
file = file + '\n' + next_block;
}
var scrollInfo = editor.getScrollInfo();
editor.setValue(file);
editor.setCursor(CodeMirror.Pos(cur.line, match[1].length + 2));
editor.scrollTo(scrollInfo.left, scrollInfo.top);
}
}else{
var previous_part = curLine.slice(0, start);
var re_w_s = new RegExp(WRITING_SET.source, "g");
var re_w_c = new RegExp(WRITING_COMMENT.source, "g");
if (!re_w_s.exec(previous_part) && !re_w_c.exec(previous_part)){
// sets
var re_dom = new RegExp(DOM.source, "g");
if (re_dom.exec(previous_part)){
var re_sets = new RegExp(SET.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_sets.exec(text)) {
if (line == cur.line && m[1] === curWord) continue;
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
for(var i= 0; i < filtered_words.length; i++){
if (inner.list.indexOf(filtered_words[i]) === -1)
inner.list.push(filtered_words[i]);
// add default sets
var default_sets = hintWords.ES_default_sets();
for (var i = 0; i < default_sets.length; i++) {
if ((!curWord || default_sets[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, default_sets[i])) {
seen[default_sets[i]] = true;
list.push(default_sets[i]);
}
}
}else{
// get variables of function
var previous_block = "";
for (var i = 0; i < cur.line; i++){
previous_block += editor.getLine(i) + '\n';
}
previous_block += previous_part;
// no hint in variables
var hint = true;
var re_funs = new RegExp(FUNS.source, "g"), match_dom, last_match_dom;
while (match_dom = re_funs.exec(previous_block)){ last_match_dom = match_dom };
if (last_match_dom){
var re_current_fun = new RegExp(last_match_dom[1] + '\\s*\\($', "g");
hint = !re_current_fun.exec(previous_part);
}
if (hint){
var re_fun = new RegExp(FUN.source, "g"), match, last_match;
while (match = re_fun.exec(previous_block)){ last_match = match };
if (last_match){
var vars = last_match[2].replace(/\s/g,'').split(',');
for (var i = 0; i < vars.length; i++) {
if (!re_digits.exec(vars[i]) && (!curWord || vars[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, vars[i])) {
seen[vars[i]] = true;
list.push(vars[i]);
}
}
// get enums
var re_enums = new RegExp(ENUMS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_enums.exec(text)) {
var enums = m[1].replace(/\s/g,'').split(',');
for (var i = 0; i < enums.length; i++) {
if (!re_digits.exec(enums[i]) && (!curWord || enums[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, enums[i])) {
seen[enums[i]] = true;
list.push(enums[i]);
}
}
}
}
}
// get functions
var re_funs = new RegExp(FUNS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_funs.exec(text)) {
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
// add default functions
var default_functions = hintWords.ES_functions();
for (var i = 0; i < default_functions.length; i++) {
if ((!curWord || default_functions[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, default_functions[i])) {
seen[default_functions[i]] = true;
list.push(default_functions[i]);
}
}
}
}
}
}
}
return inner;
};
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
function normal(source, setState) {
if (source.eatWhile(whiteCharRE)) {
......
......@@ -128,7 +128,7 @@
<label><b>Ctrl+E</b> {{ "i18n.shortcuts.exportFile" | translate }}</label>
<label><b>Ctrl+R</b> {{ "i18n.shortcuts.restartInterpreter" | translate }}</label>
<label><b>Ctrl+G</b> {{ "i18n.shortcuts.saveFile" | translate }}</label>
<label><b>Ctrl+Space</b> {{ "i18n.shortcuts.autocomplete" | translate }}</label>
<label><b>Ctrl+{{ "i18n.shortcuts.space" | translate }}</b> {{ "i18n.shortcuts.autocomplete" | translate }}</label>
</div>
</div>
</ng-template>
......
......@@ -345,6 +345,14 @@ export class MateFunComponent {
}
}
document.onkeydown = KeyPress;
let currentSession = sessionStorage.getItem("currentUser");
let langCode = currentSession ? JSON.parse(currentSession).language : 'es';
if (langCode == 'es'){
this.configCodeMirror.mode.name = "matefun-ES";
}else if (langCode == 'en'){
this.configCodeMirror.mode.name = "matefun-EN";
}
}
ngAfterViewInit() {
......
......@@ -126,7 +126,8 @@
"exportFile" : "Export point file",
"restartInterpreter" : "Restart interpreter",
"saveFile" : "Save File",
"autocomplete" : "Autocomplete"
"autocomplete" : "Autocomplete",
"space" : "Space"
}
}
}
......@@ -126,7 +126,8 @@
"exportFile" : "Exportar archivo puntual",
"restartInterpreter" : "Reiniciar intérprete",
"saveFile" : "Guardar archivo",
"autocomplete" : "Autocompletar"
"autocomplete" : "Autocompletar",
"space" : "Espacio"
}
}
}
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