slige-mirror/compiler/parse/token.ts
2025-02-04 15:06:19 +01:00

32 lines
690 B
TypeScript

import { Span } from "../diagnostics.ts";
import { IdentId } from "../ids.ts";
export type Token = {
type: string;
span: Span;
length: number;
identId?: IdentId;
identText?: string;
intValue?: number;
stringValue?: 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;
}
}