unified-query
Version:
Composable search input with autocompletion and a rich query-language parser for the Unified Data System
29 lines (28 loc) • 900 B
JavaScript
export function createUtilAnalyzer(keyword) {
return function (seg) {
const errors = [];
for (const tok of seg.tokens) {
// any token
errors.push(invalidTokErr(tok, keyword));
}
seg.errors.push(...errors);
return {
keyword: keyword,
parsed: undefined,
from: seg.from,
to: seg.to,
raw: seg.raw,
};
};
}
/* -------------------------------------------------------------------------- */
/* helpers */
/* -------------------------------------------------------------------------- */
function invalidTokErr(tok, keyword) {
return {
message: `invalid token "${tok.raw}" for @${keyword} (accepts no arguments)`,
token: tok.raw,
from: tok.from,
to: tok.to,
};
}