diff --git a/ex/README.md b/ex/README.md
deleted file mode 100644
index 97c3a33..0000000
--- a/ex/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Pokemon Fart Example
-
-Please refer to .
diff --git a/ex/pokemon/dex.ts b/ex/pokemon/dex.ts
deleted file mode 100644
index efd9083..0000000
--- a/ex/pokemon/dex.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import type { Dex as iDex } from "https://fart.tools/ts/EthanThatOneKid/fart/main/ex/pokemon/mod.ts";
-
-export class Dex implements iDex {
- constructor(
- public national = {
- [25 as number]: {
- name: "Pikachu",
- num: 25,
- caught: false,
- summary:
- "This Pokémon has electricity-storing pouches on its cheeks. These appear to become electrically charged during the night while Pikachu sleeps. It occasionally discharges electricity when it is dozy after waking up.",
- types: { type1: "Electric" },
- },
- },
- ) {}
-
- register(num: number) {
- const { name } = this.national[num];
- if (this.national[num].caught) {
- console.log(`${name} has already been registerd.`);
- return;
- }
- this.national[num].caught = true;
- console.log(`Registered ${name}!`);
- }
-}
diff --git a/ex/pokemon/mod.fart b/ex/pokemon/mod.fart
deleted file mode 100644
index 9a72d9a..0000000
--- a/ex/pokemon/mod.fart
+++ /dev/null
@@ -1,38 +0,0 @@
-type Pokeball {
- id*: string
- odds*: number
- used*: boolean
-
- throw*: fn %
-}
-
-type Pokemon {
- name*: string
- num*: number
- ball: Pokeball
-
- catch*: fn %
-}
-
-type PC {
- mons*: array % Pokemon
-}
-
-type DexEntry {
- name*: string
- num*: number
- summary*: string
- caught*: boolean
- types*: { type1*: string
- type2: string }
-}
-
-type Dex {
- national*: dict %
- register*: fn %
-}
-
-type Bag {
- dex*: Dex
- balls*: array % Pokeball
-}
\ No newline at end of file
diff --git a/ex/pokemon/pokeball.ts b/ex/pokemon/pokeball.ts
deleted file mode 100644
index da06278..0000000
--- a/ex/pokemon/pokeball.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import type { Pokeball as iPokeball } from "https://fart.tools/ts/EthanThatOneKid/fart/main/ex/pokemon/mod.ts";
-
-const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
-
-export class Pokeball implements iPokeball {
- constructor(
- public id: string,
- public odds: number,
- public used: boolean = false,
- ) {}
-
- async throw(name: string): Promise {
- if (this.used) return false;
- this.used = true;
- console.log("wiggle");
- await sleep(1e3);
- const caught = Math.random() > (1 - this.odds);
- console.log("wiggle");
- await sleep(1e3);
- if (caught) {
- console.log(`Caught ${name}`);
- return true;
- }
- console.log(`${name} broke out!`);
- return false;
- }
-}
diff --git a/ex/pokemon/run.ts b/ex/pokemon/run.ts
deleted file mode 100644
index d0837f2..0000000
--- a/ex/pokemon/run.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-// Source Fart:
-import type {
- Bag,
- PC,
- Pokemon,
-} from "https://fart.tools/ts/EthanThatOneKid/fart/main/ex/pokemon/mod.ts";
-
-// Extended Pokeball class
-import { Pokeball } from "./pokeball.ts";
-
-// Extended Dex class
-import { Dex } from "./dex.ts";
-
-// Your stuff
-const dex = new Dex();
-const great_ball = new Pokeball("great", 0.5);
-const ultra_ball = new Pokeball("ultra", 0.8);
-const bag: Bag = { dex, balls: [great_ball, ultra_ball] };
-const pc: PC = { mons: [] };
-
-// A wild Pikachu
-const pikachu: Pokemon = {
- name: "Pikachu",
- num: 25,
- async catch(ball: Pokeball) {
- const caught = await ball.throw(this.name);
- if (caught) {
- this.ball = ball;
- bag.dex.register(this.num);
- pc.mons.push(this);
- console.log(`Moved ${this.name} to the PC.`);
- }
- return caught;
- },
-};
-
-// Try to catch it
-for (const ball of bag.balls) {
- const caught = await pikachu.catch(ball);
- if (caught) break;
-}
-
-// Check the PC
-console.log("PC: ", pc);
diff --git a/lib/tokenize/t.ts b/lib/tokenize/t.ts
index 3caff3c..dde33cb 100644
--- a/lib/tokenize/t.ts
+++ b/lib/tokenize/t.ts
@@ -1,3 +1,4 @@
+// deno-lint-ignore-file camelcase
// This file simply exports an object which contains lightweight
// functions for creating Token instances with fewer keystrokes;
// used primarily for testing-purposes.
diff --git a/lib/transpile/transpile.ts b/lib/transpile/transpile.ts
index 07f0527..9a3338f 100644
--- a/lib/transpile/transpile.ts
+++ b/lib/transpile/transpile.ts
@@ -15,22 +15,41 @@ interface TranspilationContext {
tokenizer: FartTokenGenerator | null;
builder: TextBuilder | null;
prevTokens: Token[];
+ currentToken: Token | null;
+ nextToken: () => Token | undefined;
+ nextStruct: () => Promise;
+ nextTuple: () => Promise;
}
-const INITIAL_TRANSPILATION_CONTEXT: TranspilationContext = Object.freeze({
+const INITIAL_TRANSPILATION_CONTEXT: TranspilationContext = {
tokenizer: null,
builder: null,
prevTokens: [],
-});
+ currentToken: null,
+ nextToken() {
+ if (this.tokenizer !== null) {
+ if (this.currentToken !== null) {
+ this.prevTokens.push(this.currentToken);
+ }
+ return this.tokenizer.next().value;
+ }
+ },
+ async nextStruct() {
+ // TODO: handle struct
+ },
+ async nextTuple() {
+ // TODO: handle tuple
+ },
+};
const initializeTranspilationContext = () => ({
...INITIAL_TRANSPILATION_CONTEXT,
});
-export const transpile = async (
+export const transpile = (
code: string,
- options: FartOptions,
-): Promise => {
+ // options: FartOptions,
+): string => {
const ctx = initializeTranspilationContext();
ctx.tokenizer = tokenize(code);