nandgame-compiler/token.ts

77 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-04-27 01:32:06 +01:00
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;
}