(function danglingElse() {
const apgJs = require('apg-js');
const near = new (require('./grammars/dangling-else-near'))();
const far = new (require('./grammars/dangling-else-far'))();
const { apgExp } = apgJs;
const { apgLib } = apgJs;
const id = apgLib.ids;
const astStmt = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
if (data.stmtDepth > 0) {
data.output += '{';
}
data.stmtDepth += 1;
} else if (state === id.SEM_POST) {
data.stmtDepth -= 1;
if (data.stmtDepth > 0) {
data.output += '}';
}
}
return ret;
};
const astStmtFar = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
if (data.stmtDepth > 0) {
data.output += '{';
}
} else if (state === id.SEM_POST) {
if (data.stmtDepth > 0) {
data.output += '}';
}
}
return ret;
};
const astIfStmt = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
if (data.stmtDepth > 0) {
data.output += '{';
}
data.stmtDepth += 1;
} else if (state === id.SEM_POST) {
data.stmtDepth -= 1;
if (data.stmtDepth > 0) {
data.output += '}';
}
}
return ret;
};
const astIf = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
data.output += 'if ';
}
return ret;
};
const astThen = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
data.output += ' then ';
}
return ret;
};
const astElse = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
data.output += ' else ';
}
return ret;
};
const astExpr = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
data.output += apgLib.utils.charsToString(chars, phraseIndex, phraseLength);
}
return ret;
};
const astOther = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
data.output += apgLib.utils.charsToString(chars, phraseIndex, phraseLength);
}
return ret;
};
const astOtherStmt = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
data.output += apgLib.utils.charsToString(chars, phraseIndex, phraseLength);
}
return ret;
};
const astOtherElse = function (state, chars, phraseIndex, phraseLength, data) {
const ret = id.SEM_OK;
if (state === id.SEM_PRE) {
data.output += '{';
data.output += apgLib.utils.charsToString(chars, phraseIndex, phraseLength);
data.output += '}';
}
return ret;
};
const replacementFunction = function (result, exp) {
const data = {
stmtDepth: 0,
output: '',
};
exp.ast.translate(data);
return data.output;
};
try {
let exp;
let txt;
const str = 'if E1 then if E2 then S1 else S2';