UNPKG

pddl-workspace

Version:
55 lines 2.51 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.MetricParser = void 0; const PddlTokenizer_1 = require("./PddlTokenizer"); const DocumentPositionResolver_1 = require("../DocumentPositionResolver"); const DerivedVariableParser_1 = require("./DerivedVariableParser"); const ProblemInfo_1 = require("../ProblemInfo"); const NumericExpressionParser_1 = require("./NumericExpressionParser"); /** * Parses `(:metric ...)` blocks. */ class MetricParser { constructor(metricNode, positionResolver) { /*(:metric minimize|maximize <expression> )*/ let direction; let expression; const children = metricNode.getNonWhitespaceNonCommentChildren(); children.forEach(node => { const match = node.getText().match(/(minimize|maximize)/i); if (match === null || match === void 0 ? void 0 : match.length) { switch (match[1]) { case "minimize": direction = ProblemInfo_1.MetricDirection.MINIMIZE; break; case "maximize": direction = ProblemInfo_1.MetricDirection.MAXIMIZE; break; } } else if ((0, PddlTokenizer_1.isOpenBracket)(node.getToken())) { expression = new NumericExpressionParser_1.NumericExpressionParser(node).getExpression(); } }); if (direction !== undefined && expression !== undefined) { const location = new DocumentPositionResolver_1.PddlRange({ start: positionResolver.resolveToPosition(metricNode.getStart()), end: positionResolver.resolveToPosition(metricNode.getEnd()) }); const documentation = DerivedVariableParser_1.DerivedVariablesParser.getDocumentationAbove(metricNode); this.metric = new ProblemInfo_1.Metric(direction, expression, location, documentation); } } getMetric() { return this.metric; } } exports.MetricParser = MetricParser; //# sourceMappingURL=MetricParser.js.map