module.exports = function parserCallbacks() {
const { apgLib } = require('apg-js');
const id = apgLib.ids;
const thisFileName = 'parser-callbacks.js: ';
let msg = '';
const synIniFile = function (result, chars, phraseIndex, data) {
switch (result.state) {
case id.ACTIVE:
data.errors = [];
data.lineNo = 0;
break;
case id.EMPTY:
break;
case id.MATCH:
break;
case id.NOMATCH:
break;
default:
throw new Error('unrecognized state');
}
};
const synBadSectionLine = function (result, chars, phraseIndex, data) {
const funcName = `${thisFileName}synBadSectionLine: `;
switch (result.state) {
case id.ACTIVE:
break;
case id.EMPTY:
break;
case id.MATCH:
msg = `${funcName}line no: ${data.lineNo}: bad section definition:\n`;
msg += apgLib.utils.charsToString(chars, phraseIndex, result.phraseLength);
data.errors.push(msg);
break;
case id.NOMATCH:
break;
default:
throw new Error('unrecognized state');
}
};
const synBadValueLine = function (result, chars, phraseIndex, data) {
const funcName = `${thisFileName}synBadValueLine: `;
switch (result.state) {
case id.ACTIVE:
break;
case id.EMPTY:
break;
case id.MATCH:
msg = `${funcName}line no: ${data.lineNo}: bad key/value definition:\n`;
msg += apgLib.utils.charsToString(chars, phraseIndex, result.phraseLength);
data.errors.push(msg);
break;
case id.NOMATCH:
break;
default:
throw new Error('unrecognized state');
}
};
const synBadBlankLine = function (result, chars, phraseIndex, data) {
const funcName = `${thisFileName}synBadBlankLine: `;
switch (result.state) {
case id.ACTIVE:
break;
case id.EMPTY:
break;
case id.MATCH:
msg = `${funcName}line no: ${data.lineNo}: blank lines only allowed to have white space and comments\n`;
msg += apgLib.utils.charsToString(chars, phraseIndex, result.phraseLength);
data.errors.push(msg);
break;
case id.NOMATCH:
break;
default:
throw new Error('unrecognized state');
}
};
const synLineEnd = function (result, chars, phraseIndex, data) {
switch (result.state) {
case id.ACTIVE:
break;
case id.EMPTY:
break;
case id.MATCH:
data.lineNo += 1;
break;
case id.NOMATCH:
break;
default:
throw new Error('unrecognized state');
}
};