Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Nov 26, 2021
1 parent e837ab0 commit 8f21d7e
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 9 deletions.
2 changes: 0 additions & 2 deletions lib/acceptor/mod.ts

This file was deleted.

3 changes: 3 additions & 0 deletions lib/cartridge/cartridge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* @todo @ethanthatonekid write tests that reflect cartridge api design/usage
*/
6 changes: 6 additions & 0 deletions lib/cartridge/cartridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @todo @ethanthatonekid pass all tests in ./cartridge.test.ts
* @todo @ethanthatonekid refactor <https://github.com/EthanThatOneKid/fart/blob/c43f2333458b2cbc40d167610d87e2a2e3f89885/lib/gen/cart.ts>
*/
export class Cartridge {
}
1 change: 1 addition & 0 deletions lib/cartridge/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Cartridge } from "./cartridge.ts";
7 changes: 6 additions & 1 deletion lib/registry/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
// https://github.com/EthanThatOneKid/fart/blob/c43f2333458b2cbc40d167610d87e2a2e3f89885/lib/reg/registry.ts
/**
* @todo @ethanthatonekid refactor <https://github.com/EthanThatOneKid/fart/blob/c43f2333458b2cbc40d167610d87e2a2e3f89885/lib/reg/registry.ts>
*/
export class Registry {
constructor() {}
}
5 changes: 5 additions & 0 deletions lib/repl/repl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// TODO(@ethanthatonekid): create a repl around the Fart transpiler
export class FartRepl {
constructor() {
}
}
File renamed without changes.
Empty file.
1 change: 1 addition & 0 deletions lib/tokenize/mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type { FartTokenGenerator } from "./tokenize.ts";
export { tokenize } from "./tokenize.ts";
export { Token } from "./token.ts";
export { LEXICON, Lexicon } from "./lexicon.ts";
6 changes: 5 additions & 1 deletion lib/tokenize/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ interface TokenizationState {
breakingLine: boolean; // if true, updates line and column counts at end of iteration
}

type FartTokenGenerator = Generator<Token, undefined, string | undefined>;
export type FartTokenGenerator = Generator<
Token,
undefined,
string | undefined
>;

const INITIAL_TOKENIZATION_STATE: Readonly<TokenizationState> = Object.freeze({
char: null,
Expand Down
6 changes: 3 additions & 3 deletions lib/tokenize/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ Deno.test("correctly checks identifier (hyphens are bad)", () => {
assert(!checkIsIdentifier("hyphens-are-bad"));
});

Deno.test("correctly checks text literal (with '`')", () => {
Deno.test("correctly checks text literal (wrapped in '`')", () => {
assert(checkIsTextLiteral("`example`"));
});

Deno.test('correctly checks text literal (with "\'")', () => {
Deno.test('correctly checks text literal (wrapped in "\'")', () => {
assert(checkIsTextLiteral("'example'"));
});

Deno.test("correctly checks text literal (with '\"')", () => {
Deno.test("correctly checks text literal (wrapped in '\"')", () => {
assert(checkIsTextLiteral('"example"'));
});

Expand Down
32 changes: 30 additions & 2 deletions lib/transpile/transpile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
import { Token, tokenize } from "../tokenize/mod.ts";
import { Cartridge } from "../cartridge/mod.ts";
import { TextBuilder } from "../text_builder/mod.ts";
import type { FartTokenGenerator } from "../tokenize/mod.ts";

export interface FartOptions {
targetLanguage: "ts" | "go" | "json" | "html";
codeCartridges: CodeCartridge[];
codeCartridges: Cartridge[];
indentation: number;
preserveComments: boolean;
}

interface TranspilationContext {
tokenizer: FartTokenGenerator | null;
builder: TextBuilder;
prevTokens: Token[];
}

export const transpile = (code: string, options: FartOptions): string => {
const INITIAL_TRANSPILATION_CONTEXT: TranspilationContext = Object.freeze({
tokenizer: null,
builder: new TextBuilder(),
prevTokens: [],
});

const initializeTranspilationContext = () => ({
...INITIAL_TRANSPILATION_CONTEXT,
});

export const transpile = async (
code: string,
options: FartOptions,
): Promise<string> => {
const ctx = initializeTranspilationContext();
ctx.tokenizer = tokenize(code);
return "";
};

1 comment on commit 8f21d7e

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 8f21d7e Nov 26, 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/8f21d7ee16c6ec7b7b516f829f6130e8f8f68531/std/server/worker.ts': HTTP status client error (404 Not Found) for url (https://raw.githubusercontent.com/EthanThatOneKid/fart/8f21d7ee16c6ec7b7b516f829f6130e8f8f68531/std/server/worker.ts)

Please sign in to comment.