From 0cd2958a9a58c65a185d7e7a94696c4b67278659 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 10 Nov 2021 21:49:33 +0100 Subject: [PATCH] Try to parse multiline option in quotes --- src/plugins/parser.js | 54 ++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/plugins/parser.js b/src/plugins/parser.js index 72ce9b3..ded7a11 100644 --- a/src/plugins/parser.js +++ b/src/plugins/parser.js @@ -70,27 +70,45 @@ class MADRGenerator extends MADRListener { let rawDecisionOutcome = ctx.getText(); if (rawDecisionOutcome.startsWith("Chosen option: ")) { - rawDecisionOutcome = rawDecisionOutcome.split(/, because */); - rawDecisionOutcome[0] = rawDecisionOutcome[0] + let s = rawDecisionOutcome + // Remove 'Chosen option: ' .substring("Chosen option: ".length) - .trim(); // Remove 'Chosen option: ' - let delim = rawDecisionOutcome[0].charAt(0); - let chosenOption = ""; - - if ( - delim === - rawDecisionOutcome[0].charAt(rawDecisionOutcome[0].length - 1) - ) { - chosenOption = rawDecisionOutcome[0].substring( - 1, - rawDecisionOutcome[0].length - 1 - ); + .trim(); + if (s.indexOf(", because") >= 0) { + rawDecisionOutcome = rawDecisionOutcome.split(/, because */); + rawDecisionOutcome[0] = rawDecisionOutcome[0] + .substring("Chosen option: ".length) + .trim(); // Remove 'Chosen option: ' + let delim = rawDecisionOutcome[0].charAt(0); + let chosenOption = ""; + + if ( + delim === + rawDecisionOutcome[0].charAt(rawDecisionOutcome[0].length - 1) + ) { + chosenOption = rawDecisionOutcome[0].substring( + 1, + rawDecisionOutcome[0].length - 1 + ); + } else { + chosenOption = rawDecisionOutcome[0]; + } + let explanation = rawDecisionOutcome.slice(1).join(); + this.adr.decisionOutcome.chosenOption = chosenOption; + this.adr.decisionOutcome.explanation = explanation.trim(); } else { - chosenOption = rawDecisionOutcome[0]; + let firstChar = s.charAt(0); + if (firstChar == "\"") { + s = s.substring(1); + let nextQuote = s.indexOf("\""); + this.adr.decisionOutcome.chosenOption = s.substring(0, nextQuote); + this.adr.decisionOutcome.explanation = s.substring(nextQuote+1).trim(); + } else { + // unknown case + // TODO: we could search the string for a known option from the current position + this.adr.decisionOutcome.explanation = s; + } } - let explanation = rawDecisionOutcome.slice(1).join(); - this.adr.decisionOutcome.chosenOption = chosenOption; - this.adr.decisionOutcome.explanation = explanation.trim(); } else { console.log("Couldn't find chosen option."); }