summaryrefslogtreecommitdiff
path: root/src/lang/ts-lang/core/parser.ts
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2025-11-04 21:51:22 -0800
committerKai Stevenson <kai@kaistevenson.com>2025-11-06 20:29:04 -0800
commit2e7bf530d33445f34216e02aa19921d3d1ddd525 (patch)
tree47774d41dbd1191d02d71ecc4c9efb13882dc6d4 /src/lang/ts-lang/core/parser.ts
parentccaff310c85a64a852d96ee71ecf9640de57ea36 (diff)
allow currying ishkai/wip-allow-curryish
Diffstat (limited to 'src/lang/ts-lang/core/parser.ts')
-rw-r--r--src/lang/ts-lang/core/parser.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/lang/ts-lang/core/parser.ts b/src/lang/ts-lang/core/parser.ts
index db6f3aa..3b20743 100644
--- a/src/lang/ts-lang/core/parser.ts
+++ b/src/lang/ts-lang/core/parser.ts
@@ -72,6 +72,7 @@ export type ResolveNodeFromToken<_Token extends Token> = ParseNumberLiteral<
? ASTNode<NodeType.INT, "", ParseStringLiteral<_Token["name"]>, []>
: ASTNode<NodeType.EXT, _Token["name"], null, []>;
+// FIXME don't need lastToken
export type _Parse<Ctx extends ParserCtx> = Ctx["remainingTokens"] extends [
infer Head extends Token,
...infer Tail extends readonly Token[]
@@ -122,7 +123,7 @@ export type _Parse<Ctx extends ParserCtx> = Ctx["remainingTokens"] extends [
stack: [...Ctx["stack"], ResolveNodeFromToken<Ctx["lastToken"]>];
}>
: Ctx & Error<`Was not expecting ${Head["type"]}`>
- : // expect nextToken to be a name or close paren
+ : // expect nextToken to be a name or open paren or close paren
Head["type"] extends TokenType.NAME
? // lastToken = nextToken
// goto start
@@ -144,8 +145,15 @@ export type _Parse<Ctx extends ParserCtx> = Ctx["remainingTokens"] extends [
>
>;
}>
- : Ctx &
- Error<`Expected nextToken to be a name or close paren at ${Head["type"]}`>
+ : Head["type"] extends TokenType.OPEN_PAREN
+ ? // push lastToken onto stack
+ // goto start
+ _Parse<{
+ lastToken: null;
+ remainingTokens: Tail;
+ stack: Ctx["stack"];
+ }>
+ : Ctx & Error<`Was not expecting ${Head["type"]}`>
: Ctx["lastToken"] extends Token
? // case where we ended with a name
_Parse<{