diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2025-11-04 21:51:22 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2025-11-06 20:29:04 -0800 |
| commit | 2e7bf530d33445f34216e02aa19921d3d1ddd525 (patch) | |
| tree | 47774d41dbd1191d02d71ecc4c9efb13882dc6d4 /src/lang | |
| parent | ccaff310c85a64a852d96ee71ecf9640de57ea36 (diff) | |
allow currying ishkai/wip-allow-curryish
Diffstat (limited to 'src/lang')
| -rw-r--r-- | src/lang/js-lang/core/parser.ts | 10 | ||||
| -rw-r--r-- | src/lang/ts-lang/core/parser.ts | 14 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/lang/js-lang/core/parser.ts b/src/lang/js-lang/core/parser.ts index f193d6a..b87d8fd 100644 --- a/src/lang/js-lang/core/parser.ts +++ b/src/lang/js-lang/core/parser.ts @@ -113,12 +113,20 @@ const _parse = ({ }); } + if (head.type === TokenType.OPEN_PAREN) { + return _parse({ + lastToken: null, + remainingTokens, + stack, + }); + } + throw new Error( `${JSON.stringify({ lastToken, remainingTokens, stack, - })} Expected nextToken to be a name or close paren at ${head.type}` + })} Was not expecting ${head.type}` ); }; 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<{ |
