/* libxmq - Copyright (C) 2026 Fredrik Öhrström (spdx: MIT) */ // Syntax color xmq in an editor: the tokens give the kind and the position of every part // of the text. Here every token that is not whitespace is printed with its kind, an editor // would color the range start..end with the color of the kind. In a web page, // tokenizeHtml gives the same text as colored html. import { tokens, type XMQToken } from "libxmq-lite"; const text = "// A car.\ncar(id = 1) {\n model = 'Volvo'\n note = ('Very ' & 'fast')\n}\n"; /** One line for a token: its position, its kind and its text. */ function describe(t: XMQToken): string { const pos = t.line + ":" + t.column; return pos.padEnd(6) + t.kind.padEnd(31) + JSON.stringify(text.substring(t.start, t.end)); } for (const t of tokens(text, { source: "car.xmq" })) { if (t.kind !== "whitespace") console.log(describe(t)); }