From 56040f3ff85e77311f0c864a89afd63fcf1bdb50 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Mon, 3 Nov 2025 23:40:02 -0800 Subject: add js-lang, refactor some ts-lang stuff --- src/lang/core/lexer.ts | 91 -------------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 src/lang/core/lexer.ts (limited to 'src/lang/core/lexer.ts') diff --git a/src/lang/core/lexer.ts b/src/lang/core/lexer.ts deleted file mode 100644 index 567964f..0000000 --- a/src/lang/core/lexer.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { LexerCtx, Token, TokenSubType, TokenType } from "./common"; - -export type BreakingToken = - | TokenType.OPEN_PAREN - | TokenType.CLOSE_PAREN - | TokenType.COMMA - | TokenType.SEMICOLON - | TokenType.SPACE; - -export type IsWhitespace = T extends `${TokenType.SPACE}` - ? true - : T extends `${TokenType.COMMA}` - ? true - : T extends `${TokenType.SEMICOLON}` - ? true - : false; - -export type ProcessNameCollection< - Ctx extends LexerCtx, - Tail extends string, - _Token extends Token | null -> = { - next: Tail; - nameCollection: ""; - tokens: _Token extends null - ? [ - ...Ctx["tokens"], - ...(Ctx["nameCollection"] extends "" - ? [] - : [Token]) - ] - : [ - ...Ctx["tokens"], - ...(Ctx["nameCollection"] extends "" - ? [_Token] - : [Token, _Token]) - ]; -}; - -export type IsOpen = T extends `${TokenType.OPEN_PAREN}` ? true : false; -export type IsClose = T extends `${TokenType.CLOSE_PAREN}` ? true : false; - -export type ChunkedLex< - Ctx extends LexerCtx, - Depth extends any[] = [] -> = Depth["length"] extends 50 - ? Ctx & { - endChunk: true; - } - : Ctx["next"] extends `${infer Head}${infer Tail}` - ? IsWhitespace extends true - ? ChunkedLex, [0, ...Depth]> - : IsOpen extends true - ? ChunkedLex< - ProcessNameCollection>, - [0, ...Depth] - > - : IsClose extends true - ? ChunkedLex< - ProcessNameCollection>, - [0, ...Depth] - > - : ChunkedLex< - { - next: Tail; - nameCollection: `${Ctx["nameCollection"]}${Head}`; - tokens: Ctx["tokens"]; - }, - [0, ...Depth] - > - : Ctx; - -export type InnerLex< - Next extends string, - NameCollection extends LexerCtx["nameCollection"] = "", - AccTokens extends Token[] = [] -> = Next extends "" - ? AccTokens - : ChunkedLex<{ - next: Next; - tokens: []; - nameCollection: NameCollection; - }> extends infer U - ? U extends LexerCtx & { endChunk: true } - ? InnerLex - : U extends LexerCtx - ? [...AccTokens, ...U["tokens"]] - : never - : never; - -export type Lex = InnerLex; -- cgit v1.2.3-70-g09d2