slige-mirror/compiler/parser/token.ts
2025-01-27 14:47:13 +01:00

33 lines
731 B
TypeScript

import { Span } from "../diagnostics.ts";
export type Token = TokenData & {
span: Span;
length: number;
};
export type TokenData =
| { type: "ident"; identValue: string }
| { type: "int"; intValue: number }
| { type: "string"; stringValue: string }
| { type: string };
export interface TokenIter {
next(): Token | null;
}
export class SigFilter implements TokenIter {
public constructor(private iter: TokenIter) {}
next(): Token | null {
const token = this.iter.next();
if (token === null) {
return token;
}
if (token?.type === "whitespace" || token?.type === "comment") {
return this.next();
}
return token;
}
}