ai-planning-val
Version:
Javascript/typescript wrapper for VAL (AI Planning plan validation and evaluation tools from KCL Planning department and the planning community around the ICAPS conference).
56 lines • 2.33 kB
JavaScript
/* --------------------------------------------------------------------------------------------
* Copyright (c) Jan Dolejsi. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProblemPattern = void 0;
const pddl_workspace_1 = require("pddl-workspace");
class ProblemPattern {
/**
* Constructs a problem pattern
*
* @param patternWithMatchGroupOrder pattern in the form /pattern/flags/order,
* where the order part is a comma separated list of order of the capturing groups inside the pattern filename,severity,line,column,message (as a 1-based index)
* @param fileNames names of files parsed
*/
constructor(patternWithMatchGroupOrder, fileNames) {
const fileNamesJoint = fileNames.join('|')
// escape all backslashes
.split('\\').join("\\\\")
// escape all dots
.split('.').join("\\.");
const [patternOrig, flags, order] = patternWithMatchGroupOrder.split('/').slice(1);
const pattern = patternOrig.replace('$(filePaths)', fileNamesJoint);
this.regEx = new RegExp(pattern, flags);
this.indexMap = order.split(',').map(str => parseInt(str));
}
getFilePath(match) {
return match[this.mapIndex(0)];
}
getSeverity(match) {
return match[this.mapIndex(1)].toLowerCase();
}
getLine(match) {
return parseInt(match[this.mapIndex(2)]) - 1;
}
getCharacter(match) {
const index = this.mapIndex(3);
return index ? parseInt(match[index]) - 1 : undefined;
}
getMessage(match) {
return match[this.mapIndex(4)];
}
getRange(match) {
const line = this.getLine(match);
const character = this.getCharacter(match);
return character !== undefined ?
pddl_workspace_1.PddlRange.createSingleCharacterRange({ line, character }) :
pddl_workspace_1.PddlRange.createFullLineRange(line);
}
mapIndex(i) {
return this.indexMap[i];
}
}
exports.ProblemPattern = ProblemPattern;
//# sourceMappingURL=ProblemPattern.js.map