Skip to content

Commit

Permalink
neat work
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Dec 23, 2021
1 parent 4b3f831 commit 8a72c89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
34 changes: 21 additions & 13 deletions lib/transpile/transpile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CartridgeEvent.StructOpen>) => {
// 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<CartridgeEvent.StructOpen>) => {
assertEquals(event.data.name, "Example");
assertEquals(event.data.comments, []);
return "ABC";
},
);
const result = await transpile(`type Example {`, fakeCart);
assertEquals(result, "ABC");
});
16 changes: 8 additions & 8 deletions lib/transpile/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

1 comment on commit 8a72c89

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 8a72c89 Dec 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

failed to fetch 'https://raw.githubusercontent.com/EthanThatOneKid/fart/8a72c8922df7e4875bc63f4bdd08012b96a72363/fart_server/handle_request.ts': HTTP status client error (404 Not Found) for url (https://raw.githubusercontent.com/EthanThatOneKid/fart/8a72c8922df7e4875bc63f4bdd08012b96a72363/fart_server/handle_request.ts)

Please sign in to comment.