depends-txt
Version:
A parser module for TeX Live's DEPENDS.txt file format
68 lines • 2.27 kB
JavaScript
export const Token = {
Word: 'Word',
WhiteSpace: 'WhiteSpace',
Comment: 'Comment',
NewLine: 'NewLine',
};
export function* tokenize(input) {
yield* new Tokenizer().tokenize(input);
}
/** @see {@link https://unicode.org/reports/tr18/#Line_Boundaries} */
const NEWLINE = /([\n\v\f\r\u{0085}\p{Zl}\p{Zp}\q{\r\n}])/v;
// eslint-disable-next-line no-control-regex
const WHITESPACE = /([\s\u{001C}-\u{001F}]+)/v;
const COMMENTER = '#';
class Tokenizer {
*tokenize(input) {
this.
this.
for (const [line, newline] of pairs(input.split(NEWLINE))) {
this.
this.
yield* this.
if (newline !== undefined) {
yield this.
}
}
}
*
if (input.length > 0) {
const commentStart = input.indexOf(COMMENTER);
if (commentStart < 0) {
yield* this.
}
else {
yield* this.
yield this.
}
}
}
*
if (input.length > 0) {
for (const [word, ws] of pairs(input.split(WHITESPACE))) {
if (word.length > 0) {
yield this.
}
if (ws !== undefined) {
yield this.
}
}
}
}
const start = { ...this.
this.
this.
const end = { ...this.
return { type, value, position: { start, end } };
}
}
/** @remarks This function modifies the argument directly. */
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
function* pairs(arr) {
while (arr.length > 0) {
yield arr.splice(0, 2);
}
}
//# sourceMappingURL=tokenize.js.map