UNPKG

pddl-workspace

Version:
111 lines 5.97 kB
"use strict"; /* -------------------------------------------------------------------------------------------- * 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.PddlStructure = void 0; const PddlTokenizer_1 = require("./PddlTokenizer"); class PddlStructure { static findPrecedingSection(newSectionName, defineNode, supportedSections) { const precedingSections = PddlStructure.getPrecedingSections(newSectionName, supportedSections); // const followingSections = PddlStructure.getFollowingSections(newSectionName, supportedSections); let previousSectionNode = defineNode; for (let index = 0; index < precedingSections.length; index++) { const node = defineNode.getFirstOpenBracket(precedingSections[index]); if (node) { previousSectionNode = node; } } return previousSectionNode; } /** * Determines which PDDL sections/keywords/structures are allowed at the currentNode * @param siblingReferenceNode node for which siblings are retrieved * @param currentNode node that is used to split the sibling nodes to before/after * @param siblingType to filter the siblings by type * @param allSupportedSections all supported ordered PDDL sections * @param allSupportedStructures additional PDDL structures (e.g. action/durative-action/process/effect/derived) */ static getSupportedSectionsHere(siblingReferenceNode, currentNode, siblingType, allSupportedSections, allSupportedStructures) { const precedingSiblings = siblingReferenceNode.getPrecedingSiblings(siblingType, currentNode); const followingSiblings = siblingReferenceNode.getFollowingSiblings(siblingType, currentNode); let supportedSectionsHere = allSupportedSections; precedingSiblings.forEach(predecessor => { supportedSectionsHere = PddlStructure.getFollowingSections(PddlStructure.stripBracket(predecessor), supportedSectionsHere); }); followingSiblings.reverse().forEach(successor => { supportedSectionsHere = PddlStructure.getPrecedingSections(PddlStructure.stripBracket(successor), supportedSectionsHere); }); if (followingSiblings.every(successor => allSupportedStructures.find(sectionName => sectionName === PddlStructure.stripBracket(successor)))) { supportedSectionsHere = supportedSectionsHere.concat(allSupportedStructures); } if (precedingSiblings.some(successor => allSupportedStructures.find(sectionName => sectionName === PddlStructure.stripBracket(successor)))) { // only suggest structures supportedSectionsHere = allSupportedStructures; } return supportedSectionsHere; } static stripBracket(node) { return node.getToken().tokenText.replace('(', '').trim(); } static getPrecedingSections(newSectionName, supportedSections) { const indexOfNewSection = supportedSections.indexOf(newSectionName); if (indexOfNewSection === -1) { return supportedSections; } return supportedSections.slice(0, indexOfNewSection); } static getFollowingSections(newSectionName, supportedSections) { const indexOfNewSection = supportedSections.indexOf(newSectionName); if (indexOfNewSection === -1) { return supportedSections; } return supportedSections.slice(indexOfNewSection + 1); } static getPrecedingKeywordOrSelf(node) { const parent = node.getParent(); if (parent && parent.isType(PddlTokenizer_1.PddlTokenType.Keyword)) { return parent; } else { return node; } } } exports.PddlStructure = PddlStructure; /* DOMAIN KEYWORDS */ PddlStructure.DOMAIN = 'domain'; PddlStructure.REQUIREMENTS = ':requirements'; PddlStructure.TYPES = ':types'; PddlStructure.CONSTANTS = ':constants'; PddlStructure.PREDICATES = ':predicates'; PddlStructure.FUNCTIONS = ':functions'; PddlStructure.CONSTRAINTS = ':constraints'; PddlStructure.PDDL_DOMAIN_SECTIONS = [PddlStructure.DOMAIN, PddlStructure.REQUIREMENTS, PddlStructure.TYPES, PddlStructure.CONSTANTS, PddlStructure.PREDICATES, PddlStructure.FUNCTIONS, PddlStructure.CONSTRAINTS]; /* DOMAIN STRUCTURES */ PddlStructure.DERIVED = ':derived'; PddlStructure.ACTION = ':action'; PddlStructure.DURATIVE_ACTION = ':durative-action'; PddlStructure.JOB = ":job"; PddlStructure.PROCESS = ':process'; PddlStructure.EVENT = ':event'; PddlStructure.PDDL_DOMAIN_STRUCTURES = [PddlStructure.DERIVED, PddlStructure.ACTION, PddlStructure.DURATIVE_ACTION, PddlStructure.PROCESS, PddlStructure.EVENT, PddlStructure.JOB]; /* PROBLEM KEYWORDS */ PddlStructure.PROBLEM = 'problem'; PddlStructure.PROBLEM_DOMAIN = ':domain'; PddlStructure.OBJECTS = ':objects'; PddlStructure.INIT = ':init'; PddlStructure.GOAL = ':goal'; PddlStructure.METRIC = ':metric'; PddlStructure.PDDL_PROBLEM_SECTIONS = [PddlStructure.PROBLEM, PddlStructure.PROBLEM_DOMAIN, PddlStructure.REQUIREMENTS, PddlStructure.OBJECTS, PddlStructure.INIT, PddlStructure.GOAL, PddlStructure.CONSTRAINTS, PddlStructure.METRIC]; /* ACTION KEYWORDS */ PddlStructure.PARAMETERS = ':parameters'; PddlStructure.PRECONDITION = ':precondition'; PddlStructure.EFFECT = ':effect'; PddlStructure.PDDL_ACTION_SECTIONS = [PddlStructure.PARAMETERS, PddlStructure.PRECONDITION, PddlStructure.EFFECT]; /* DURATIVE-ACTION KEYWORDS */ PddlStructure.DURATION = ':duration'; PddlStructure.CONDITION = ':condition'; PddlStructure.PDDL_DURATIVE_ACTION_SECTIONS = [PddlStructure.PARAMETERS, PddlStructure.DURATION, PddlStructure.CONDITION, PddlStructure.EFFECT]; //# sourceMappingURL=PddlStructure.js.map