module.exports = function moreSetup(udtcallback, title) {
const nodeUtil = require('node:util');
const inspectOptions = {
showHidden: true,
depth: null,
};
try {
const { apgLib } = require('apg-js');
const grammar = new (require('./more'))();
const parser = new apgLib.parser();
parser.stats = new apgLib.stats();
parser.trace = new apgLib.trace();
parser.callbacks.u_more = udtcallback;
const inputString = 'start more more';
const inputCharacterCodes = apgLib.utils.stringToChars(inputString);
const startRule = 0;
const result = parser.parse(grammar, startRule, inputCharacterCodes);
console.log();
console.log("the parser's results");
console.dir(result, inspectOptions);
if (result.success === false) {
throw new Error(`input string: '${inputString}' : parse failed`);
}
let html = '';
html += parser.stats.toHtml('hits', title);
html += parser.trace.toHtml(title);
return html;
} catch (e) {
let msg = '\nEXCEPTION THROWN: \n';
if (e instanceof Error) {
msg += `${e.name}: ${e.message}`;
} else if (typeof e === 'string') {
msg += e;
} else {
msg += nodeUtil.inspect(e, inspectOptions);
}
process.exitCode = 1;
console.log(msg);
throw e;
}
};