UNPKG

unified-query

Version:

Composable search input with autocompletion and a rich query-language parser for the Unified Data System

37 lines (36 loc) 969 B
/** * Semantic analyser for `@time`. * Accepts only tokens of kind `"time"`. Any other token is reported * as a semantic error (“invalid token for @time”). */ export function analyzeTime(seg) { const times = []; const errors = []; for (const tok of seg.tokens) { if (tok.kind === 'time') { if (tok.op) { times.push({ op: tok.op, ...tok.value }); } else { times.push(tok.value); } continue; } // anything else -> semantic error errors.push({ message: `invalid token "${tok.raw}" for @time`, token: tok.raw, from: tok.from, to: tok.to, }); } // expose semantic errors for the CodeMirror linter seg.errors.push(...errors); return { keyword: 'time', parsed: times, from: seg.from, to: seg.to, raw: seg.raw, }; }