From 8a72c8922df7e4875bc63f4bdd08012b96a72363 Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Wed, 22 Dec 2021 18:23:23 -0800 Subject: [PATCH] neat work --- lib/transpile/transpile.test.ts | 34 ++++++++++++++++++++------------- lib/transpile/transpile.ts | 16 ++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/lib/transpile/transpile.test.ts b/lib/transpile/transpile.test.ts index 0069d09..71484cc 100644 --- a/lib/transpile/transpile.test.ts +++ b/lib/transpile/transpile.test.ts @@ -13,16 +13,24 @@ Deno.test("create transpilation context without crashing", () => { assertEquals(ctx.started, false); }); -// Deno.test("transpiles struct_open event", async () => { -// const fakeCart = new Cartridge(); -// fakeCart.on( -// CartridgeEvent.StructOpen, -// (event: CartridgeEventContext) => { -// assertEquals(event.data.name, "Example"); -// assertEquals(event.data.comments, []); -// return "ABC"; -// }, -// ); -// const result = await transpile(`type Example {`, fakeCart); -// assertEquals(result, "ABC"); -// }); +Deno.test("empty ", () => { + const iterator = tokenize(""); + const cartridge = new Cartridge(); + const builder = new TextBuilder(cartridge); + const ctx = new TranspilationContext(iterator, builder); + assertEquals(ctx.started, false); +}); + +Deno.test("transpiles struct_open event", async () => { + const fakeCart = new Cartridge(); + fakeCart.on( + CartridgeEvent.StructOpen, + (event: CartridgeEventContext) => { + assertEquals(event.data.name, "Example"); + assertEquals(event.data.comments, []); + return "ABC"; + }, + ); + const result = await transpile(`type Example {`, fakeCart); + assertEquals(result, "ABC"); +}); diff --git a/lib/transpile/transpile.ts b/lib/transpile/transpile.ts index 09ecd90..027cd59 100644 --- a/lib/transpile/transpile.ts +++ b/lib/transpile/transpile.ts @@ -74,21 +74,21 @@ export async function transpile( const ctx = new TranspilationContext(tokenize(code), builder); for ( - const token = ctx.nextToken(); + let token = ctx.nextToken(); !ctx.done; + token = ctx.nextToken() ) { switch (token?.kind) { case Lexicon.Load: { const loader = assertKind(token, Lexicon.Load); const source = assertKind(ctx.nextToken(), Lexicon.TextLiteral); const opener = assertKind(ctx.nextToken(), Lexicon.StructOpener); - console.log({ loader, source, opener }); - // await ctx.builder?.append( - // CartridgeEvent.StructOpen, - // [loader, source, opener], - // [], - // ); - // await ctx.nextTuple(); + await ctx.builder.append( + CartridgeEvent.StructOpen, + [loader, source, opener], + [], + ); + await ctx.nextTuple(); break; }