From 8896b33a652563d90cb211a85dd2f7213f42e5d1 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 28 Oct 2025 22:49:46 -0700 Subject: parse, lex works --- src/lib/core/lexer.ts | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/lib/core/lexer.ts (limited to 'src/lib/core/lexer.ts') diff --git a/src/lib/core/lexer.ts b/src/lib/core/lexer.ts new file mode 100644 index 0000000..3315fb2 --- /dev/null +++ b/src/lib/core/lexer.ts @@ -0,0 +1,64 @@ +import { LexerCtx, Token, 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< + Cur extends LexerCtx, + Tail extends string, + _Token extends Token | null +> = { + next: Tail; + nameCollection: ""; + tokens: _Token extends null + ? [ + ...Cur["tokens"], + ...(Cur["nameCollection"] extends "" + ? [] + : [Token]) + ] + : [ + ...Cur["tokens"], + ...(Cur["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 _Lex = + Ctx["next"] extends `${infer Head}${infer Tail}` + ? IsWhitespace extends true + ? _Lex> + : IsOpen extends true + ? _Lex>> + : IsClose extends true + ? _Lex>> + : _Lex<{ + next: Tail; + nameCollection: `${Ctx["nameCollection"]}${Head}`; + tokens: Ctx["tokens"]; + }> + : // : Ctx["next"] extends `${infer Head}` + // ? _Lex<{ next: Head; tokens: Ctx["tokens"] }> + Ctx["tokens"]; + +export type Lex = _Lex<{ + next: `${Raw};`; + tokens: []; + nameCollection: ""; +}>; -- cgit v1.2.3-70-g09d2