In this case the color
callback function modifies the parsing process by calling a UDT
function to do its work.
In addition to accepting the colors red, white and blue, it uses a UDT
to accept yellow as well.
inputString = 'red,white,blue,yellow';
inputCharacterCodes = apgLib.utils.stringToChars(inputString);
parser.callbacks.color = callbacks.callUdtCallback;
result = parser.parse(grammar, startRule, inputCharacterCodes, data);
console.log();
console.log('the evaluateUdt() callback results');
console.dir(result, inspectOptions);
html += parser.trace.toHtml('ascii', 'evaluateUdt() callback');
html = apgLib.utils.htmlToPage(html, 'colors app');
writeHtml(html, fileName);
} 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;
}
})();