fix(basic.gbapp): FIND now return case insensitive BASIC objects.
This commit is contained in:
parent
81c7fc3972
commit
701bbae2f2
3 changed files with 24 additions and 17 deletions
|
@ -243,6 +243,26 @@ export class GBVMService extends GBService {
|
|||
let col = 1;
|
||||
let index = 1
|
||||
|
||||
// Makes objects in BASIC insensitive.
|
||||
|
||||
const caseInsensitive = (listOrRow) => {
|
||||
const lowercase = (oldKey) => typeof oldKey === 'string' ? oldKey.toLowerCase() : oldKey;
|
||||
|
||||
const createCaseInsensitiveProxy = (obj) => {
|
||||
const propertiesMap = new Map(Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]]));
|
||||
const caseInsensitiveGetHandler = {
|
||||
get: (target, property) => propertiesMap.get(lowercase(property))
|
||||
};
|
||||
return new Proxy(obj, caseInsensitiveGetHandler);
|
||||
};
|
||||
|
||||
if (listOrRow.length) {
|
||||
return listOrRow.map(row => createCaseInsensitiveProxy(row));
|
||||
} else {
|
||||
return createCaseInsensitiveProxy(listOrRow);
|
||||
}
|
||||
};
|
||||
|
||||
// Transfers NLP auto variables into global object.
|
||||
|
||||
for(i in this.variables) {
|
||||
|
|
|
@ -466,11 +466,12 @@ export class KeywordsExpressions {
|
|||
keywords[i++] = [
|
||||
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gim,
|
||||
($0, $1, $2, $3) => {
|
||||
return `${$1} = await sys.find({pid: pid, handle: page, args:[${$2}]})\n
|
||||
`${$1} = caseInsensitive(await sys.find({pid: pid, handle: page, args:[${$2}]}))\n
|
||||
if (!${$1}) {
|
||||
await dk.talk ({pid: pid, text: ${$3}})\n;
|
||||
return -1;
|
||||
}
|
||||
return ${$1};
|
||||
`;
|
||||
}
|
||||
];
|
||||
|
@ -486,7 +487,7 @@ export class KeywordsExpressions {
|
|||
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)/gim,
|
||||
($0, $1, $2, $3) => {
|
||||
return `
|
||||
${$1} = await sys.find({pid: pid, handle: page, args: [${$2}]})`;
|
||||
${$1} = caseInsensitive(await sys.find({pid: pid, handle: page, args: [${$2}]}))`;
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
@ -1153,20 +1153,6 @@ export class SystemKeywords {
|
|||
row['ordinal'] = rowCount;
|
||||
row['line'] = foundIndex + 1;
|
||||
|
||||
const lowercase = (oldKey) => {
|
||||
// Check that it's a string.
|
||||
return typeof oldKey === 'string' ? oldKey.toLowerCase() : oldKey;
|
||||
}
|
||||
const propertiesMap = new Map(
|
||||
Object.keys(row).map(propKey => [lowercase(propKey), row[propKey]])
|
||||
);
|
||||
const caseInsensitiveGetHandler = {
|
||||
get: function(target, property, receiver) {
|
||||
return propertiesMap.get(lowercase(property));
|
||||
}
|
||||
};
|
||||
row = new Proxy(row, caseInsensitiveGetHandler);
|
||||
|
||||
table.push(row);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue