diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2025-11-02 18:08:16 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2025-11-02 18:09:14 -0800 |
| commit | e9f3c782bc10d4c5c44faf768aa60cd6bcc66574 (patch) | |
| tree | cb4e447a5ce5deffe989a65ff774e90f0e8ad518 /src/lang/core/common.ts | |
| parent | f53622d63c74a1e2dd0397f4a26f31aa72dea60b (diff) | |
refactor
Diffstat (limited to 'src/lang/core/common.ts')
| -rw-r--r-- | src/lang/core/common.ts | 57 |
1 files changed, 57 insertions, 0 deletions
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[]; +}; |
