nandgame-compiler/token.ts
SimonFJ20 b2b1533ee6 init
2023-04-27 02:32:06 +02:00

77 lines
1.3 KiB
TypeScript

export type Position = { index: number; line: number; col: number };
export type CompileError = { pos: Position; message: string };
export type DynamicTokenType = "id" | "int";
export type StaticTokenType =
| "eof"
| "invalid"
| "lparen"
| "rparen"
| "lbrace"
| "rbrace"
| "lbracket"
| "rbracket"
| "dot"
| "comma"
| "colon"
| "semicolon"
| "plus"
| "plusplus"
| "plusequal"
| "minus"
| "minusminus"
| "minusequal"
| "minusgt"
| "asterisk"
| "tilde"
| "ampersand"
| "ampersandequal"
| "pipe"
| "pipeequal"
| "hat"
| "hatequal"
| "equal"
| "equalequal"
| "exclamation"
| "exclamationequal"
| "lt"
| "gt"
| "ltequal"
| "gtequal"
| "not"
| "and"
| "or"
| "let"
| "mut"
| "fn"
| "return"
| "if"
| "else"
| "loop"
| "while"
| "break"
| "continue";
export type TokenType = DynamicTokenType | StaticTokenType;
export type Token =
& {
pos: Position;
}
& (
| { tokenType: "id"; value: string }
| {
tokenType: "int";
value: number;
}
| {
tokenType: StaticTokenType;
}
);
export interface TokenIter {
next(): Token;
}