Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to parse multiline option in quotes #148

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions src/plugins/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down