From e9f3c782bc10d4c5c44faf768aa60cd6bcc66574 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 2 Nov 2025 18:08:16 -0800 Subject: refactor --- src/lang/core/common.ts | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/lang/core/common.ts (limited to 'src/lang/core/common.ts') diff --git a/src/lang/core/common.ts b/src/lang/core/common.ts new file mode 100644 index 0000000..c1a1dc3 --- /dev/null +++ b/src/lang/core/common.ts @@ -0,0 +1,57 @@ +export enum TokenType { + OPEN_PAREN = "(", + CLOSE_PAREN = ")", + SPACE = " ", + SEMICOLON = ";", + COMMA = ",", + NAME = "NAME", +} + +export enum TokenSubType { + NA = "NA", + LITERAL = "LITERAL", + REFERENCE = "REFERENCE", +} + +export type Token< + Type extends TokenType = TokenType, + Name extends string = string +> = { + type: Type; + name: Name; +}; + +export type LexerCtx = { + next: string; + nameCollection: string; + tokens: readonly Token[]; +}; + +export enum NodeType { + INT = "INT", + EXT = "EXT", + PARSER_ERROR = "PARSER_ERROR", +} + +export type ASTNode< + Type extends NodeType = NodeType, + Name extends string = string, + Value extends any = any, + Children extends readonly ASTNode[] = readonly ASTNode< + NodeType, + string, + any, + any + >[] +> = { + type: Type; + name: Name; + value: Value; + children: Children; +}; + +export type ParserCtx = { + remainingTokens: readonly Token[]; + lastToken: Token | null; + stack: readonly ASTNode[]; +}; -- cgit v1.2.3-70-g09d2