UNPKG

pddl-workspace

Version:
64 lines 3.13 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.DerivedVariablesParser = void 0; const language_1 = require("../language"); const PddlTokenizer_1 = require("./PddlTokenizer"); const DocumentPositionResolver_1 = require("../DocumentPositionResolver"); const VariablesParser_1 = require("./VariablesParser"); /** Parses derived predicates and functions. E.g.: * `(:derived (<p> ?x ?y - type) <condition> )` */ class DerivedVariablesParser { constructor(derivedNode, positionResolver) { const children = derivedNode.getNonWhitespaceChildren() .filter(c => c.getToken().type !== PddlTokenizer_1.PddlTokenType.Comment); if (children.length !== 2) { return; } const fullNameNode = children[0]; if (fullNameNode.getToken().type !== PddlTokenizer_1.PddlTokenType.OpenBracket) { return; } const fullName = fullNameNode.getNestedText(); const parameters = (0, VariablesParser_1.parseParameters)(fullName); this.conditionNode = children[1]; this.variable = new language_1.Variable(fullName, parameters); const location = new DocumentPositionResolver_1.PddlRange({ start: positionResolver.resolveToPosition(derivedNode.getStart()), end: positionResolver.resolveToPosition(derivedNode.getEnd()) }); this.variable.setLocation(location); this.variable.setDocumentation(DerivedVariablesParser.getDocumentationAbove(derivedNode)); } static getDocumentationAbove(derivedNode) { var _a, _b; const siblingNodes = (_b = (_a = derivedNode.getParent()) === null || _a === void 0 ? void 0 : _a.getChildren()) !== null && _b !== void 0 ? _b : []; const indexOfThisNode = siblingNodes.indexOf(derivedNode); // iterate backwards through the siblings and find first comment line // the previous sibling should be a white space const whiteSpaceIndex = indexOfThisNode - 1; if (whiteSpaceIndex < 0 || siblingNodes[whiteSpaceIndex].getToken().type !== PddlTokenizer_1.PddlTokenType.Whitespace) { return []; } const commentIndex = whiteSpaceIndex - 1; if (commentIndex < 0 || siblingNodes[commentIndex].getToken().type !== PddlTokenizer_1.PddlTokenType.Comment) { return []; } else { const documentation = siblingNodes[commentIndex].getText().substr(1).trim(); // strip the semicolon return [documentation]; } } getVariable() { return this.variable; } getConditionNode() { return this.conditionNode; } } exports.DerivedVariablesParser = DerivedVariablesParser; //# sourceMappingURL=DerivedVariableParser.js.map