new(basic.gblib): New TOLIST, APPEND, SORT TO keyword..

This commit is contained in:
Rodrigo Rodriguez 2021-08-03 16:24:59 -03:00
parent b6962f058b
commit dfa2d51e37
3 changed files with 54 additions and 7 deletions

View file

@ -133,6 +133,16 @@ export class DialogKeywords {
return date.toLocaleString('en-us', { weekday: 'short' });
}
/**
* Returns specified list member separated by comma.
*
* @example TALK TOLIST (array, member)
*
*/
public toList(array, member) {
return Array.prototype.map.call(array, (item)=> { return item[member]; }).join(",");
}
/**
* Returns the specified time in format hh:dd.
*

View file

@ -161,10 +161,11 @@ export class GBVMService extends GBService {
username = this.userName(step);
mobile = this.userMobile(step);
from = mobile;
ubound = function(list){return list.length};
isarray = function(list){return Array.isArray(list) };
ubound = function(array){return array.length};
isarray = function(array){return Array.isArray(array) };
weekday = this.getWeekFromDate;
hour = this.getHourFromDate;
tolist = this.toList;
headers = {};
${code}
@ -240,6 +241,14 @@ export class GBVMService extends GBService {
return `${$1} = sys().find(${$2})\n`;
});
code = code.replace(/(\w)\s*\=\s*append\s*(.*)/gi, ($0, $1, $2, $3) => {
return `${$1} = sys().append(${$2})\n`;
});
code = code.replace(/(\w+)\s*\=\s*sort\s*(\w+)\s*by(.*)/gi, ($0, $1, $2, $3) => {
return `${$1} = sys().sortBy(${$2}, ${$3})\n`;
});
code = code.replace(/(wait)\s*(\d+)/gi, ($0, $1, $2) => {
return `sys().wait(${$2})`;
});
@ -429,6 +438,7 @@ export class GBVMService extends GBService {
parsedCode = parsedCode.replace(/(\btoday\b)(?=(?:[^"]|"[^"]*")*$)/gi, 'await this.getToday(step)');
parsedCode = parsedCode.replace(/(\bweekday\b)(?=(?:[^"]|"[^"]*")*$)/gi, 'weekday');
parsedCode = parsedCode.replace(/(\bhour\b)(?=(?:[^"]|"[^"]*")*$)/gi, 'hour');
parsedCode = parsedCode.replace(/(\btolist\b)(?=(?:[^"]|"[^"]*")*$)/gi, 'tolist');
parsedCode = beautify(parsedCode, { indent_size: 2, space_in_empty_paren: true });
fs.writeFileSync(jsfile, parsedCode);
@ -491,6 +501,7 @@ export class GBVMService extends GBService {
code = code.replace('ubound = async', 'ubound ='); // TODO: Improve this.
code = code.replace('hour = await', 'hour ='); // TODO: Improve this.
code = code.replace('weekday = await', 'weekday ='); // TODO: Improve this.
code = code.replace('tolist = await', 'tolist ='); // TODO: Improve this.
code = code.replace('isArray = async', 'isArray ='); // TODO: Waiting for a compiler.
return code;

View file

@ -74,6 +74,17 @@ export class SystemKeywords {
this.dk = dk;
}
/**
* Retrives the content of a given URL.
*/
public async append(...args) {
return [].concat(...args);
}
public async sortBy(array, memberName) {
return array ? [].sort(p => p[memberName]) : null;
}
/**
* Retrives the content of a given URL.
*/
@ -316,6 +327,15 @@ export class SystemKeywords {
operator: op.toString().replace(/\//g, '').replace(/\\/g, '').replace(/\b/g, ''),
value: parts[1].trim()
};
// Swaps values and names in case of IN operators.
if (filter.operator === 'not in' || filter.operator === 'in') {
const columnName = filter.columnName;
filter.columnName = filter.value;
filter.value = columnName;
}
done = true;
}
});
@ -371,8 +391,7 @@ export class SystemKeywords {
let table = [];
table.push({ 'this is a hidden base 0': 'element' });
let foundIndex = 0;
let foundIndex = 1;
// Fills the row variable.
@ -390,6 +409,16 @@ export class SystemKeywords {
filterAcceptCount++;
}
break;
case 'not in':
if (filter.value.indexOf(result)) {
filterAcceptCount++;
}
break;
case 'in':
if (!filter.value.indexOf(result)) {
filterAcceptCount++;
}
break;
}
break;
case 'number':
@ -451,9 +480,6 @@ export class SystemKeywords {
}
}
/**
* Creates a folder in the bot instance drive.
*